没有找到类别AdView

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

Didn't find class AdView

问题

build.gradle

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

layout.xml

...

	<com.google.android.gms.ads.AdView
		android:id="@+id/banner_ad"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_centerHorizontal="true"
		android:layout_alignParentBottom="true"
		app:adSize="FULL_BANNER"
		app:adUnitId="ca-app-pub-xxx/xxx"/>

...

Log

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

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

layout.xml

...

	&lt;com.google.android.gms.ads.AdView
		android:id=&quot;@+id/banner_ad&quot;
		android:layout_width=&quot;match_parent&quot;
		android:layout_height=&quot;wrap_content&quot;
		android:layout_centerHorizontal=&quot;true&quot;
		android:layout_alignParentBottom=&quot;true&quot;
		app:adSize=&quot;FULL_BANNER&quot;
		app:adUnitId=&quot;ca-app-pub-xxx/xxx&quot;/&gt;

...

Log

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/

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

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

答案2

得分: 0

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

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

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

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

Add below in app Gradle

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

Then,

            &lt;com.google.android.gms.ads.AdView
                android:id=&quot;@+id/adView&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                ads:adSize=&quot;BANNER&quot;
                ads:adUnitId=&quot;@string/ad_unit_id&quot;&gt;
            &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:

确定