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

1

1

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?

Forby answered 25/7, 2020 at 16:16 Comment(0)
F
2

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)
Forby answered 25/7, 2020 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.