joshcomley
joshcomley

Reputation: 28818

AndroidX suddenly causing build failure for NativeScript

All of a sudden, with no changes to my dependencies, I am now getting the following error:

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:18:2-31:16 to override.

I have tried applying the suggestion (along with the relevant namespace XML attribute), but unfortunately this yields a message along the lines of multiple errors, see logs, but I don't know where the logs are.

I've read and read into this, and I understand it's a problem with attempting to have AndroidX and the now deprecated support libraries at the same time. However, I have not changed any of my dependencies before this suddenly stopped building - only cleared my platforms to force a full rebuild.

I do not know which plugins are conflicting, and I also understand that Jetifier should remedy this, except NativeScript seems to not give me the ability to modify gradle.properties in any persistent way (that I am aware of), and currently the latest version of NativeScript (which is confusing because NativeScript is 5.4.1, TNS core modules is 5.4.2 and the platform added in my package.json seems to be 5.4.0) seems to not utilise Jetifier and the latest AndroidX build on NPM seems to be a bit out of date.

So, how can I get my app back up and running now? Help!

Upvotes: 4

Views: 1151

Answers (5)

Nicol&#225;s Pulido M
Nicol&#225;s Pulido M

Reputation: 83

Got same error, check libraries version, for me, Firebase was the problem.

before-plugins.gradle

project.ext {
    googlePlayServicesVersion = "15.0.1"
    googleFirebaseServicesVersion = "18.0.0"
}

dependencies {

    def googlePlayServicesVersion = project.googlePlayServicesVersion
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
    compile "com.google.firebase:firebase-messaging:$googleFirebaseServicesVersion"
}

Upvotes: 0

18 Clans
18 Clans

Reputation: 21

I only updated GooglePlayservices to 15.0.0 and added this to the AndroidManifest inside <application>.

 <application>
     ...
              <uses-library android:name="org.apache.http.legacy" 
               android:required="false"/>
     ...            

    <application/>

Upvotes: 0

Javobal
Javobal

Reputation: 141

I fixed this by taking a look to ./gradlew app:dependencies and i fixed any package that appeared to be using an updated dependency that uses androidx to a previous version.

enter image description here

So you can see here that tagmanager was resolving as 17 because the dependency uses '+', so instead i fixed this one to 16.0.8

implementation (project(':react-native-device-info')) {
    exclude group: 'com.google.android.gms', module: 'play-services-gcm'
}

implementation (project(':react-native-google-analytics-bridge')){
    exclude group: 'com.google.android.gms', module: 'play-services-analytics'
    exclude group: 'com.google.android.gms', module: 'play-services-tagmanager-v4-impl'
}
implementation (project(':react-native-admob')) {
    exclude group: 'com.google.android.gms', module: 'play-services-ads'
}

implementation ('com.google.android.gms:play-services-gcm:16.1.0') {
    force = true
}

implementation ('com.google.android.gms:play-services-ads:17.2.0') {
    force = true
}

implementation ('com.google.android.gms:play-services-analytics:16.0.8') {
    force = true
}

implementation ('com.google.android.gms:play-services-tagmanager-v4-impl:16.0.8') {
    force = true
}

Upvotes: 0

Forcing the following dependencies did it for me.

dependencies {

    compile 'com.google.android.gms:play-services-analytics:16.0.4'

    implementation('com.google.android.gms:play-services-analytics:16.0.6'){

    force = true

  }

  implementation('com.google.android.gms:play-services-base:16.1.0'){

    force = true

  }
}

Upvotes: 0

joshcomley
joshcomley

Reputation: 28818

So I fixed this by moving my support dependencies into before-plugins.gradle, which now looks like this:

project.ext {
  googlePlayServicesVersion = "15.0.0"
}

dependencies {
  compile 'com.squareup.picasso:picasso:2.71828'
  def googlePlayServicesVersion = project.googlePlayServicesVersion
  compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
  compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
  def supportVer = "28.0.0"
  compile "com.android.support:support-v4:$supportVer"
  compile "com.android.support:appcompat-v7:$supportVer"
  compile "com.android.support:design:$supportVer"
}

And for good measure, here's my app.gradle:

android {
  defaultConfig {
    // Fix for: The number of method references in a .dex file cannot exceed 64K.
    // (see: https://developer.android.com/tools/building/multidex.html)
    multiDexEnabled true
    minSdkVersion 17
    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;
}

Upvotes: 5

Related Questions