首页 > 解决方案 > 从应用程序源代码在 AOSP 中添加系统应用程序(安全 VPN)

问题描述

我正在尝试在 AOSP中添加一个 VPN 应用程序作为系统应用程序。我在AOSP_source/packages/app/securevpn中添加了 VPN 应用程序的所有代码。我在这个文件夹中创建了一个 Android.mk 文件。我写了我LOCAL_PACKAGE_NAMEPRODUCT_PACKAGES/device/google/mydevice/aosp_mydevice.mk现在,当我编译 AOSP 时,我遇到了一些错误。我错过了什么Android.mk吗?还是其他错误?
注意:此应用在 Android Studio 中运行良好。

以下是错误

packages/apps/securevpn/res/layout/activity_content.xml:22: error: attribute cardCornerRadius (aka com.technoupdate.securevpn:cardCornerRadius) not found.
packages/apps/securevpn/res/layout/activity_content.xml:22: error: attribute cardPreventCornerOverlap (aka com.technoupdate.securevpn:cardPreventCornerOverlap) not found.
packages/apps/securevpn/res/layout/activity_current_status.xml:18: error: resource drawable/md_nav_back (aka com.technoupdate.securevpn:drawable/md_nav_back) not found.
packages/apps/securevpn/res/layout/activity_current_status.xml:162: error: attribute adSize (aka com.technoupdate.securevpn:adSize) not found.
packages/apps/securevpn/res/layout/activity_current_status.xml:162: error: attribute adUnitId (aka com.technoupdate.securevpn:adUnitId) not found.
packages/apps/securevpn/res/layout/activity_details.xml:53: error: resource drawable/md_nav_back (aka com.technoupdate.securevpn:drawable/md_nav_back) not found.
packages/apps/securevpn/res/layout/activity_details.xml:310: error: attribute adSize (aka com.technoupdate.securevpn:adSize) not found.
packages/apps/securevpn/res/layout/activity_details.xml:310: error: attribute adUnitId (aka com.technoupdate.securevpn:adUnitId) not found.
packages/apps/securevpn/res/layout/motion_drawerlayout_content.xml:2: error: attribute layoutDescription (aka com.technoupdate.securevpn:layoutDescription) not found.
packages/apps/securevpn/res/layout/motion_drawerlayout_menu.xml:2: error: attribute layoutDescription (aka com.technoupdate.securevpn:layoutDescription) not found.
packages/apps/securevpn/res/xml/scene_content.xml:18: error: attribute constraintSetEnd (aka com.technoupdate.securevpn:constraintSetEnd) not found.
packages/apps/securevpn/res/xml/scene_content.xml:18: error: attribute constraintSetStart (aka com.technoupdate.securevpn:constraintSetStart) not found.
packages/apps/securevpn/res/xml/scene_content.xml:18: error: attribute duration (aka com.technoupdate.securevpn:duration) not found.
packages/apps/securevpn/res/xml/scene_content.xml:18: error: attribute motionInterpolator (aka com.technoupdate.securevpn:motionInterpolator) not found.
packages/apps/securevpn/res/xml/scene_main_content.xml:312: error: attribute constraintSetEnd (aka com.technoupdate.securevpn:constraintSetEnd) not found.
packages/apps/securevpn/res/xml/scene_main_content.xml:312: error: attribute constraintSetStart (aka com.technoupdate.securevpn:constraintSetStart) not found.
packages/apps/securevpn/res/xml/scene_main_content.xml:312: error: attribute duration (aka com.technoupdate.securevpn:duration) not found.
packages/apps/securevpn/res/xml/scene_main_content.xml:312: error: attribute motionInterpolator (aka com.technoupdate.securevpn:motionInterpolator) not found.
packages/apps/securevpn/res/xml/scene_main_content.xml:318: error: attribute dragDirection (aka com.technoupdate.securevpn:dragDirection) not found.
15:22:33 ninja failed with: exit status 1

#### failed to build some targets (01:35 (mm:ss)) #### 

这是我的 Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := securevpn
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_USE_AAPT2 := true
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false

LOCAL_STATIC_ANDROID_LIBRARIES += \
    androidx.appcompat_appcompat \
    androidx-constraintlayout_constraintlayout \

include $(BUILD_PACKAGE)

endif

这是我的 gradle 依赖项

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintLayoutVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifeCycleVersion"
implementation "com.google.android.material:material:$rootProject.materialVersion"
implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation "android.arch.work:work-runtime-ktx:1.0.1"
implementation 'com.google.android.gms:play-services-ads:19.1.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.github.AppIntro:AppIntro:5.1.0'

我已经通过 make 文件添加 jar、aar 文件解决了所有 gradle 依赖项,但现在我面临另一个错误

下面的新错误

packages/apps/securevpn/src/main/Android.mk: error: "securevpn (APPS android-arm64) missing libmaterial (JAVA_LIBRARIES android-arm64)" 
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.
packages/apps/securevpn/src/main/Android.mk: error: "securevpn (APPS android-arm64) missing libcore (JAVA_LIBRARIES android-arm64)" 
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.
packages/apps/securevpn/src/main/Android.mk: error: "securevpn (APPS android-arm64) missing libwork-runtime-ktx (JAVA_LIBRARIES android-arm64)" 
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.
packages/apps/securevpn/src/main/Android.mk: error: "securevpn (APPS android-arm64) missing libmultidex (JAVA_LIBRARIES android-arm64)" 
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.
packages/apps/securevpn/src/main/Android.mk: error: "securevpn (APPS android-arm64) missing android-arm64 (JAVA_LIBRARIES android-arm64)" 
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.
build/make/core/main.mk:948: error: exiting from previous errors.
16:15:46 ckati failed with: exit status 1

#### failed to build some targets (01:21 (mm:ss)) ####

标签: androidxmlvpnandroid-source

解决方案


AOSP 构建系统不会自行解决您的 gradle 依赖关系。它只考虑您在 Android.mk 中添加的内容。

根据您的错误,您在这些 xml 文件中引用了一些库,但找不到该库。

要解决此问题,您必须自己添加这些依赖项(aar 或 jar),然后在您的 makefile 中引用它们。

但是,我真的建议继续使用 Android Studio 进行开发,并将预构建的 APK 放入 AOSP 中。它要简单得多,如果您需要包含另一个依赖项,它将为您省去麻烦。


推荐阅读