gpt4 book ai didi

android - Android添加系统权限文件/系统库的方法

转载 作者:搜寻专家 更新时间:2023-11-01 09:18:02 32 4
gpt4 key购买 nike

我正在尝试关注 Diane Hackborn 的 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.

所以我使用了sdk的TicTacToe示例:

  1. 将 com.example.android.tictactoe.library 导出到/data/app/TTTLib.jar
  2. 添加/system/etc/permissions/com.example.android.tictactoe.library.xml 中的行:

    <?xml version="1.0" encoding="utf-8"?>
    <permissions>
    <library name="com.example.android.tictactoe.library"
    file="/data/app/TTTLib.jar" />
    </permissions>

  3. 并通过添加指向库的类文件夹但不将库本身添加到 .apk 来编译 com.example.android.tictactoe.MainActivity

它编译、安装、开始运行,但在调用库类时崩溃并显示错误消息:

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

我错过了什么?感谢您的帮助。

最佳答案

在 AndroidManifest.xml 中,您必须输入库依赖项,例如

<uses-library android:name="com.example.android.tictactoe.library"/>

此外,我认为您必须先对 jar 内容进行 DEX,然后再将其上传到设备,类似于将 scala 库上传到设备。参见 http://lampwww.epfl.ch/~michelou/android/emulator-android-sdk.htmlhttp://lampwww.epfl.ch/~michelou/android/android-examples-in-scala/android-sdk.zip对于将 jar 删除到 dexed jar 中的脚本:)希望它确实有意义。

检查android-sdk.zip中的bin/createdexlibs

基本上应该是这样的

~/android-sdks/platform-tools/dx --dex --output=TTTLib.jar TTLLib_input.jar

关于android - Android添加系统权限文件/系统库的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3164908/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com