Android 如何在 AOSP 版本中添加 APK?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10579827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:14:34  来源:igfitidea点击:

How do I add APKs in an AOSP build?

androidandroid-source

提问by CodeGuru

I need to add some 3rd party APKs to my AOSP build. What folder should I keep these APKs so that when I build the code and the image is created, it is installed in the emulator?

我需要在我的 AOSP 构建中添加一些 3rd 方 APK。我应该将这些 APK 保存在哪个文件夹中,以便在构建代码和创建图像时将其安装在模拟器中?

It looks like the system apps are kept in the packages/appfolder so I need to know where the third party APKs are kept.

看起来系统应用程序保存在包/应用程序文件夹中,所以我需要知道第三方 APK 的保存位置。

回答by Tiago Costa

Adding third party APKs to the build is definitely possible.

将第三方 APK 添加到构建中绝对是可能的。

Also APKs and APPs with source code go to the same place; the package/appfolder.

也有源代码的 APK 和 APP 去同一个地方;该package/app文件夹。

Adding a new APK to the build

将新的 APK 添加到构建中

In the AOSP root add the folder:

在 AOSP 根目录中添加文件夹:

<aosp root>/package/app/< yourappfolder >

<aosp root>/package/app/< yourappfolder >

Then inside this folder add:

然后在这个文件夹中添加:

  • empty Android.mk
  • < yourapp.apk >
  • 空的 Android.mk
  • < yourapp.apk >

The android make file should have the reference to your apk, add this to your Android.mk:

android make 文件应该包含对您的 apk 的引用,将其添加到您的Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE := < your app folder name >

LOCAL_CERTIFICATE := < desired key >

LOCAL_SRC_FILES := < app apk filename >

LOCAL_MODULE_CLASS := APPS

LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)

include $(BUILD_PREBUILT)

Create an entry in the commons.mk(from AOSP 8.1.0 onwards it is called core.mk, and is usually found in build/target/product) for your apk add the line (check where all the others are)

在您的 apk 中创建一个条目commons.mk(从 AOSP 8.1.0 开始,它被称为core.mk,通常可以在 中找到build/target/product)添加该行(检查所有其他人的位置)

PRODUCT_PACKAGES += < what you have defined in LOCAL_MODULE, it should be your app folder name >

Compile the AOSP and you have a brand new app installed on the system.

编译 AOSP,您就会在系统上安装一个全新的应用程序。

Notes

笔记

  • If your APK is already signed, use the special value PRESIGNEDas value for LOCAL_CERTIFICATE
  • If you want your APK to end up in the /data/app/directory, add the line LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)before the line include $(BUILD_PREBUILT)
  • 如果您的 APK 已经签名,请使用特殊值PRESIGNED作为LOCAL_CERTIFICATE
  • 如果您希望您的 APK 最终出现在/data/app/目录中,请在该行LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)之前添加该行include $(BUILD_PREBUILT)

回答by user3913384

The Android.mk presented above will install the APK in /system/app

上面显示的 Android.mk 将在 /system/app 中安装 APK

If you wish to install the APK in /data/app you will need to add the following the line to Android.mk before line include $(BUILD_PREBUILT)

如果您希望在 /data/app 中安装 APK,则需要将以下行添加到 Android.mk 行之前 include $(BUILD_PREBUILT)

LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)

回答by Justin Buser

You could also do the following in the target output dir:

您还可以在目标输出目录中执行以下操作:

<path-to-your-build-dir>/host/linux-x86/bin/simg2img system.img temp.img
mkdir system_root
sudo mount -t ext4 -o loop temp.img system_root

At this point you can make whatever changes you'd like to the files in system_root, i.e. adding apks to system/app etc...

此时,您可以对 system_root 中的文件进行任何您想要的更改,即将 apks 添加到 system/app 等...

When you're done just go back down to the output dir and do:

完成后,返回到输出目录并执行以下操作:

sudo umount system_root
<path-to-your-build-dir>/host/linux-x86/bin/img2simg temp.img system.img

You can now flash system.img using fastboot as usual.

您现在可以像往常一样使用 fastboot 刷新 system.img。