如何在AOSP构建期间使用约束布局而不包含外部.aar和.jar [英] How to use constraint-layout during AOSP build without including external .aar and .jar

查看:199
本文介绍了如何在AOSP构建期间使用约束布局而不包含外部.aar和.jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过构建为AOSP源代码中的模块来构建基于Java的android应用程序.我的应用程序使用android.support.constraint.ConstraintLayout.但是,我没有找到在Android.mk中包含约束布局依赖项的直接方法.

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.

我已将项目放在AOSP_ROOT/packages/apps下,并尝试使用此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:

忍者:错误:'out/target/common/obj/APPS/MyApp_intermediates/AndroidManifest需要'out/target/common/obj/JAVA_LIBRARIES/android-support-constraint-layout_intermediates/aar/classes.jar'. xml",丢失,尚无已知规则 20:57:54忍者失败,退出状态为1

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

我了解的-它正在搜索可以从.aar文件构建的classes.jar,但是缺少它.但是,这里的答案解决了这个问题:如何包含AOSP项目中的约束布局库

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

但是,问题是,该答案建议在我的项目libs目录中添加外部constraint-layout.aarconstraint-layout-solver.jar.

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

我的问题,是否可以在AOSP中使用内置库在项目中添加constraint-layout支持,而无需在项目中添加外部.aar.jar?

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?

推荐答案

无论如何,我已经找到了解决方案.无需将constraint-layout作为额外的库包含在项目libs中.

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

要解决此问题,在Android.mk中,我们需要添加一行:

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

LOCAL_USE_AAPT2 := true

并且还使用LOCAL_STATIC_ANDROID_LIBRARIES代替LOCAL_STATIC_JAVA_AAR_LIBRARIES.

这是有效的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)

这篇关于如何在AOSP构建期间使用约束布局而不包含外部.aar和.jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆