0

I added an npm library to my project and since then, the android version no longer works. The iOS version works fine. The library I added was https://www.npmjs.com/package/react-native-connectivity-status

When I try to run react-native run-android I get error message "> Android dependency 'com.google.android.gms:play-services-basement' has different version for the compile (11.8.0) and runtime (15.0.1) classpath. You should manually set the same version via DependencyResolution" .

In the app build.gradle I added:

implementation project(':react-native-connectivity-status') // to check if BT is turned on

This post indicates that all I need to do is add

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
            && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.0.2"
            }
        }
    }
}

to the root level build.gradle. Which I've done. I've also switched all of the compile statements to implementation.

So now my root level build.gradle now looks like:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {

        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        // Add jitpack repository (added by react-native-spinkit)
        maven { url "https://jitpack.io" }
        mavenLocal()

        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        jcenter()
    }
    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex') ) {
                    details.useVersion "26.0.2"
                }
            }
        }
    }
}

Here is a list of the dependencies in my build.gradle

dependencies {
    implementation project(':react-native-i18n')
    implementation project(':react-native-svg')
    implementation project(':react-native-extra-dimensions-android')
    implementation project(':react-native-google-analytics-bridge')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-spinkit')
    implementation project(':react-native-fbsdk')
    implementation project(':react-native-picker')
    implementation 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.facebook.react:react-native:+'
    // From node_modules
    implementation 'com.facebook.fresco:fresco:1.3.0'
    implementation 'com.facebook.fresco:animated-gif:1.3.0'
    implementation project(':blelibrary')
    implementation project(':gaialibrary')
    implementation project(':vmupgradelibrary')
    implementation 'com.google.code.gson:gson:2.8.4'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation project(':react-native-connectivity-status') // to check if BT is turned on
}

and some additional info

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.someapp"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 28
        versionName "1.2.4"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        packagingOptions {
            exclude "lib/arm64-v8a/libgnustl_shared.so"
        }
        externalNativeBuild {
            cmake {
                arguments '-DANDROID_STL=c++_static'
            }
        }
    }

I'm extremely confused by the error message because I don't see com.google.android.gms:play-services-basement anywhere in the build.gradle.

I've looked at numerous answers before posting this question: here, here and here

I realized that I didn't add multiDexEnabled true in the default Config. After adding it, running ./gradlew clean and then react-native run-android, I get a new error: > Android dependency 'com.google.android.gms:play-services-tasks-license:11.8.0' is set to compileOnly/provided which is not supported

VK1
  • 1,676
  • 4
  • 28
  • 51

1 Answers1

-1

I was able to build it (with new and improved errors) by adding the following dependencies in the build.gradle at the app level:

implementation("com.google.android.gms:play-services-basement:15.0.1")
implementation("com.google.android.gms:play-services-base:15.0.1") 
Gurunath Sripad
  • 1,308
  • 2
  • 14
  • 24
VK1
  • 1,676
  • 4
  • 28
  • 51