【问题标题】:I am facing a strange problem on integrating Admob into my Android Studio Project我在将 Admob 集成到我的 Android Studio 项目时遇到了一个奇怪的问题
【发布时间】:2019-05-21 14:17:47
【问题描述】:

所以我正在尝试将 admob 实现到我的 android 项目中。为此,我正在关注 Google 的官方指南 (https://developers.google.com/admob/android/quick-start#import_the_mobile_ads_sdk) 但我在将这一行添加到我的 build.gradle(Module app) 时出错,

实施 'com.google.android.gms:play-services-ads:17.1.1'

问题描述:

所有 com.android.support 库必须使用完全相同的版本 规范(混合版本可能导致运行时崩溃)。成立 版本 28.0.0、26.1.0。例子包括 com.android.support:animated-vector-drawable:28.0.0 和 com.android.support:customtabs:26.1.0 少... (Ctrl+F1) 有 一些库或工具和库的组合,它们是 不兼容,或者可能导致错误。一种这样的不兼容性是 使用不支持的 Android 支持库版本进行编译 最新版本(或者特别是低于您的 targetSdkVersion)。问题 ID:GradleCompatible

我的目标 SDK 是 API 14

我的 build.gradle(Module:app) https://justpaste.it/684d6

【问题讨论】:

  • 在这里也添加完整的 gradle 文件
  • 为什么你的目标sdk是api 14?
  • 混合版本错误可以通过在您的模块级 gradle 文件中添加所有冲突的依赖项来解决,所有版本都相同
  • 如果您在应用程序中还有其他一些模块,请同时检查它们的版本,它们可能彼此不同
  • @RakshitNawani 这是我的 build.gradle(Nodule:app) :justpaste.it/684d6

标签: android android-studio gradle admob build.gradle


【解决方案1】:

用这个替换。

    apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.bitpix.tales"
minSdkVersion 14
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'
    compile 'com.android.support:customtabs:28.0.0'
    compile 'com.android.support:support-v4:28.0.0'
    compile 'com.android.support:support-media-compat:28.0.0'
    compile 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:design:28.0.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.gms:play-services-ads:17.1.2'

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

【讨论】:

    【解决方案2】:

    只需复制并粘贴 gradle 中显示的错误版本。对于这种情况,它是'com.android.support:customtabs:26.1.0 '

    在你的 gradle 文件中实现这一行,它将解决问题。

    //add this line
    implementation 'com.android.support:customtabs:26.1.0'
    //change the version to your appcompat support version it will solve the problem
    implementation 'com.android.support:customtabs:28.0.0'
    

    编译 gradle 一次。此错误将得到解决。

    【讨论】:

      【解决方案3】:

      支持库Bundle中有多个依赖,这个库版本不一样,但是你可以在没有解决这个错误的情况下运行。你的应用程序运行良好。

      【讨论】:

      • 不,应用程序在启动时崩溃
      • 但我已将此添加到清单文件中:
      • 尝试替换这个实现 'com.google.android.gms:play-services-ads:16.0.0'
      • 现在它没有崩溃但我仍然无法显示广告,我的 xml 无法识别“广告”关键字:imgur.com/a/AnKvuPT
      猜你喜欢
      • 2019-05-05
      • 1970-01-01
      • 2012-04-09
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 2022-06-11
      相关资源
      最近更新 更多