没有找到类别AdView

huangapple 未分类评论55阅读模式
标题翻译

Didn't find class AdView

问题

build.gradle

  1. ...
  2. dependencies {
  3. api ('com.google.android.gms:play-services-ads:16.0.0'){force = true}
  4. api fileTree(dir: 'libs', include: ['*.jar'])
  5. }

layout.xml

  1. ...
  2. <com.google.android.gms.ads.AdView
  3. android:id="@+id/banner_ad"
  4. android:layout_width="match_parent"
  5. android:layout_height="wrap_content"
  6. android:layout_centerHorizontal="true"
  7. android:layout_alignParentBottom="true"
  8. app:adSize="FULL_BANNER"
  9. app:adUnitId="ca-app-pub-xxx/xxx"/>
  10. ...

Log

  1. 03-16 11:32:47.006 E/AndroidRuntime(2784): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: DexPathList[[zip file ...
英文翻译

I want to add AdMob in my application but the AdView class is not found in my application

build.gradle

  1. ...
  2. dependencies {
  3. api (&#39;com.google.android.gms:play-services-ads:16.0.0&#39;){force = true}
  4. api fileTree(dir: &#39;libs&#39;, include: [&#39;*.jar&#39;])
  5. }

layout.xml

  1. ...
  2. &lt;com.google.android.gms.ads.AdView
  3. android:id=&quot;@+id/banner_ad&quot;
  4. android:layout_width=&quot;match_parent&quot;
  5. android:layout_height=&quot;wrap_content&quot;
  6. android:layout_centerHorizontal=&quot;true&quot;
  7. android:layout_alignParentBottom=&quot;true&quot;
  8. app:adSize=&quot;FULL_BANNER&quot;
  9. app:adUnitId=&quot;ca-app-pub-xxx/xxx&quot;/&gt;
  10. ...

Log

  1. 03-16 11:32:47.006 E/AndroidRuntime(2784): Caused by: java.lang.ClassNotFoundException: Didn&#39;t find class &quot;com.google.android.gms.ads.AdView&quot; on path: DexPathList[[zip file ...

答案1

得分: 0

dependencies {
compile 'com.google.android.gms:play-services-ads:8.4.0'
}

Also see here: https://stackoverflow.com/questions/34963633/

英文翻译
  1. dependencies {
  2. compile &#39;com.google.android.gms:play-services-ads:8.4.0&#39;
  3. }

Also see here: https://stackoverflow.com/questions/34963633/

答案2

得分: 0

在应用的 Gradle 中添加以下内容:

  1. implementation 'com.google.firebase:firebase-ads:18.3.0'

然后,在布局文件中添加以下代码:

  1. <com.google.android.gms.ads.AdView
  2. android:id="@+id/adView"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. ads:adSize="BANNER"
  6. ads:adUnitId="@string/ad_unit_id">
  7. </com.google.android.gms.ads.AdView>
英文翻译

Add below in app Gradle

  1. implementation &#39;com.google.firebase:firebase-ads:18.3.0&#39;

Then,

  1. &lt;com.google.android.gms.ads.AdView
  2. android:id=&quot;@+id/adView&quot;
  3. android:layout_width=&quot;wrap_content&quot;
  4. android:layout_height=&quot;wrap_content&quot;
  5. ads:adSize=&quot;BANNER&quot;
  6. ads:adUnitId=&quot;@string/ad_unit_id&quot;&gt;
  7. &lt;/com.google.android.gms.ads.AdView&gt;

huangapple
  • 本文由 发表于 2020年3月16日 12:43:02
  • 转载请务必保留本文链接:https://java.coder-hub.com/60700433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定