How to use constraint-layout during AOSP build without including external .aar and .jar

痴心易碎 提交于 2020-08-10 04:57:24

问题


I'm trying to build my java based android app through building as a module inside AOSP source. My app uses android.support.constraint.ConstraintLayout. But, I didn't find a direct way to include constraint-layout dependency in my Android.mk.

I've put my project under AOSP_ROOT/packages/apps and tried with this Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true                 
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true

LOCAL_SRC_FILES := $(call all-java-files-under, java) 
LOCAL_MANIFEST_FILE := AndroidManifest.xml

LOCAL_AAPT_FLAGS := \
    --auto-add-overlay \
    --extra-packages android.support.constraint

LOCAL_STATIC_JAVA_LIBRARIES := \
    android-common \
    android-support-v4 \
    android-support-constraint-layout-solver

LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
    android-support-constraint-layout

include $(BUILD_PACKAGE)

But, this comes up with build error:

ninja: error: 'out/target/common/obj/JAVA_LIBRARIES/android-support-constraint-layout_intermediates/aar/classes.jar', needed by 'out/target/common/obj/APPS/MyApp_intermediates/AndroidManifest.xml', missing and no known rule to make it 20:57:54 ninja failed with: exit status 1

What I understand - it is searching for classes.jar which could be built from .aar file, but it is missing. However, the answer here solves the issue: How to include constraint layout library in an AOSP project

But, the problem is, that answer suggests to add external constraint-layout.aar and constraint-layout-solver.jar within my project libs directory.

My question, is it possible to add constraint-layout support in my project using built-in library inside AOSP without adding external .aar and .jar to my project?


回答1:


Anyways, I've found the solution. There is no need to include the constraint-layout in the project libs as extra library.

To solve the issue, in Android.mk we need to add one extra line:

LOCAL_USE_AAPT2 := true

And also use LOCAL_STATIC_ANDROID_LIBRARIES instead of LOCAL_STATIC_JAVA_AAR_LIBRARIES.

This is the working Android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true                 
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true

LOCAL_USE_AAPT2 := true

LOCAL_SRC_FILES := $(call all-java-files-under, java) 
LOCAL_MANIFEST_FILE := AndroidManifest.xml

LOCAL_AAPT_FLAGS := \
    --auto-add-overlay \
    --extra-packages android.support.constraint

LOCAL_STATIC_ANDROID_LIBRARIES:= \
    android-support-constraint-layout

LOCAL_STATIC_JAVA_LIBRARIES := \
    android-common \
    android-support-v4 \
    android-support-constraint-layout-solver

include $(BUILD_PACKAGE)


来源:https://stackoverflow.com/questions/63090643/how-to-use-constraint-layout-during-aosp-build-without-including-external-aar-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!