frameworks中引用aar包

在frameworks中引用aar包的步骤(以我需要在PKMS中调用为例):

1.在相应的目录中新建一个文件夹,存放test-debug.aar及Android.bp文件。
如我在\frameworks\base\services目录下新建一个文件夹:data_test,里面放test-debug.aar及Android.bp.

2.Android.bp中的内容
android_library_import {
    name: "services.data_test",
    aars: ["test-debug.aar"],
    sdk_version: "current",
}

3.在\frameworks\base\services\Android.bp中添加services.data_test
 // The convention is to name each service module 'services.$(module_name)'
    static_libs: [
        "services.core",
        "services.accessibility",
        "services.appwidget",
        "services.autofill",
        "services.backup",
        "services.companion",
        "services.coverage",
        "services.devicepolicy",
        "services.midi",
        "services.net",
        "services.print",
        "services.restrictions",
        "services.usage",
        "services.usb",
        "services.voiceinteraction",
        "android.hidl.base-V1.0-java",
        "services.data_test",
    ],

4.在需要引用的模块的Android.bp中添加services.data_test
如我需要在PackageManagerService.java中引用test-debug.aar,则需要在frameworks\base\services\core\Android.bp中添加:
    libs: [
        "services.net",
        "android.hardware.light-V2.0-java",
        "android.hardware.power-V1.0-java",
        "android.hardware.tv.cec-V1.0-java",
        "android.hidl.manager-V1.0-java",
        "services.data_test",
    ],
(因为PackageManagerService.java在frameworks\base\services\core\java\com\android\server\pm目录下,离其最近的Android.bp中添加)

5.在PackageManagerService.java正常import及使用即可
import com.xxx.datatest.Mytest;//aar包中的包名
private void processPendingInstall(final InstallArgs args, final int currentStatus) {
        // Queue up an async operation since the package installation may take a little while.
        Log.d(TAG, "processPendingInstall ");

        Mytest.initForFramework(mContext);
        Mytest.hook("安装应用+1");
        ......
}

PS,也可以把test-debug.aar直接放置在\frameworks\base目录下。
步骤1需要做的修改是:在\frameworks\base目录下新建一个文件夹data_test,里面放test-debug.aar及Android.bp。
步骤2不需要修改,即Android.bp内容跟上面一样。
步骤3需要修改为在\frameworks\base\Android.bp中添加services.data_test:
    static_libs: [
        "framework-protos",
        "android.hidl.base-V1.0-java",
        "android.hardware.cas-V1.0-java",
        "android.hardware.contexthub-V1.0-java",
        "android.hardware.health-V1.0-java-constants",
        "android.hardware.thermal-V1.0-java-constants",
        "android.hardware.tv.input-V1.0-java-constants",
        "android.hardware.usb-V1.0-java-constants",
        "android.hardware.usb-V1.1-java-constants",
        "android.hardware.vibrator-V1.0-java",
        "android.hardware.vibrator-V1.1-java",
        "android.hardware.vibrator-V1.2-java",
        "android.hardware.wifi-V1.0-java-constants",
        "android.hardware.radio-V1.0-java",
        "android.hardware.usb.gadget-V1.0-java",
        "services.data_test",
    ],
步骤4及步骤5不需要修改。

 

 

你可能感兴趣的:(frameworks中引用aar包)