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
分享到:
相关推荐
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)
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...
The book details how to write vertex and fragment shaders, how to implement advanced rendering techniques such as per-pixel lighting and shadowing, and basic interaction techniques such as selecting ...
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
### 使用Eclipse进行C/C++程序调试 #### 概述 Eclipse 是一款非常流行的开源集成开发环境(IDE),广泛应用于各种编程语言的开发中,包括C和C++。通过Eclipse,开发者不仅可以编写代码,还可以编译、运行以及调试...
《C++ How to Program, 7/e》是Paul Deitel和Harvey Deitel合著的一本经典的C++编程教程,其源代码包含了丰富的实例和练习,旨在帮助学习者深入理解和掌握C++语言。这本书覆盖了从基础语法到高级特性的全面内容,...
#### 三、Eclipse IDE for C/C++ Developers的安装 **1. Eclipse简介** Eclipse是一款功能强大的开源IDE,广泛用于多种编程语言的开发。本教程中提到的是专为C/C++开发者设计的版本。 **2. 下载与安装** - 下载地址...
该公司的服务范围包括但不限于编程语言、软件技术等,具体涵盖C++、Visual C++、C、Java、C#、Visual Basic、Objective-C、XML、Python、JavaScript、面向对象技术、互联网与Web开发以及Android和iPhone应用程序开发...
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 ...
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 ...
### 使用OpenWrt SDK构建C/C++程序 在本文中,我们将探讨如何为LinkIt Smart 7688开发平台构建C/C++二进制文件,并通过交叉编译技术创建可使用`opkg`命令安装的`.ipk`文件。 #### 环境准备 目前仅支持Ubuntu Linux...
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...
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, ...