com.google.android.gms:play-services-base编译和React Native发生运行时冲突

时间:2019-07-16 19:08:03

标签: android firebase react-native google-play-services

我的本​​机项目有问题。当我尝试构建项目(在Android,Windows 10,Android仿真器中)时,遇到编译时版本与Play-Service-Base的运行时版本之间发生冲突的错误。

我正在使用:

"react": "16.3.1"
"react-native": "0.55.3"
"react-native-firebase": "^4.3.8"

android / build.gradle

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

buildscript {
    repositories {
        maven {
               url 'https://maven.fabric.io/public'
            }
        maven {
            url 'https://google.bintray.com/exoplayer/'
        }
        google()
        mavenLocal()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'io.fabric.tools:gradle:1.25.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://google.bintray.com/exoplayer/'
        }
        maven {
            url 'https://maven.google.com'
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        jcenter()
        configurations.all {
                        resolutionStrategy.force 'com.google.android.gms:play-services-base:17.0.0'
                    }
    }
}

subprojects {

project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.google.android.gms'
                    && (details.requested.name.contains('play-services-core')
                    || details.requested.name.contains('play-services-tasks')
                    || details.requested.name.contains('play-services-basement')
                    || details.requested.name.contains('play-services-stats'))) {
                details.useVersion "17.0.0"
            }
        }
        afterEvaluate {project ->
    if (project.name.contains('react-native-fetch-blob') ||
            project.name.contains('react-native-image-picker') ||
            project.name.contains('react-native-vector-icons')) {
        buildscript {
            repositories {
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }
        }
    }
}
}
}

android / app / build.gradle

    apply plugin: "com.android.application"
apply plugin: 'io.fabric'

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 = true
def Properties localproperties = new Properties()
localproperties.load(project.rootProject.file("local.properties").newDataInputStream())

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "ir.brogrammers.tamin"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 32
        versionName "1.0.8"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        multiDexEnabled true
    }
    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
            }
        }
    }
    /* signingConfigs {
        release {
                if (localproperties.getProperty('MYAPP_RELEASE_STORE_FILE', null)) {
                storeFile file(localproperties['MYAPP_RELEASE_STORE_FILE'])
                storePassword localproperties['MYAPP_RELEASE_STORE_PASSWORD']
                keyAlias localproperties['MYAPP_RELEASE_KEY_ALIAS']
                keyPassword localproperties['MYAPP_RELEASE_KEY_PASSWORD']
            }
        }
    } */
    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"
            signingConfig signingConfigs.release
            ext.enableCrashlytics = true
        }
    }
    // 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-firebase')

    // Firebase dependencies
    implementation "com.google.android.gms:play-services-base:17.0.0"
    implementation "com.google.firebase:firebase-core:17.0.0"
    implementation "com.google.firebase:firebase-messaging:19.0.0"
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.0"
    implementation("com.facebook.react:react-native:0.55.3") { force = true }
    implementation project(':react-native-document-picker')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-fs')
    implementation project(':react-native-device-info')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-video')
    implementation project(':react-native-file-viewer')
    implementation project(':react-native-splash-screen')
    implementation 'com.facebook.fresco:animated-base-support:1.3.0'
    implementation 'com.facebook.fresco:animated-gif:1.3.0'
    implementation 'com.facebook.fresco:fresco:1.3.0'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.+'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1'
    implementation project(':react-native-fetch-blob')
    implementation project(':react-native-account-manager')
    compile project(':react-native-shortcut-badge')
    compile project(':react-native-wheel-picker-android')
    implementation 'com.android.support:multidex:1.0.3'
    implementation project(':react-native-i18n')

//    configurations.all {
//        resolutionStrategy {
//            force 'com.google.android.gms:play-services-gcm:17.0.0'
//            force 'com.google.android.gms:play-services-base:17.0.0'
//            force 'com.google.firebase:firebase-core:17.0.0'
//            force 'com.google.firebase:firebase-messaging:19.0.0'
//        }
//    }
}

// 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'
}

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

当我想使用 react-native run-android 构建项目时,会因该错误而失败

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.google.android.gms:play-services-base' has different version for the compile (16.0.1) and runtime (17.0.0) classpath. You should manually set the same version via DependencyResolution

我尝试将基于play-services的版本更改为17.0.0,并强制其使用版本17.0.0

    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.google.android.gms'
                && (details.requested.name.contains('play-services-core')
                || details.requested.name.contains('play-services-tasks')
                || details.requested.name.contains('play-services-basement')
                || details.requested.name.contains('play-services-stats'))) {
            details.useVersion "17.0.0"
        }
    }

1 个答案:

答案 0 :(得分:1)

github的评论为您的问题提供了答案

一个依赖项(在这种情况下为react-native-device-info)正在使用其依赖项之一的最新版本,而不是固定/固定版本。谷歌服务的新版本昨天发布时,它导致该构建为设备信息引入了新版本,从而与正确固定所需版本的其他依赖项产生冲突。

implementation(project(":react-native-device-info"),  {
  exclude group: "com.google.android.gms"
})

实现“ com.google.android.gms:play-services-gcm:16.0.0” 并可能用可能具有相同问题的任何其他依赖项替换react-native-device-info(它们将包括诸如实现“ com.google.android.gms:play-services-gcm:+”之类的行,具体取决于最新版的Google gcm)。