views:

262

answers:

0

I want to load third-party jni library in runtime.
I've tried to load directly from sdcard. It expectedly failed.
I've tried to copy library from sdcard to /data/data/app/ and then
System.load(/data/data/app/libjni.so)
It works on HTC HERO, but fails on HTC Legend with Android 2.1. it fails during execution of native code and write to log uninformative stack trace Any other way to do it? Thats the best piece of code, that works at 1.5(HTC Hero), but donot works on 2.1(HTC Legend).

FileInputStream fis = new FileInputStream("/sdcard/libjni.so");
File nf = new File("/data/data/app/libjni.so");
FileOutputStream fos = new FileOutputStream(nf);
byte[] buf = new byte[2048];
int n;
while ((n = fis.read(buf)) > 0)
    fos.write(buf, 0, n);
fis.close();
fos.close();
System.load("/data/data/app/libjni.so");