【问题标题】:React Native Android is suddenly unable to find google servicesReact Native Android 突然找不到谷歌服务
【发布时间】:2016-09-16 13:16:14
【问题描述】:

昨天我很高兴在 iOS 和 Android 上编译我的应用程序。当我回来时,Android 上没有任何工作了。

google-services 插件无法检测到 com.google.android.gms 或 com.google.firebase 的任何版本,将使用默认版本:9.0.0。 请在构建文件的底部应用 google-services 插件。

该消息非常简单明了,在将依赖项安装到应用程序中时,我已经不得不处理好几次了。我总是设法解决这个问题。但是这次它显示出来的原因绝对没有明显的原因,因为我没有触摸我的 android sdk。

此外,我的 gradle 配置文件也没有被触及。在下面你会看到我在文件末尾还有apply google-services plugin 行。

为了以防万一,我尝试回到较旧的提交。但事情还是一样,我现在对这个问题有点不知所措..

这是我的app/gradle 文件:

apply plugin: "com.android.application"

import com.android.build.OutputFile

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.myApp"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias RELEASE_KEY_ALIAS
            keyPassword 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
        }
    }
    // 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
            }
        }
    }
}

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-ads:9.2.1'
        force "com.google.android.gms:play-services:9.2.1"
        force "com.google.android.gms:play-services-location:9.2.1"
        force "com.google.android.gms:play-services-maps:9.2.1"
        force "com.google.android.gms:play-services-gcm:9.2.1"
        force "com.google.android.gms:play-services-analytics:9.2.1"
        force "com.google.firebase:firebase-core:9.2.1"
        force "com.google.firebase:firebase-analytics:9.2.1"
    }
}

dependencies {
    compile project(':react-native-maps')
    compile project(':react-native-linear-gradient')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile project(':react-native-fbsdk')
    compile project(':react-native-firebase-analytics')
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// 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 plugin: 'com.google.gms.google-services'

这是我的 android SDK Manager 的截图

有人知道发生了什么吗?

【问题讨论】:

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


    【解决方案1】:

    我找到了解决问题的方法。实际上,我根本不知道它为什么会起作用。

    但是,通过阅读我的代码,我实际上看到我 force 是 Firebase 的一个版本,但我从未真正编译过它......所以我从 configuration 中删除了 force 并将我的依赖移到了 @987654324 @

    我真的不知道这是否是正确的解决方案 但这解决了我的问题:

    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-ads:9.2.1'
            force "com.google.android.gms:play-services:9.2.1"
            force "com.google.android.gms:play-services-location:9.2.1"
            force "com.google.android.gms:play-services-maps:9.2.1"
            force "com.google.android.gms:play-services-gcm:9.2.1"
            force "com.google.android.gms:play-services-analytics:9.2.1"
        }
    }
    
    dependencies {
        compile project(':react-native-maps')
        compile project(':react-native-linear-gradient')
        compile fileTree(dir: "libs", include: ["*.jar"])
        compile project(':react-native-fbsdk')
        compile project(':react-native-firebase-analytics')
        compile "com.android.support:appcompat-v7:23.0.1"
        compile "com.facebook.react:react-native:+"  // From node_modules
        compile "com.google.firebase:firebase-core:9.2.1"
        compile "com.google.firebase:firebase-analytics:9.2.1"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      相关资源
      最近更新 更多