Android support in Android.mk

Now I am creating a custom ROM for Android. The aosp build system is based on Android.mk, but I want to include some aar libraries, is it possible to include in the Ap-libraries in Android.mk?

+8
android aar android-build
source share
2 answers

You must add the following blocks to your Android.mk

LOCAL_STATIC_JAVA_AAR_LIBRARIES:= <aar alias> . . . include $(BUILD_PACKAGE) include $(CLEAR_VARS) LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := <aar alias>:libs/<lib file>.aar include $(BUILD_MULTI_PREBUILT) 

Also note the minSdkVersion satisfaction required by the library in the manifest file.

+9
source share

Konstantin Luzan's answer has a problem. After compilation, the resources in aar will be added to my main package R file, but not to the RAR file of the AAR package. For example, the package name aar is my.aar, the main name of the project package is my.main. Aar has a string named "string_in_aar". After compilation, the line identifier is my.main.R.string_in_aar, not my.aar.R.string_in_aar. This causes apk to crash because the code in aar uses my.aar.R.string_in_aar.

The solution is to use: LOCAL_AAPT_FLAGS + = --extra-packages {package name aar}. You will get two R. files. They have some content. One package is the main package, the other is the aar package.

+5
source share

All Articles