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
分享到:
相关推荐
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. ...
Please reference the [test codes](./android/test/ndcam/). ```console $ gradle connectedAndroidTest # Run test ``` ### Use The following code shows working with `SurfaceView` class. ```java package...
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...
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 ...
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 源代码
昆腾磁带库报错:No cleaning slots are configured, cannot import cleaning media的解决方法
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
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...
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, ...
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...
The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the Second...
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, ...
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)
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 ...
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++高清文字版本. 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...
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 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: ...