Nativescript: Play Services now using AndroidX

Created on 18 Jun 2019  路  19Comments  路  Source: NativeScript/NativeScript

Nativescript: 5.4.2
Android: 5.4.0

Clean builds starting today fail with:

    + adding aar plugin dependency: C:\Users\lweidig\ownCloud\CodeRepo\nativscript\excelnet-installer\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
C:\myapp\platforms\android\app\src\main\AndroidManifest.xml:22:18-91 Error:
        Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:19:5-37:19 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:19:5-37:19 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 28s

We use Google Maps, Phone and many other plugins that might be related to Play service. I see on the Google site:

https://developers.google.com/android/guides/releases#june_17_2019

Breaking changes in the API. Have been looking for a fix to this all day. Any thoughts would be appreciated.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

known-issue android

Most helpful comment

We have made some progress just recently. We had the app->App_Resources->Android->before-plugins.gradle file which looked like:

android {  
  project.ext {
      googlePlayServicesVersion = "+"
  }
} 

Changed that file to:

android {  
  project.ext {
      googlePlayServicesVersion = "16.0.0"
  }
} 

The application now builds 100%, we just are experiencing crashes in the app now. But it does seem as though this is progress somehow :)

All 19 comments

Hi, I have the same issue with google-maps-sdk plugin.
I've not already found a solution for this.

Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:19:5-37:19 to override.

Is the output message.
I hope that you can help me

Hi, we have the same issue. Please if you found anything share with me.
Thanx

We have made some progress just recently. We had the app->App_Resources->Android->before-plugins.gradle file which looked like:

android {  
  project.ext {
      googlePlayServicesVersion = "+"
  }
} 

Changed that file to:

android {  
  project.ext {
      googlePlayServicesVersion = "16.0.0"
  }
} 

The application now builds 100%, we just are experiencing crashes in the app now. But it does seem as though this is progress somehow :)

Maybe this can be helpful

It works!

Perfect @ExcelNet-Public

We're currently building with no issues with the following config on before-plugins.gradle:

ext {
  supportVersion = "28.+"
  googlePlayServicesVersion = "16.+"
}

This also makes sure we're using the latest minor/patch versions.

Related to this breaking change from Google Play Services SDK https://developers.google.com/android/guides/releases

The latest update to Google Play services and Firebase includes the following changes:

Migration from Android Support Libraries to Jetpack (AndroidX) Libraries. Libraries will not work unless you make the following changes in your app:

Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later.
Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.

NativeScript is already working on migration to AndroidX but until that, use the solutions provided by @ExcelNet-Public or by @edusperoni (reverting to an older version of Google Play Services)

@edusperoni Thanks, this is a more complete solution than the one I posted. Using this and have application back up and running. Now back to coding!

Temporary reopening the issue (+ marking it as a known issue) for more visibility.

@NickIliev These solutions didn't work for me. I created before-plugins.gradle file under the route @ExcelNet-Public provided, since this file didn't exist in my project, with this code:

android {  
  project.ext {
    supportVersion = "28.+"
    googlePlayServicesVersion = "16.+"
  }
} 

Removed android platform and then built again. This is the output:

* What went wrong:
Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
        is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:22:2-50:16 to override.

@cerealexx the solution will work only for NativeScript plugins which are using the googlePlayServicesVersion exported variable (e.g., like done here).

However, if the plugin is not using the exported variable and is directly setting the Google Play Services version of _latest_ then the solution won't work. In such case, you will need to manually track where the dependency version is set and to change it from latest to a previous version of the library, which is not containing the AndoirdX breaking change.

I am not able to find a plugin that directly sets the version but see for example how the google-maps-sdk plugin is setting the version of the library

    def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : '+'
    compile "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"

The above will look for googlePlayServicesVersion and if such is present (from before-plugins.gradle) will use its value. Otherwise, it will set + which means take _latest_

Meaning that if you see a plugin that sets the _latest_ version like this

compile "com.google.android.gms:play-services:+"

you will have to change and rebuild with a previous version

compile "com.google.android.gms:play-services:16.0.0"

If you are still not able to resolve your issue, please post the package.json content so I could try to reproduce the problem.

@NickIliev In which dir in my project should I execute this search? I've searched in 'platforms' files but no result was returned.

Here's my package.json just in case:

{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "tns-ios": {
      "version": "5.4.2"
    },
    "tns-android": {
      "version": "5.4.0"
    }
  },
  "dependencies": {
    "@angular/animations": "~6.0.0",
    "@angular/common": "~6.0.0",
    "@angular/compiler": "~6.0.0",
    "@angular/core": "~6.0.0",
    "@angular/forms": "~6.0.0",
    "@angular/http": "~6.0.0",
    "@angular/platform-browser": "~6.0.0",
    "@angular/platform-browser-dynamic": "~6.0.0",
    "@angular/router": "~6.0.0",
    "@localization/l10n": "^2.1.7",
    "@nstudio/nativescript-camera-plus": "^2.2.0",
    "@teammaestro/nativescript-svg": "^1.0.1",
    "lodash": "^4.17.11",
    "nativescript-angular": "~6.0.0",
    "nativescript-checkbox": "^3.0.3",
    "nativescript-facebook": "^4.1.0",
    "nativescript-fcuuid": "^1.0.2",
    "nativescript-iqkeyboardmanager": "^1.3.0",
    "nativescript-localstorage": "^1.1.5",
    "nativescript-mixpanel": "^2.0.1",
    "nativescript-ngx-shadow": "^6.1.0",
    "nativescript-ngx-slides": "^6.1.0",
    "nativescript-orientation": "^2.2.1",
    "nativescript-pedometer": "^2.0.2",
    "nativescript-plugin-firebase": "^8.3.2",
    "nativescript-speech-recognition": "^1.4.1",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-toasty": "^1.3.0",
    "nativescript-ui-gauge": "^3.7.1",
    "nativescript-ui-sidedrawer": "^5.0.0",
    "reflect-metadata": "~0.1.8",
    "rxjs": "^6.2.0",
    "tns-core-modules": "^5.4.2",
    "tns-platform-declarations": "^5.2.1",
    "ts-md5": "^1.2.4",
    "zone.js": "^0.8.26"
  },
  "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",
    "commitizen": "^2.10.1",
    "cz-conventional-changelog": "2.1.0",
    "lazy": "1.0.11",
    "nativescript-dev-sass": "^1.6.0",
    "nativescript-dev-typescript": "~0.7.0",
    "nativescript-dev-webpack": "0.24.0",
    "typescript": "2.9.2"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}

@cerealexx each plugin that uses native libraries has its own platforms folder which contains either the native library (*.aar) or/and include.gradle with dependencies section. You should check the ones that are requiring the gms library.

Update: @cerealexx I've created this project using all the dependencies from the package.json and I was able to build with no issues. Note that I have updated all dependencies to use the latest version. Perhaps, you could check what firebase functionalities are used in your app.

Another thing to check out if you have requested the Google Play Services in the app.gradle (and if so verify that you are not requesting latest version)

Note: "tns-platform-declarations": "^5.2.1" should be used as devDependency and never as a dependency (otherwise your app in production will be a lot bigger in size)

For additional details about this issue please refer to this blog post

Mystery solved. I had the following code in app.gradle:

dependencies {
  compile 'com.google.android.gms:play-services-gcm:+'
}

Changed it to:

dependencies {
  compile 'com.google.android.gms:play-services-gcm:16.0.0'
}

It works now. Thanks for your help @NickIliev

The problem was solved thanks to @NickIliev's post suggestion, add this to the app.gradle file:

dependencies {
  configurations.all {
      exclude group: 'commons-logging', module: 'commons-logging'
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
      def requested = details.requested
      if (requested.group == 'com.google.firebase') {
        details.useVersion '17.+'
      }
      if (requested.group == 'com.google.android.gms') {
        details.useVersion '16.+'
      }
      if (requested.group == 'com.android.support' && requested.name != 'multidex') {
        // com.android.support major version should match buildToolsVersion
        details.useVersion '28.+'
      }           
    }
  }
}

This will prevent the PlayServices from using AndroidX.

Hi,

I had same issue, and now exactly I was able to fix it, may be we have not same cause, I post my solution and hope this will help :

rm -rf platforms hooks nodes_module
npm install tns-core-modules@androidx --save-exact
tns platform add android@androidx
npm i
tns run android

If you have already uploaded your app on google play and you have those config in app/App_Rersources/Android/app.gradleyout must comment ndk.abiFilters if you lunch your app on emulator :

android {  
    defaultConfig {  
        generatedDensities = []
        applicationId = "__"

        //override supported platforms
        ndk {
            abiFilters.clear()
        }
        //ndk.abiFilters 'armeabi-v7a','arm64-v8a','x64' // comment this line 
    }  

    lintOptions {
        . . .
    }
}

I've tried all of the above solutions, apart from updating to NS6, without any luck. Is anyone else in the same situation?

Posting my package.json and gradle files in case it helps in any way

"dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/common": "^7.2.15",
    "@angular/compiler": "^7.2.15",
    "@angular/core": "^7.2.15",
    "@angular/forms": "^7.2.15",
    "@angular/http": "^7.2.15",
    "@angular/platform-browser": "^7.2.15",
    "@angular/platform-browser-dynamic": "^7.2.15",
    "@angular/router": "^7.2.15",
    "moment": "^2.24.0",
    "nativescript-angular": "^7.2.4",
    "nativescript-cardview": "^3.2.0",
    "nativescript-datetimepicker": "^1.2.1",
    "nativescript-iqkeyboardmanager": "^1.5.1",
    "nativescript-local-notifications": "^3.2.2",
    "nativescript-localstorage": "^2.0.0",
    "nativescript-pager": "^9.5.4",
    "nativescript-secure-storage": "^2.5.0",
    "nativescript-theme-core": "^1.0.6",
    "nativescript-ui-autocomplete": "^5.1.0",
    "nativescript-windowed-modal": "^6.0.0",
    "reflect-metadata": "~0.1.13",
    "rxjs": "^6.5.2",
    "tns-core-modules": "~5.4.3",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular/cli": "^7.3.9",
    "@angular/compiler-cli": "^7.2.15",
    "@nativescript/schematics": "^0.6.0",
    "@ngtools/webpack": "^7.3.9",
    "nativescript-dev-typescript": "~0.9.0",
    "nativescript-dev-webpack": "^0.24.1",
    "tns-platform-declarations": "^5.4.3"
  }

app.gradle

// Add your native dependencies here:

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

// If you want to add something to be applied before applying plugins' include.gradle files 
// e.g. project.ext.googlePlayServicesVersion = "15.0.1"
// create a file named before-plugins.gradle in the current directory and place it there

// https://stackoverflow.com/questions/56744824/how-to-remove-error-execution-failed-for-task-appprocessdebugmanifest
dependencies {
    configurations.all {
        exclude group: 'commons-logging', module: 'commons-logging'
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
             def requested = details.requested
             if (requested.group == 'com.google.firebase') {
               details.useVersion '17.+'
             }
             if (requested.group == 'com.google.android.gms') {
                 details.useVersion '16.+'
             }
             if (requested.group == 'com.android.support' && requested.name != 'multidex') {
                 // com.android.support major version should match buildToolsVersion
                 details.useVersion '28.+'
             }           
        }
    }
}
android {  
  defaultConfig {  
    generatedDensities = []
  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }  
} 

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;
}

before-plugins.gradle

// https://github.com/NativeScript/NativeScript/issues/7372

android {
     project.ext { 
          supportVersion = "28.+"
          googlePlayServicesVersion = "16.+"
     }
} 
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NathanaelA picture NathanaelA  路  92Comments

lscown picture lscown  路  58Comments

surdu picture surdu  路  63Comments

valentinstoychev picture valentinstoychev  路  79Comments

morningrat picture morningrat  路  67Comments