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

查看:30
本文介绍了如何在 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/code> 目录并添加到您的 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

缺点:您必须使用 make by mmamm -B 来构建代码,或者使用 gradle 作为您的代码用于开发的第二个构建系统.第二个选项可行,但要建立完整的构建并将 .apk 构建在 out/ 目录中,您必须使用 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.添加约束布局

如果您想拥有多个使用约束布局的应用程序,您可以将其作为新库模块添加为预编译的 .aar.可以分别位于 'vendor/yourname/libs' 或 'your_dir_name/libs' 中的某个位置.它类似于添加一个预构建的 .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

或者,您可以将 ConstraintLayout.aar 添加到 prebuilds/ 中,因为它最终会在某一天出现.

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天全站免登陆