本文介绍了错误:AOSP中缺少android-support-constraint-layout,但是prebuilts/sdk/current/extras有它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android源存储库已经分别在prebuilts/sdk/current/extras/constraint-layout/libs/prebuilts/sdk/current/extras/constraint-layout-solver/处具有两个jar文件android-support-constraint-layout.jarandroid-support-constraint-layout-solver.jar.现在,我在packages/app中有一个应用,其中有一个app/src/main/Android.mk:

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

仍然,编译Android后出现以下错误:

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)

除了第一个,中的任何方法此链接用于在AOSP中添加约束布局.

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

推荐答案

我在AOSP for Android-Oreo(v8.1)的一个软件包中添加了约束布局.

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

从maven存储库下载constraint-layout(.aar)和constraint-layout-solver(.jar): 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 将它们放在应用程序主目录(packages/apps/AnotherFirstApp/)中的libs/文件夹中.

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.2Put them in the libs/ folder in the app's home (packages/apps/AnotherFirstApp/).

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))

现在,没有问题.该应用程序可以构建并正常运行.由于未以共享jar之类的方式添加constraint-solver,因此可能存在一个问题,以防其他应用程序也尝试使用此jar.这需要通过在frameworkexternal中添加此jar来解决.

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
  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

这篇关于错误:AOSP中缺少android-support-constraint-layout,但是prebuilts/sdk/current/extras有它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 13:05