如何在AOSP项目中包含约束布局库 [英] How to include constraint layout library in an AOSP project

查看:315
本文介绍了如何在AOSP项目中包含约束布局库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的android应用程序,我想使用Android.mk在AOSP(android源码树)中构建.该应用程序使用的约束布局未包含在AOSP源代码树(AFAIK)中. 我如何满足这种依赖性?包括其他支持库,例如recyclerview,v4等,但不包含约束布局.

I have an existing android application that I'd like to build inside AOSP (android source tree) using Android.mk. The app uses constraint layout which is not included in AOSP source tree (AFAIK). How can I satisfy this dependency? Other support libs are included such as recyclerview, v4 etc but not contraint layout.

我应该下载lib aar吗?如果是,如何添加/包含它? 还是应该获取源代码(在何处下载?)并将其构建在源代码树中的某个位置?

Should I download the lib aar and if yes , how do I add/include it? Or should I get the source (where to download?) and build it somewhere in the source tree?

在此先感谢您的帮助.

推荐答案

有几种方法可以解决您的问题.

There are several ways to resolve your issue.

1.添加预构建的.apk

您不必将源代码放入AOSP树中. 您只需添加.apk文件,将其放在packages/apps/YourAppvendor/yourname/packages/apps/YourApp甚至your_dir_name/packages/apps/YourApp中,然后创建一个Android.mk文件用于构建系统来确定您的应用程序.

You don't have to put your source code to the AOSP tree. You can just add your .apk file, put it either in packages/apps/YourApp, or vendor/yourname/packages/apps/YourApp, or even your_dir_name/packages/apps/YourApp, and create an Android.mk file for build system to determine your application.

Android.mk如下所示:

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

LOCAL_MODULE := YourApplication # your .apk name
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)

include $(BUILD_PREBUILT)

优点:您可以使用gradle构建项目.

Pros: you can build your project with gradle.

2.将源代码添加到AOSP

如果您仍然希望将源代码放置到packages/apps并在此处构建,则可以将ConstrainsLayout放入项目的libs/目录中,然后将类似以下内容的内容添加到您的Android.mk中:

If you still want to place your source code to packages/apps and build it there, you can put a ConstrainsLayout to your project's libs/ directory and add to your Android.mk something like:

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

  # List of static libraries to include in the package
  LOCAL_STATIC_JAVA_LIBRARIES := constraint-layout

  # Build all java files in the java subdirectory
  LOCAL_SRC_FILES := $(call all-subdir-java-files)

  # Name of the APK
  LOCAL_PACKAGE_NAME := YourApplication

  # Tell it to build an APK
  include $(BUILD_PACKAGE)

以防万一您无法使用它(我尚未遇到此问题,

In case you will not get it work (I haven't met this issue, but he did):

LOCAL_STATIC_JAVA_LIBRARIES := libconstraint-layout

include $(BUILD_PACKAGE)

其他东西,最后

include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libconstraint-layout:libs/constraint-layout.aar

缺点:您必须使用mmamm -B的make来构建代码,或者使用gradle作为开发的第二个构建系统.第二个选项可以使用,但是要建立完整版本并在out/目录中建立.apk,您必须使用make进行构建.

Cons: You will have to build your code either with make by mma or mm -B, or to have a gradle as your second build system for development. The second option will work, but to establish a full build and to have your .apk built in out/ directory you will have to build it with make.

3.添加ConstraintLayout

如果要拥有多个使用约束布局的应用程序,则可以将其作为预编译的.aar作为新的库模块添加. 可以分别位于供应商/您的名称/库"或您的目录名称/库"中的某个位置. 这类似于添加预构建的.apk:

In case you want to have several applications, which use a constraint layout, you can add it as a new library module as precompiled .aar. Can be somewhere in 'vendor/yourname/libs' or 'your_dir_name/libs' respectively. It is similar to adding a prebuilt .apk:

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

LOCAL_MODULE := constraint-layout
LOCAL_SRC_FILES := $(LOCAL_MODULE).aar
LOCAL_MODULE_SUFFIX := .aar

include $(BUILD_PREBUILT)

之后,您必须在应用程序的Android.mk中添加:

After that, in your application's Android.mk you will have to add:

LOCAL_STATIC_JAVA_LIBRARIES := constraint-layout

或者,您也可以在prebuilds/上添加ConstraintLayout.aar,因为它终有一天会出现.

Alternatively, you can add a ConstraintLayout's .aar to the prebuilds/ as it eventually will be there someday.

关于Android.mk有一个很好的话题: https://wladimir-tm4pda .github.io/porting/build_cookbook.html

There is a good topic about Android.mk: https://wladimir-tm4pda.github.io/porting/build_cookbook.html

这篇关于如何在AOSP项目中包含约束布局库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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