无法导入 com.google.android.gms:play-services-ads:17.1.1

Cannot import com.google.android.gms:play-services-ads:17.1.1(无法导入 com.google.android.gms:play-services-ads:17.1.1)

本文介绍了无法导入 com.google.android.gms:play-services-ads:17.1.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

apply plugin: 'com.android.application'
   android {
   compileSdkVersion 28

   defaultConfig {
      applicationId "com.kaiboon0216gmail.homeownerstarterkit"
      minSdkVersion 21
      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'
   implementation 'com.android.support:cardview-v7:28.0.0'
   implementation 'com.google.android.gms:play-services-ads:17.1.1'
}

这些是我的代码.我正在使用 Admob 在我的应用中显示广告.当我添加此代码时:"'com.google.android.gms:play-services-ads:17.1.1'" 和同步,我的应用程序崩溃了.

These are my codes.I'm using Admob to display the ads in my app.When I add this code:"'com.google.android.gms:play-services-ads:17.1.1'" and sync , my apps crash.

之后我去Admob官网发现这个版本是针对'com.android.support:appcompat-v7:26.1.0'版本的.但是当我将 compileSdkVersion 更改为 26 时,我的应用程序仍然崩溃....

After that I go to Admob official website and found that this version is for 'com.android.support:appcompat-v7:26.1.0' version. But when I change the compileSdkVersion to 26, my apps still crash....

我已经测试了没有这个代码的代码:'com.google.android.gms:play-services-ads:17.1.1'" 并且它可以运行.我确定这个代码是问题,但我不知道如何纠正它.

I have test the code without this code:"'com.google.android.gms:play-services-ads:17.1.1'" and it can run.Im sure that this code is the problem but i have no idea how to correct it.

谁能帮助解决我的问题?谢谢.

Could anyone help to solve my problem? Thank you.

推荐答案

转到 Admob - 选择应用 - 应用设置 - 应用 IDApp ID 复制值

现在添加这个(更改这个 android:value="paste the App ID value you copy from your admob app")

Now add this (change this android:value="paste the App ID value you copy from your admob app" )

<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-111100000000~1111111"/>

meta-dataAndroidManifest.xml 文件

无需在 android:name="com.google.android.gms.ads.APPLICATION_ID"APPLICATION_ID 中添加任何内容

No need to add anything in APPLICATION_ID from android:name="com.google.android.gms.ads.APPLICATION_ID"

这行得通!

看下图就清楚了

这篇关于无法导入 com.google.android.gms:play-services-ads:17.1.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法导入 com.google.android.gms:play-services-ads:17.1.1

基础教程推荐