Project needs, using the NDK and the Java Development Library, so that after two separate individuals: so and jar packages, to provide customers not only trouble, there are two versions to maintain, so think of putting so into the jar package.
The simple approach is to copy the so library into the specified directory and load it into the jar package from this directory.
Traditional load so method: Put so into the Libs/armeabi directory (ARM architecture) and load the so library with the following code.
Static { system.loadlibrary ("Native-jni"); }
So into the jar package, you need to remove the so library suffix, put it under the Assets Resource folder, and load with the code below.
Public Static BooleanLoadurlsolib (Context context) {String package_name=Context.getpackagename (); String Db_url_lib= "/data" + environment.getdatadirectory (). GetAbsolutePath () + "/" + package_name+ "/" + "Lib"; String Db_path= "/data" + environment.getdatadirectory (). GetAbsolutePath () + "/" + package_name+ "/" + "libs" + "/" + "native-jni.so"; String Db_url= "/data" + environment.getdatadirectory (). GetAbsolutePath () + "/" + package_name+ "/" + "libs"; if(util.is_logout) {LOG.E ("Drvlib", "New File (Db_url_lib). LastModified ()-system.currenttimemillis () =" + (NewFile (Db_url_lib). LastModified ()-System.currenttimemillis ())); } if(! (NewFile (Db_path). Exists ()) | | (NewFile (Db_url_lib). Exists () && (System.currenttimemillis ()-NewFile (Db_url_lib). LastModified () < 6000))) { Try{InputStream is= Context.getassets (). Open ("Libnative-jni"); Libnative-jni generated so de-suffix name
String Command= "chmod 777" +Db_url; Runtime Runtime=Runtime.getruntime (); Runtime.exec (command); File dir=NewFile (Db_url); if(!dir.exists ()) {Dir.mkdir (); } FileOutputStream Fos=NewFileOutputStream (Db_path,false); byte[] buffer =New byte[1024*4]; intCount = 0; while((count = is.read (buffer)) > 0) {fos.write (buffer,0, Count); } fos.close (); Is.close (); }Catch(Exception e) {e.printstacktrace (); return false; }} system.load (Db_path); return true; }
Android so library put in jar