Search code examples
androidandroid-sourceandroid-constraintlayout

Error: missing android-support-constraint-layout in AOSP but prebuilts/sdk/current/extras has it


My Android source repo already has two jar files android-support-constraint-layout.jar and android-support-constraint-layout-solver.jar respectively at prebuilts/sdk/current/extras/constraint-layout/libs/ and prebuilts/sdk/current/extras/constraint-layout-solver/. Now, I have an app in packages/app, where I have an app/src/main/Android.mk:

LOCAL_STATIC_ANDROID_LIBRARIES := \
...
android-support-constraint-layout \
android-support-constraint-layout-solver

Still, I get the following error after compiling Android:

error: FirstApp (APPS android-x86) missing android-support-constraint-layout (JAVA_LIBRARIES android-x86)
You can set ALLOW_MISSING_DEPENDENCIES=true in your environment if this is intentional, but that may defer real problems until later in the build.
error: FirstApp (APPS android-x86) missing android-support-constraint-layout-solver (JAVA_LIBRARIES android-x86)

Except the first, none of the methods in this link works to add constraint-layout in AOSP.


Solution

  • I added constraint-layout in one of the packages in AOSP for Android-Oreo (v8.1).

    Download the constraint-layout (.aar) and constraint-layout-solver (.jar) from maven repository: https://mvnrepository.com/artifact/com.android.support.constraint/constraint-layout/1.0.2, https://mvnrepository.com/artifact/com.android.support.constraint/constraint-layout-solver/1.0.2 Put them in the libs/ folder in the app's home (packages/apps/AnotherFirstApp/).

    In Android.mk:

    LOCAL_PATH:= $(call my-dir)
    include $(CLEAR_VARS)
    
    LOCAL_PACKAGE_NAME := AnotherFirstApp
    LOCAL_MODULE_TAGS := optional
    LOCAL_DEX_PREOPT := false
    
    LOCAL_SRC_FILES := $(call all-java-files-under, src)
    
    LOCAL_PROGUARD_FLAG_FILES := ../../../frameworks/support/design/proguard-rules.pro
    
    
    ifeq ($(TARGET_BUILD_APPS),)
    support_library_root_dir := frameworks/support
    else
    support_library_root_dir := prebuilts/sdk/current/support
    endif
    
    LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res \
                          $(support_library_root_dir)/design/res \
                  $(support_library_root_dir)/v7/cardview/res \
                  $(support_library_root_dir)/v7/recyclerview/res \
                          $(support_library_root_dir)/v7/appcompat/res
    
    LOCAL_AAPT_FLAGS := \
        --auto-add-overlay \
        --extra-packages android.support.design \
        --extra-packages android.support.v7.cardview \
        --extra-packages android.support.constraint \
        --extra-packages android.support.v7.recyclerview \
        --extra-packages android.support.v7.appcompat
    
    LOCAL_STATIC_JAVA_LIBRARIES := \
        android-support-design \
        android-support-v7-recyclerview \
        android-support-v4 \
        android-support-v7-cardview \
        android-support-v7-appcompat \
        constraint-layout-solver \
    
    LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
                   constraint-layout
    
    include $(BUILD_PACKAGE)
    
    include $(CLEAR_VARS)
    
    LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
               constraint-layout:libs/constraint-layout-1.0.2.aar \
               constraint-layout-solver:libs/constraint-layout-solver-1.0.2.jar 
    
    include $(BUILD_MULTI_PREBUILT)
    
    include $(call all-makefiles-under,$(LOCAL_PATH))
    

    Now, there's no problem. The app builds and runs fine. There might be one issue because of not adding constraint-solver in a way like shared jar, in case other apps are also trying to use this jar. This needs to be handled by adding this jar in the framework or external.

    I got help from the following blogs:

    1. https://sites.google.com/site/sbobovyc/home/Programming/a/creating-system-app
    2. http://saurabhsharma123k.blogspot.com/2017/03/add-and-use-external-library-or-jar.html
    3. https://kevinaboos.wordpress.com/2016/10/29/adding-an-external-library-or-jarfile-to-android-frameworks/
    4. https://github.com/BrahmaOS/brahmaos-packages-apps-GoodWeather/blob/master/Android.mk