将“com.google.gms.google-services”插件与 android 应用程序集成时出现问题

Posted

技术标签:

【中文标题】将“com.google.gms.google-services”插件与 android 应用程序集成时出现问题【英文标题】:Problem in integrating 'com.google.gms.google-services' plugin with android app 【发布时间】:2020-11-13 06:54:17 【问题描述】:

当我尝试将 apply plugin: 'com.google.gms.google-services' 放在我的构建 gradle 的底部或我的应用程序构建 gradle 中的任何其他位置时,我收到以下错误:

In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[19.0.
2]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.android.gms:play-services-vision-image-label:18.0.3 -> com.google.android.gms:play-servic
es-vision-common@[19.0.2], but play-services-vision-common version was 19.1.0.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art
ifact with the issue.
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision-object-detection-model@strictly 19.0.5
-- Project 'app' depends onto com.google.android.gms:play-services-vision-common@strictly 19.1.0
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision@strictly 24.0.3
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision-internal-vkp@strictly 17.0.1
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision-object-detection-model@19.0.5
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision@24.0.3
-- Project 'app' depends onto com.google.android.gms:play-services-vision-image-label@strictly 18.0.3
-- Project 'app' depends onto com.google.android.gms:play-services-mlkit-face-detection@16.1.0
-- Project 'app' depends onto com.google.android.gms:play-services-vision@strictly 20.1.0
-- Project 'app' depends onto com.google.android.gms:play-services-mlkit-face-detection@strictly 16.1.0

For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep
endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding "googleServices  disableVersionCheck = false " to your b
uild.gradle file.

我在应用级别的 build.gradle 是:

apply plugin: 'com.android.application'
android 
    compileSdkVersion 30
    buildToolsVersion "29.0.3"

    defaultConfig 
        applicationId "com.example.mlkitfacedetection"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    



dependencies 
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.1.0'
    implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
    implementation 'com.google.firebase:firebase-ml-vision-object-detection-model:19.0.5'
    def camerax_version = "1.0.0-beta03"
// CameraX core library using camera2 implementation
    implementation "androidx.camera:camera-camera2:$camerax_version"
// CameraX Lifecycle Library
    implementation "androidx.camera:camera-lifecycle:$camerax_version"
// CameraX View class
    implementation "androidx.camera:camera-view:1.0.0-alpha10"

apply plugin: 'com.google.gms.google-services'

我无法解决该错误。另一个应用程序中的相同代码运行良好。 我正在使用在 firebase 上注册的另一个应用程序中的 google-services.json 文件。这不是问题的原因吗?

【问题讨论】:

implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.0.0' 的同样问题? 不,上述实现工作正常。仅当我添加此插件“com.google.gms.google-services”时,代码才会出错。我正在使用另一个应用程序中的 google-services.json 文件。这不是问题的原因吗? Only when i am adding this plugin 'com.google.gms.google-services', the code is giving error. I am using google-serivices.json file from another app. Isn't it the cause of problem? 【参考方案1】:

我测试了这个解决方法,这似乎有效。在 dependencies 块中添加以下内容:

implementation 'com.google.android.gms:play-services-vision-image-label:18.0.4'

【讨论】:

是的,但是为什么呢?我不想给项目添加随机依赖,不知道它在做什么。【参考方案2】:
implementation 'com.google.android.gms:play-services-vision:20.1.1'
implementation 'com.google.android.gms:play-services-vision-common:19.1.1'
implementation "com.google.android.gms:play-services-vision-face-contour-internal:16.0.2"
implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
implementation 'com.google.firebase:firebase-ml-vision-face-model:20.0.2'
implementation 'com.google.firebase:firebase-ml-model-interpreter:22.0.4'
implementation 'org.tensorflow:tensorflow-lite:2.0.0'

点击此链接了解更多详情 - https://github.com/firebase/firebase-android-sdk/issues/1904

【讨论】:

【参考方案3】:

您可能只需要更新您的依赖项:文件-->项目结构-->依赖项然后在下半部分,您将看到任何需要更新的依赖项...为我工作 p>

【讨论】:

以上是关于将“com.google.gms.google-services”插件与 android 应用程序集成时出现问题的主要内容,如果未能解决你的问题,请参考以下文章

如何将Ios文件上传到

Javascript 将正则表达式 \\n 替换为 \n,将 \\t 替换为 \t,将 \\r 替换为 \r 等等

如何将视频文件转换格式

sh 一个将生成CA的脚本,将CA导入到钥匙串中,然后它将创建一个证书并与CA签名,然后将其导入到

python怎么将0写入文件?

如何将CMD窗口背景改成透明?