[android-developers] Re: how to load a .so library in a apk?

2009-08-04 Thread Kaj Bjurman

I'm not sure about this, since I haven't done it myself, but I've
heard that some people place the libraries under res/raw, and then
they copy it to /data/data/your-package-name when it's first started.


On 4 Aug, 04:53, "xuxiake2...@gmail.com" 
wrote:
> I have a .so library ,which I had  put  in directory  "assets" .   But
> how can i load it ?
>
> I can't use System.loadLibrary or System.load  because i can't get the
> path.  thanks
>
> in advance for your answers.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: how to load a .so library in a apk?

2009-08-04 Thread spark

yes,I have already did this .



private void loadLibraryFromAssets() {
AssetManager am = getAssets();
String path = null;
try {
InputStream in;
in = am.open("lib/libjni_xxx.so");

BufferedInputStream bis = new BufferedInputStream(in);

path = Enviroment.getAppPath(this) + "libjni_xxx.so";

File file = new File(path);

if (!file.exists()) {
file.createNewFile();
}

FileOutputStream out = new FileOutputStream(path);
byte[] temp = new byte[2048];
while (bis.read(temp) > 0) {
out.write(temp);
}
bis.close();
out.close();

//am.close(); can't be closed
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG,"load Library From Assets error: " + 
e.getMessage());
}

try {
System.load(path);
} catch (UnsatisfiedLinkError e) {
String errorMsg = e.getMessage();
Log.e(TAG,"System.load error: " + errorMsg);
} catch (SecurityException e) {
String errorMsg = e.getMessage();
Log.e(TAG,"System.load error: " + errorMsg);
}

}



On 8月4日, 下午3时03分, Kaj Bjurman  wrote:
> I'm not sure about this, since I haven't done it myself, but I've
> heard that some people place the libraries under res/raw, and then
> they copy it to /data/data/your-package-name when it's first started.
>
> On 4 Aug, 04:53, "xuxiake2...@gmail.com" 
> wrote:
>
>
>
> > I have a .so library ,which I had  put  in directory  "assets" .   But
> > how can i load it ?
>
> > I can't use System.loadLibrary or System.load  because i can't get the
> > path.  thanks
>
> > in advance for your answers.- 隐藏被引用文字 -
>
> - 显示引用的文字 -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: how to load a .so library in a apk?

2009-08-04 Thread Kaj Bjurman
That code contains at least one bug.

This loop isn't correct:

>  while (bis.read(temp) > 0) {
>out.write(temp);
>  }

bis.read returns the number of bytes that was read, that number can be
larger than 0 but still less than temp.length. You should do something
like this instead:

int len = 0;
while (( len = bis.read(temp)) > 0) {
out.write(temp, 0, len);
}

Your file wile otherwise be corrupt.



On 4 Aug, 13:14, spark  wrote:
> yes,I have already did this .
>
> private void loadLibraryFromAssets() {
>                 AssetManager am = getAssets();
>                 String path = null;
>                 try {
>                         InputStream in;
>                         in = am.open("lib/libjni_xxx.so");
>
>                         BufferedInputStream bis = new BufferedInputStream(in);
>
>                     path = Enviroment.getAppPath(this) + "libjni_xxx.so";
>
>                         File file = new File(path);
>
>                         if (!file.exists()) {
>                                 file.createNewFile();
>                         }
>
>                         FileOutputStream out = new FileOutputStream(path);
>                         byte[] temp = new byte[2048];
>                         while (bis.read(temp) > 0) {
>                                 out.write(temp);
>                         }
>                         bis.close();
>                         out.close();
>
>                         //am.close(); can't be closed
>                 } catch (IOException e) {
>                         e.printStackTrace();
>                         Log.e(TAG,"load Library From Assets error: " + 
> e.getMessage());
>                 }
>
>                 try {
>                         System.load(path);
>                 } catch (UnsatisfiedLinkError e) {
>                         String errorMsg = e.getMessage();
>                         Log.e(TAG,"System.load error: " + errorMsg);
>                 } catch (SecurityException e) {
>                         String errorMsg = e.getMessage();
>                         Log.e(TAG,"System.load error: " + errorMsg);
>                 }
>
>         }
>
> On 8月4日, 下午3时03分, Kaj Bjurman  wrote:
>
>
>
> > I'm not sure about this, since I haven't done it myself, but I've
> > heard that some people place the libraries under res/raw, and then
> > they copy it to /data/data/your-package-name when it's first started.
>
> > On 4 Aug, 04:53, "xuxiake2...@gmail.com" 
> > wrote:
>
> > > I have a .so library ,which I had  put  in directory  "assets" .   But
> > > how can i load it ?
>
> > > I can't use System.loadLibrary or System.load  because i can't get the
> > > path.  thanks
>
> > > in advance for your answers.- 隐藏被引用文字 -
>
> > - 显示引用的文字 -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: how to load a .so library in a apk?

2009-08-04 Thread Aki

I putted my created .so file into libs/armeabi/

I reccomend you download Android NDK .
http://developer.android.com/sdk/ndk/1.5_r1/index.html

and ask Android NDK Group is better.
http://groups.google.com/group/android-ndk

thanks

On 8月4日, 午後4:03, Kaj Bjurman  wrote:
> I'm not sure about this, since I haven't done it myself, but I've
> heard that some people place the libraries under res/raw, and then
> they copy it to /data/data/your-package-name when it's first started.
>
> On 4 Aug, 04:53, "xuxiake2...@gmail.com" 
> wrote:
>
>
>
> > I have a .so library ,which I had  put  in directory  "assets" .   But
> > how can i load it ?
>
> > I can't use System.loadLibrary or System.load  because i can't get the
> > path.  thanks
>
> > in advance for your answers.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---