1*c73d2a95SAndroid Build Coastguard WorkerPlatform Library Example 2*c73d2a95SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~ 3*c73d2a95SAndroid Build Coastguard Worker 4*c73d2a95SAndroid Build Coastguard Worker 5*c73d2a95SAndroid Build Coastguard WorkerThis directory contains a full example of writing your own Android platform 6*c73d2a95SAndroid Build Coastguard Workershared library, without changing the Android framework. It also shows how to 7*c73d2a95SAndroid Build Coastguard Workerwrite JNI code for incorporating native code into the library, and a client 8*c73d2a95SAndroid Build Coastguard Workerapplication that uses the library. 9*c73d2a95SAndroid Build Coastguard Worker 10*c73d2a95SAndroid Build Coastguard WorkerThis example is ONLY for people working with the open source platform to 11*c73d2a95SAndroid Build Coastguard Workercreate a system image that will be delivered on a device which will include 12*c73d2a95SAndroid Build Coastguard Workera custom library as shown here. It can not be used to create a third party 13*c73d2a95SAndroid Build Coastguard Workershared library, which is not currently supported in Android. 14*c73d2a95SAndroid Build Coastguard Worker 15*c73d2a95SAndroid Build Coastguard WorkerTo declare your library to the framework, you must place a file with a .xml 16*c73d2a95SAndroid Build Coastguard Workerextension in the /system/etc/permissions directory with the following contents: 17*c73d2a95SAndroid Build Coastguard Worker 18*c73d2a95SAndroid Build Coastguard Worker<?xml version="1.0" encoding="utf-8"?> 19*c73d2a95SAndroid Build Coastguard Worker<permissions> 20*c73d2a95SAndroid Build Coastguard Worker <library name="com.example.android.platform_library" 21*c73d2a95SAndroid Build Coastguard Worker file="/system/framework/com.example.android.platform_library.jar"/> 22*c73d2a95SAndroid Build Coastguard Worker</permissions> 23*c73d2a95SAndroid Build Coastguard Worker 24*c73d2a95SAndroid Build Coastguard WorkerThere are three major parts of this example, supplying three distinct 25*c73d2a95SAndroid Build Coastguard Workerbuild targets and corresponding build outputs: 26*c73d2a95SAndroid Build Coastguard Worker 27*c73d2a95SAndroid Build Coastguard Worker 28*c73d2a95SAndroid Build Coastguard Workercom.example.android.platform_library 29*c73d2a95SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30*c73d2a95SAndroid Build Coastguard Worker 31*c73d2a95SAndroid Build Coastguard WorkerThe top-level Android.mk defines the rules to build the shared library itself, 32*c73d2a95SAndroid Build Coastguard Workerwhose target is "com.example.android.platform_library". The code for this 33*c73d2a95SAndroid Build Coastguard Workerlibrary lives under java/. 34*c73d2a95SAndroid Build Coastguard Worker 35*c73d2a95SAndroid Build Coastguard WorkerNote that the product for this library is a raw .jar file, NOT a .apk, which 36*c73d2a95SAndroid Build Coastguard Workermeans there is no manifest or resources associated with the library. 37*c73d2a95SAndroid Build Coastguard WorkerUnfortunately this means that if you need any resources for the library, such 38*c73d2a95SAndroid Build Coastguard Workeras drawables or layout files, you will need to add these to the core framework 39*c73d2a95SAndroid Build Coastguard Workerresources under frameworks/base/res. Please make sure when doing this that 40*c73d2a95SAndroid Build Coastguard Workeryou do not make any of these resources public, they should not become part of 41*c73d2a95SAndroid Build Coastguard Workerthe Android API. In the future we will allow shared libraries to have their 42*c73d2a95SAndroid Build Coastguard Workerown resources. 43*c73d2a95SAndroid Build Coastguard Worker 44*c73d2a95SAndroid Build Coastguard WorkerOther than that, the library is very straight-forward, and you can write 45*c73d2a95SAndroid Build Coastguard Workerbasically whatever code you want. You can also put code in other Java 46*c73d2a95SAndroid Build Coastguard Workernamespaces -- the namespace given in the <library> tag above is just the 47*c73d2a95SAndroid Build Coastguard Workerpublic unique name by which clients will link to your library, but once this 48*c73d2a95SAndroid Build Coastguard Workerlink happens all of the Java namespaces in that library will be available 49*c73d2a95SAndroid Build Coastguard Workerto the client. 50*c73d2a95SAndroid Build Coastguard Worker 51*c73d2a95SAndroid Build Coastguard Worker 52*c73d2a95SAndroid Build Coastguard Workerlibplatform_library_jni 53*c73d2a95SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~ 54*c73d2a95SAndroid Build Coastguard Worker 55*c73d2a95SAndroid Build Coastguard WorkerThis is an optional example of how to write JNI code associated with a 56*c73d2a95SAndroid Build Coastguard Workershared library. This code lives under jni/. The jni/Android.mk file defines 57*c73d2a95SAndroid Build Coastguard Workerthe rules for building the final .so in which the code lives. This example 58*c73d2a95SAndroid Build Coastguard Workerprovides everything needed to hook up the native code with the Java library 59*c73d2a95SAndroid Build Coastguard Workerand call through to it, plus a very simple JNI call. 60*c73d2a95SAndroid Build Coastguard Worker 61*c73d2a95SAndroid Build Coastguard Worker 62*c73d2a95SAndroid Build Coastguard WorkerPlatformLibraryClient 63*c73d2a95SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~ 64*c73d2a95SAndroid Build Coastguard Worker 65*c73d2a95SAndroid Build Coastguard WorkerThis shows an example of how you can write client applications for your new 66*c73d2a95SAndroid Build Coastguard Workershared library. This code lives under client/. Note that the example is 67*c73d2a95SAndroid Build Coastguard Workersimply a regular Android .apk, like all of the other .apks created by the 68*c73d2a95SAndroid Build Coastguard Workerbuild system. The only two special things needed to use your library are: 69*c73d2a95SAndroid Build Coastguard Worker 70*c73d2a95SAndroid Build Coastguard Worker- A LOCAL_JAVA_LIBRARIES line in the Android.mk to have the build system link 71*c73d2a95SAndroid Build Coastguard Workeragainst your shared library. 72*c73d2a95SAndroid Build Coastguard Worker 73*c73d2a95SAndroid Build Coastguard Worker- A <uses-library> line in the AndroidManifest.xml to have the runtime load 74*c73d2a95SAndroid Build Coastguard Workeryour library into the application. 75