2

I'm getting following error while building application

Android dependency 'com.google.android.gms:play-services-base' has different version for the compile (15.0.1) and runtime (16.0.1) classpath. You should manually set the same version via DependencyResolution

APP/build.gradle file

    apply plugin: "com.android.application"

import com.android.build.OutputFile


project.ext.react = [
        entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.afbmobilebanking"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 14
        versionName "1.0.9"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            debuggable false
            // minifyEnabled true
            // shrinkResources true
            signingConfig signingConfigs.release
            //  minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    lintOptions {
        abortOnError false
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
//    buildTypes {
//        release {
//            minifyEnabled enableProguardInReleaseBuilds
//            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
//        }
//    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a": 1, "x86": 2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    implementation project(':react-native-maps')
    implementation project(':react-native-i18n')
    implementation project(':react-native-device-info')
    implementation project(':react-native-maps')
    implementation project(':react-native-device-info')
    implementation project(':react-native-i18n')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:23.0.1"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.facebook.fresco:animated-gif:1.3.0'
//    implementation(project(':react-native-maps')) {
//        exclude group: 'com.google.android.gms', module: 'play-services-base'
//        exclude group: 'com.google.android.gms', module: 'play-services-maps'
//    }
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

Please let me know how to resolve this .

Kartiikeya
  • 2,358
  • 7
  • 33
  • 68

3 Answers3

1

Some of your libs might have dependencies on the play services. You can see the dependency tree using:

$ ./gradlew app:dependencies

And then you can exclude the conflicting dependency from the lib or try to upgrade all your libs to the latest, or try to simply ignore the problem (which is not recommended) using

com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
Vladimir Gladun
  • 416
  • 2
  • 16
  • Can you be specific where i have to include that line of disableversioncheck – Kartiikeya Oct 11 '18 at 07:54
  • Just add it to the and of your APP/build.gradle file. But it won't necessary help. Have you tried to update your play services version to the latest one? – Vladimir Gladun Oct 11 '18 at 07:59
  • I am not sure if this is the best solution ... for my case was enough to clean project and build it again ... and i think better solution is force lates library for all dep like this ```implementation("com.google.android.gms:play-services-base:${YOUR_VERSION}") { force = true }``` – Lukáš Šálek Feb 21 '19 at 11:18
1

Remove duplicate declaration of implementation project(':react-native-maps') and If it's conflict from react-native-maps library then replace below code with implementation project(':react-native-maps').

implementation(project(':react-native-maps')) {
       exclude group: 'com.google.android.gms', module: 'play-services-base'
} 
Hardy Android
  • 855
  • 9
  • 20
0
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.facebook.react:react-native:0.20.1"  // From node_modules
implementation "com.google.android.gms:play-services-base:16.1.0"

add implementation "com.google.android.gms:play-services-base:16.1.0" in build.Gradle/app ,its working for me.