首页 > 解决方案 > android gradle 错误:库必须使用完全相同的版本规范。找到版本 28.0.0

问题描述

这是应用程序级别的依赖项。我一直在尝试将 firebase 添加到我的应用程序中。但它显示错误

apply plugin: 'com.android.application'  

    android {  
        compileSdkVersion 28  
        defaultConfig {  
            applicationId "com.example.rachitshah.fireapp"  
            minSdkVersion 15  
            targetSdkVersion 28  
            versionCode 1  
            versionName "1.0"  
            testInstrumentationRunner   "android.support.test.runner.AndroidJUnitRunner"  
        }
        buildTypes {
            release {
                minifyEnabled false  
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])  

这一行的错误

 implementation 'com.android.support:appcompat-v7:28.0.0'  
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'  
        testImplementation 'junit:junit:4.12'  
        androidTestImplementation 'com.android.support.test:runner:1.0.2'  
        androidTestImplementation   'com.android.support.test.espresso:espresso-core:3.0.2'  

这是firebase依赖。

implementation 'com.google.firebase:firebase-core:16.0.1'  

标签: androidfirebasegradle

解决方案


当您通过添加在 gradle 文件中添加 firebase 依赖项时

implementation 'com.google.firebase:firebase-core:16.0.1'

然后在您的应用中也添加了 2 个库

com.android.support:support-media-compat:26.1.0
com.android.support:support-v4:26.1.0

他们的版本与 versin 28.0.0 不同,这是错误发生的原因。

要修复此错误,请更改您的 gradle 文件

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'

    // Add this line
    implementation 'com.android.support:support-v4:28.0.0'

    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
}

推荐阅读