`
zhubin215130
  • 浏览: 140249 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

【转】How to port native (C/C++) library into android.

阅读更多
Android official documents don’t have supports for writing native (C/C++) applications or libraries on android. But after all, android is a new platform, a lots of useful software are unavailable on android, if developing them from scratch using android Java framework, it will cost us much more time, further more, native functions should have better performance than pure Java applications. so, we will often think about porting existing native shared library to Android.


First, you have to pass build on android for your native library, write you own Android.mk including $(BUILD_SHARED_LIBRARY).

Second, using Java Api in Android Framework to write the UI for your application, call the native functions in your native library through JNI


At last you may encounter a problem about how to publish your software?.


All the native libraries come together with android are prelinked into the system.img, they will go to Android phone when the system.img is flashed into phone. This method is suitable for phone manufactures, but if you want to make a single .apk package to let users around the world to download and install, you have to think about put the native shared library into the .apk package. but how to use it in runtime? Here is a workaround method, pack your shared library into the apk as assets and copy the lib out of the package at the first launch time of your application. How to copy? Using AssetManager in Android Framework, see following sample code:



InputStream instream = getAssets().open( “native lib path in the apk package” );

 if(new File(“new lib path in phone”).exists() == false)

               copyFile(“new lib path in phone”,instream);       


  

If your native lib size is greater than UNCOMPRESS_DATA_MAX( = 1M currently), you will get exception when using instream to read file,  this time you couldn’t use AssetManager any more, instead you could use zip utilities in Java.util.zip, see following sample code:

           ZipFile zip = new ZipFile(APK_PATH);

           ZipEntry zipen = getFileZipEntry(zip,NATIVE_LIBRARY);

           copyFile(libPath, zip.getInputStream(zipen));


Another point, every Java application in android could only write on it’s own private folder, that is /data/data/packagename/, so the only place you could put your native library is here.


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wzshuoshuo/archive/2008/12/29/3636657.aspx
分享到:
评论

相关推荐

    Android代码-Library

    Library: BibTeX on Android License: Library is free software published under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. Build (for dummies): Install and set up the Android SDK. ...

    NDK Camera

    Please reference the [test codes](./android/test/ndcam/). ```console $ gradle connectedAndroidTest # Run test ``` ### Use The following code shows working with `SurfaceView` class. ```java package...

    Rhino5_Python_Primer.pdf

    Another very thorough resource for Python is from MIT, called "How to Think Like a Computer Scientist": http://www.greenteapress.com/thinkpython/thinkCSpy/thinkCSpy.pdf Common Exceptions/Errors: For a...

    UE(官方下载)

    However, what happens when you're moving to a new system and you want to port your settings and customizations over along with UltraEdit? Add a webpage to your toolbar Use UltraEdit's powerful user ...

    Android代码-simplenote-android

    Simplenote for Android A Simplenote client for Android....How to Configure ...sdk.dir=/Applications/Android Studio.app/sdk Install debug build with Android Studio or: ./gradlew insta

    C++ How to Program, 7/e 源代码

    C++ How to Program, 7/e 源代码

    How to Set Up Cleaning Slots and Import Cleaning Tapes for the I40/I80 Library

    昆腾磁带库报错:No cleaning slots are configured, cannot import cleaning media的解决方法

    How to use the NFS Client c# Library

    The target of this project is to implement NFS (Network File System v2/v3/v4.1) over the Dokan user file system for windows. This let you mount very easily an NFS export as a local windows drive. You ...

    C++.How.To.Program.8th.Ed

    C++.How.To.Program.8th.Ed

    Android代码-Material Design风格Preference UI

    Based on support-preference from Android Support Library, adding a lot of exciting features. Sample How to use add dependencies // replace with version above implementation 'moe.shizuku.preference...

    Apress.Beginning.Android.C++.Game.Development.2013

    How to build your first real-world quality game app for Android smartphones and tablets using the power of the Android C++ APIs as found in the NDK How to do professional level, quality game design, ...

    Android Programming

    This tutorial will go through how to set-up an Android programming environment on Windows 7 platform. Once the Android programming platform is set-up you can start to create (develop) your own Android...

    C++标准库(第二版)英文版.pdf

    The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the Second...

    UniWebView+3.unitypackage.zip

    UniWebView is a Unity3D plugin built on native iOS/Android technology. It helps your users to enjoy web content and interact with your game through the web views. ## Documentation To get started, ...

    Android代码-WsManager

    WsManager A library that simplifies the use of OkHttp ...How to use Instantiate a WsManager object: OkHttpClient okHttpClient = new OkHttpClient().newBuilder() .pingInterval(15, TimeUnit.SECONDS)

    Learning.React.Native.Building.Native.Mobile.Apps.with.JavaScript.149192

    By bringing the advantages of ReactJS to mobile, React Native transforms every web developer into a potential mobile developer. Unlike existing JavaScript-for-mobile approaches, React Native actually ...

    Android代码-Blurry

    Blurry is an easy blur library for Android. Screenshot How do I use it? Setup Dependencies dependencies { compile 'jp.wasabeef:blurry:2.1.1' } Functions Overlay Parent must be ViewGroup Blurry.with...

    Jumping Into C++ 完整英文版.pdf

    Jumping Into C++高清文字版本. Want to learn to code? Want to learn C++? Struggling to follow your lecturer or books and tutorials written for experts? You're not alone. As a professional C++ developer...

    simple demo web project, it covers below techical topics:

    How to import to IDEA? refer to http://www.jianshu.com/p/31ff3b571b68 How to run ? 1. fire create table sql script in dbscripts folder. 2. change the datasource setting in /src/main/resource/...

    Pro Android C++ with the NDK.apress.2012

    Pro Android C++ with the NDK Copyright ? 2012 by Onur Cinar ISBN-13 (pbk): 978-1-4302-4827-9 ISBN-13 (electronic): 978-1-4302-4828-6 Content: Chapter 1: Getting Started with C++ on Android Chapter 2: ...

Global site tag (gtag.js) - Google Analytics