Android so library put in jar

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.