0

I am trying to add a VPN app as System App in AOSP. I have added all code of VPN app in AOSP_source/packages/app/securevpn. I have created an Android.mk file in this folder. I wrote my LOCAL_PACKAGE_NAME in PRODUCT_PACKAGES of /device/google/mydevice/aosp_mydevice.mk. Now When I compile AOSP i am getting some errors. Am i missing some thing Android.mk ? or some other mistake ?
Note:This app is working fine in Android Studio.

Following are errors

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)) #### 

Here is my 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

and Here are my gradle dependencies

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'

I have resolved all gradle dependencies by adding jar,aar files through make file but now I am facing another errors

New errors below

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)) ####
semw
  • 137
  • 1
  • 1
  • 10

1 Answers1

1

AOSP build system won't resolve your gradle dependencies by itself. It only takes into account what you add in your Android.mk.

Based on your error, there is some library that you're referring in those xml files, and that library is not found.

To fix this, you'd have to add those dependencies by yourself (aar or jar) and then refer to them in your makefile.

But, I'd really suggest to instead continue using Android Studio for development and just put the prebuilt APK in AOSP. It's far more straightforward, and will save you troubles down the road if you need to include yet another dependency.

Rick Sanchez
  • 4,528
  • 2
  • 27
  • 53
  • 1
    I have added some apps as pre-built APKs in AOSP but when I added this VPN app as pre-built APK in aosp it crashes, while if I install its APK in my device it works fine. I have also added its libraries in AOSP. but its not working. Thats why I am trying to add it from source code. If you can help in this I shall be grateful to you. – semw Oct 28 '20 at 04:54
  • Either post your layout file and we can debug this, or post another question with the error/crash you are getting as prebuilt. – Rick Sanchez Oct 28 '20 at 07:54
  • I can't post all xlms here (exceeding word type limit) but I have uploaded on this [link](https://drive.google.com/drive/folders/13Kkj5cA7u48HC2EvOU2pJx35_R6pxjFI?usp=sharing) , You can have a lot at them. I have also uploaded my Pre Build Apk errors [here](https://stackoverflow.com/questions/64735430/adding-pre-built-apk-vpn-in-aosp-crashes) Please check, Thanks – semw Nov 08 '20 at 09:20
  • Like I said in the answer, dependencies that you add in gradle have to be imported. For example in your xml some of the errors are due to com.google.android.gms.ads.AdView and others for CardView. Make sure to 'import' these ( and others for other errors) like you did for constraintlayout – Rick Sanchez Nov 08 '20 at 14:31
  • Can you please tell me how to import/add gradle dependencies in aosp ? – semw Nov 08 '20 at 14:37
  • 1
    You'd have to manually download the aar from maven and import them (search for how to import aar in AOSP, there are plenty of answers) – Rick Sanchez Nov 08 '20 at 18:11
  • I have added all gradle dependencies in make file, now new errors came. I have edited question with new errors. – semw Nov 10 '20 at 11:26