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