Nativescript-cli: Android - NS5 build fails with android resource linking failed

Created on 22 Nov 2018  路  4Comments  路  Source: NativeScript/nativescript-cli

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
CLI: 5.0.1
Android Runtime: 5.0.0
iOS Runtime (if applicable): 5.0.0
Plugin(s): see Package.JSON below

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.nativescript.xyz",
    "tns-ios": {
      "version": "5.0.0"
    },
    "tns-android": {
      "version": "5.0.0"
    }
  },
  "dependencies": {
    "@angular/animations": "~7.0.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "nativescript-algolia": "^1.1.0",
    "nativescript-angular": "^7.0.0",
    "nativescript-camera": "^4.0.2",
    "nativescript-email": "^1.5.3",
    "nativescript-filter-select": "^1.2.9",
    "nativescript-filterable-listpicker": "^2.2.3",
    "nativescript-geolocation": "^4.2.6",
    "nativescript-imagepicker": "^6.0.4",
    "nativescript-iqkeyboardmanager": "^1.3.0",
    "nativescript-ngx-slides": "^6.1.0",
    "nativescript-pdf-view": "^2.0.1",
    "nativescript-plugin-firebase": "^7.4.2",
    "nativescript-social-share": "^1.5.0",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-toast": "^1.4.6",
    "nativescript-ui-listview": "^3.8.0",
    "nativescript-web-image-cache": "^4.2.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.2.2",
    "tns-core-modules": "^5.0.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~6.1.0",
    "@ngtools/webpack": "~6.2.0",
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "codelyzer": "^4.4.4",
    "es6-promise-loader": "^1.0.2",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "^0.7.3",
    "nativescript-dev-webpack": "^0.17.0",
    "prettier": "^1.11.1",
    "tslint": "^5.1.0",
    "typescript": "~3.1.1",
    "webpack": "^4.25.1",
    "zone.js": "^0.8.26"
  },
}

Describe the bug
On executing tns run android, i get the following error log:

Building project...
Gradle build...
         + setting applicationId
         + applying user-defined configuration from /Users/krithika/Projects/<AppName>/app/App_Resources/Android/app.gradle
         Applying settings from /Users/krithika/Projects/<AppName>/app/App_Resources/Android/settings.json
Using support library version 28.0.0
         + adding nativescript runtime package dependency: nativescript-optimized-with-inspector
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-algolia/platforms/android/nativescript_algolia.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-camera/platforms/android/nativescript_camera.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-filterable-listpicker/platforms/android/nativescript_filterable_listpicker.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-geolocation/platforms/android/nativescript_geolocation.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-plugin-firebase/platforms/android/firebase-release.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-social-share/platforms/android/nativescript_social_share.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-ui-listview/platforms/android/TNSListView-release.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-web-image-cache/platforms/android/nativescript_web_image_cache.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/nativescript-ui-core/platforms/android/TNSCore-release.aar
         + adding aar plugin dependency: /Users/krithika/Projects/<AppName>/node_modules/tns-core-modules-widgets/platforms/android/widgets-release.aar
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Android resource linking failed
  Output:  /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml:31: error: resource drawable/icon (aka org.nativescript.qbank:drawable/icon) not found.
  error: failed processing manifest.

  Command: /Users/krithika/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/2eed916ddcf9151ce53f774e84877768/aapt2-3.2.1-4818971-osx/aapt2 link -I\
          /usr/local/share/android-sdk/platforms/android-28/android.jar\
          --manifest\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml\
          -o\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/processed_res/debug/processDebugResources/out/resources-debug.ap_\
          -R\
          @/Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/incremental/processDebugResources/resources-list-for-resources-debug.ap_.txt\
          --auto-add-overlay\
          --java\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r\
          --proguard-main-dex\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/legacy_multidex_aapt_derived_proguard_rules/debug/processDebugResources/manifest_keep.txt\
          --custom-package\
          org.nativescript.qbank\
          -0\
          apk\
          --no-version-vectors\
          --output-text-symbols\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/symbols/debug/R.txt\
          --no-version-vectors
  Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0
  Output:  /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml:31: AAPT: error: resource drawable/icon (aka org.nativescript.qbank:drawable/icon) not found.

  error: failed processing manifest.
  Command: /Users/krithika/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/2eed916ddcf9151ce53f774e84877768/aapt2-3.2.1-4818971-osx/aapt2 link -I\
          /usr/local/share/android-sdk/platforms/android-28/android.jar\
          --manifest\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml\
          -o\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/processed_res/debug/processDebugResources/out/resources-debug.ap_\
          -R\
          @/Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/incremental/processDebugResources/resources-list-for-resources-debug.ap_.txt\
          --auto-add-overlay\
          --java\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r\
          --proguard-main-dex\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/legacy_multidex_aapt_derived_proguard_rules/debug/processDebugResources/manifest_keep.txt\
          --custom-package\
          org.nativescript.qbank\
          -0\
          apk\
          --no-version-vectors\
          --output-text-symbols\
          /Users/krithika/Projects/<AppName>/platforms/android/app/build/intermediates/symbols/debug/R.txt\
          --no-version-vectors
  Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0

Additional context
IOS project runs as expected with NS 5.

android

Most helpful comment

The error was happening because of the change in directory structure of the for android resources within App_Resources folder. Even though the new folders had been created within the src directory they were empty and did not contain the required files.
Deleting the src directory in App_Resources/Android and running tns resources update fixed this issue but I am getting another error posted here.

All 4 comments

@anuragd7 can you try to upgrade your compileSdkVersion to 28

@NickIliev I tried adding compileSdkVersion 28 to my app.gradle. Next I deleted and then added android platform. However I still get the same error on tns run android.

the contents of my app.gradle file are as follows:

// Add your native dependencies here:
dependencies {
    compile 'com.facebook.android:facebook-android-sdk:4.6.0'
    // compile 'com.google.android.gms:play-services-auth:8.4.0'

    // compile('com.twitter.sdk.android:twitter:1.13.2@aar') {
    //     transitive = true
    // }
    configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}
}

// Uncomment to add recyclerview-v7 dependency
//dependencies {
//  compile 'com.android.support:recyclerview-v7:+'
//}

android {  
  compileSdkVersion 28
  defaultConfig {  
    generatedDensities = []
    applicationId = "org.nativescript.XYZ" 
    multiDexEnabled true

    //override supported platforms
    // ndk {
    //       abiFilters.clear()
    //          abiFilters "armeabi-v7a"
        // }

  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  

  project.ext {
    googlePlayServicesVersion = "15.0.1"
  }
} 

def settingsGradlePath

if(project.hasProperty("appResourcesPath")){
    settingsGradlePath = "$project.appResourcesPath/Android/settings.gradle";
} else {
    settingsGradlePath = "$rootDir/../../app/App_Resources/Android/settings.gradle";
}

def settingsGradleFile = new File(settingsGradlePath);

if(settingsGradleFile.exists())
{
    apply from: settingsGradleFile;
}
// project.ext.supportVersion = "26.0.0.-alpha1"

The error was happening because of the change in directory structure of the for android resources within App_Resources folder. Even though the new folders had been created within the src directory they were empty and did not contain the required files.
Deleting the src directory in App_Resources/Android and running tns resources update fixed this issue but I am getting another error posted here.

Thank you so much!!!
I'm hardstuck in this problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

farfromrefug picture farfromrefug  路  3Comments

kefahB picture kefahB  路  3Comments

NickIliev picture NickIliev  路  3Comments

ZMW9 picture ZMW9  路  3Comments

charsleysa picture charsleysa  路  3Comments