How to add system permission file/system library to Android
I am attempting to follow Diane Hackborn's request:
For a permission that allows an application to be root, it is okay to add the permission to the framework <...>. However, there still must be some kind of shared library (even if it is a stub) for the application to request along with it, and the package manager should not allow the application get this permission unless they also request the shared library.
So I used the sdk's sample example of TicTacToe:
- exported com.example.android.tictactoe.library to a /data/app/TTTLib.jar
added /system/etc/permissions/com.example.android.tictactoe.library.xml with lines:
<?xml version="1.0" encoding="utf-8"?> <permissions> <library name="com.example.android.tictactoe.library" file="/data/app/TTTLib.jar" /> </permissions>
And compile com.example.android.tictactoe.MainActivity by adding a class folder pointing to the library but not adding the library itself to the .apk
It compiles, installs, starts running, but at the point when a library class were called crashes with error msg:
W/dalvikvm( 464): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime开发者_开发问答( 464): FATAL EXCEPTION: main
E/AndroidRuntime( 464): java.lang.NoClassDefFoundError: com.example.android.tictactoe.library.GameActivity
E/AndroidRuntime( 464): at com.example.android.tictactoe.MainActivity.startGame(MainActivity.java:51)
E/A
What do I miss? Thanks for your help.
In AndroidManifest.xml you have to enter the library dependency such as
<uses-library android:name="com.example.android.tictactoe.library"/>
Also i think you have to DEX the jar content before uploading it to the device, similar to the uploading of scala library to the device. See http://lampwww.epfl.ch/~michelou/android/emulator-android-sdk.html and http://lampwww.epfl.ch/~michelou/android/android-examples-in-scala/android-sdk.zip for scripts that dexes the jar into dexed jar :) Hope it does make any sense.
Check bin/createdexlibs in android-sdk.zip
Basically it should be something like
~/android-sdks/platform-tools/dx --dex --output=TTTLib.jar TTLLib_input.jar
精彩评论