android - Gradle Firebase AdMob 依赖项与 app compat v7 28.0.0 冲突

标签 android firebase gradle admob

当我添加 AdMob 依赖项时,会出现这条红线:

First error

完整的错误信息:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:customtabs:26.1.0 less... (Ctrl+F1) Inspection info:There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion). Issue id: GradleCompatible



如果我尝试让项目出现此错误消息:

Second error

我已经使缓存/重启无效,重新导入 gradle 并且没有任何效果......

Gradle 模块
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.dev.marcellocamara.pgm"
        minSdkVersion 19
        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:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:customtabs: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.8'
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.google.firebase:firebase-database:16.1.0'
    implementation 'com.google.firebase:firebase-storage:16.1.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'
    implementation 'com.google.firebase:firebase-ads:17.2.0'
}

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

Gradle 应用
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我查看了同样问题的另一个答案,但没有一个像我一样使用太多的 firebase 库。他们告诉添加支持 v7 28.0.0,我已经做到了。

最佳答案

通过关注此文档:https://developer.android.com/studio/build/multidex

我添加了 multiDexEnabled true到构建 gradle 模块:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.dev.marcellocamara.pgm"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

根据文档,为什么我使用 min SDK 作为 19,我添加了 'com.android.support:multidex:1.0.3'作为构建 gradle 模块的依赖,最后添加了 android:name="android.support.multidex.MultiDexApplication"到应用程序 manifest.xml

错误消息消失并且应用程序正在运行...

关于android - Gradle Firebase AdMob 依赖项与 app compat v7 28.0.0 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55642863/

相关文章:

android - Android 单元测试中的模拟改造 Observable<T> 响应

Firebase 机器学习套件

android - 错误 : Could not find org. jetbrains.kotlin :kotlin-stdlib-jdk8:1. 3.31

android - 多个support-v4 jar导致问题

spring-boot - Gradle5.2 中的 Gradle kotlin Unresolved reference : dependtest

java - 无法将空值放入 JSON 对象

android - 如何通过输入法服务将 KeyEvents 发送到 Dialog 或 Spinner 菜单?

java - 用户注销并再次登录后,Firebase facebook 登录错误将您记录到应用程序中

ios - 执行 segue 让用户与帖子创建者聊天

android - 捏缩放后获得正确的坐标(画线)Android Canvas