0

我需要使用 firebase 设置我的 react-native 应用程序,然后按照 firebase 设置指南进行操作,然后重新运行该应用程序,但它失败并出现错误,我尝试了许多互联网上可用的解决方案,但我的问题仍然没有解决.

如果有人以前遇到过这个问题并已经解决了,请你帮我解决这个问题。

这是错误:

* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.google.android.gms:play-services-measurement:12.0.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
       - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
       - file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
       - file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
       - https://jcenter.bintray.com/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
       - https://jcenter.bintray.com/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
       - https://jitpack.io/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.pom
       - https://jitpack.io/com/google/android/gms/play-services-measurement/12.0.1/play-services-measurement-12.0.1.aar
     Required by:
         project :app > com.google.firebase:firebase-analytics:17.2.0
   > Could not find com.google.android.gms:play-services-measurement-api:12.0.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
       - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
       - file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
       - file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
       - https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
       - https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
       - https://jitpack.io/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.pom
       - https://jitpack.io/com/google/android/gms/play-services-measurement-api/12.0.1/play-services-measurement-api-12.0.1.aar
     Required by:
         project :app > com.google.firebase:firebase-analytics:17.2.0
   > Could not find com.google.android.gms:play-services-measurement-sdk:12.0.1.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
       - https://dl.google.com/dl/android/maven2/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
       - file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
       - file:/home/iswan/.m2/repository/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/react-native/android/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
       - file:/home/iswan/works/office/xforce/xForceMobile/node_modules/jsc-android/dist/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
       - https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
       - https://jcenter.bintray.com/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
       - https://jitpack.io/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.pom
       - https://jitpack.io/com/google/android/gms/play-services-measurement-sdk/12.0.1/play-services-measurement-sdk-12.0.1.aar
     Required by:
         project :app > com.google.firebase:firebase-analytics:17.2.0

构建.gradle

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

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        googlePlayServicesVersion = "+"
    }
    repositories {
        google()
        maven { url "https://maven.google.com" } 
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.2")
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        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")
        }


        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        jcenter()
        maven { url 'https://jitpack.io' }
    }

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

2 回答 2

1

@AjithMadhu 我发现了这个问题,因为下面的部分。我在一个月前硬编码,我没有注意到那个。

subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.google.android.gms'
                && !details.requested.name.contains('multidex') ) {
                    details.useVersion "12.0.1"
                }
            }
        }
    }
于 2019-12-26T12:51:01.360 回答
0

好吧,这就是我所做的。请参考这个,

安卓/build.gradle

dependencies {
    classpath("com.android.tools.build:gradle:3.4.2")
    + classpath 'com.google.gms:google-services:4.3.3' // check this line

}   

android/app/build.gradle

dependencies {
+ implementation "com.google.android.gms:play-services-base:17.1.0"
+ implementation 'com.google.firebase:firebase-core:17.2.1'
+ implementation 'com.google.firebase:firebase-messaging:20.0.1'
}

android/grade.properties

firebaseCoreVersion=17.2.1
firebaseMessagingVersion=20.0.1

MainApplication.java

+ import io.invertase.firebase.messaging.RNFirebaseMessagingPackage;
+ import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;

 @Override
protected List<ReactPackage> getPackages() {
  @SuppressWarnings("UnnecessaryLocalVariable")
  List<ReactPackage> packages = new PackageList(this).getPackages();
  packages.add(new RNFirebaseMessagingPackage());
  packages.add(new RNFirebaseNotificationsPackage());      
  return packages;
}
于 2019-12-26T12:51:35.363 回答