AOSP 项目中的 AAR

huangapple go评论73阅读模式
英文:

AAR in AOSP Project

问题

我一直在尝试将一个aar文件添加到使用AOSP开发的应用程序中,使用我的Android.mk文件中的以下部分:

...
LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
    aar-lib    
LOCAL_AAPT_FLAGS := --auto-add-overlay \
--extra-packages com.mypackage.name

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
    aar-libr:libs/aarname.aar
...

许多中间文件被创建在out/target/common/obj/JAVA_LIBRARIESout/target/common/R文件夹中。然而,我似乎无法真正导入aar中的包。例如,aar本身包含一个带有classes.jar存档的libs文件夹。但导入包含的类的导入语句在构建时引发错误。

我正在使用目标SDK版本28进行工作。是否有方法解决这些依赖关系问题?

英文:

I have been trying to add an aar file to my application developed with the AOSP using the following section of my Android.mk:

...
LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
    aar-lib    
LOCAL_AAPT_FLAGS := --auto-add-overlay \
--extra-packages com.mypackage.name

include $(BUILD_PACKAGE)

include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
    aar-libr:libs/aarname.aar
...

A bunch of immediates are created in the out/target/common/obj/JAVA_LIBRARIES and in the out/target/common/R folder. However, I do not seem to be able to actually import the packages contained in the aar. For example, the aar itself contains a libs folder with a classes.jar archive. But the import statements for contained classes cause errors when building.

I am working with the target sdk version 28.
Is there a way to resolve these dependency issues?

答案1

得分: 1

如果您倾向于在您的应用中使用 Android.bp,可以尝试以下方法来定义库:

android_library_import {
    name: "your-lib-name",
    aars: ["your-lib-file-name.aar"],
    sdk_version: "current",
    min_sdk_version: "28", // 可选
}

然后在您的 android_appstatic_libs 中添加上述定义的名称。

英文:

If you tend to use Android.bp for your app, try this approach for defining the library:

android_library_import {
    name: "your-lib-name",
    aars: ["your-lib-file-name.aar"],
    sdk_version: "current",
    min_sdk_version: "28", // optional
}

and add the name defined above in your android_app's static_libs

huangapple
  • 本文由 发表于 2020年6月5日 20:23:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/62215317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定