您可以摆脱 jar 文件并使用 google play 服务来处理广告和地图。进行以下更改:
在您的布局中,将广告 xml 命名空间更改为:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
-----/>
收件人:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
----/>
然后,改变:
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginTop="300dp"
ads:adSize="BANNER"
ads:adUnitId="***************"
ads:loadAdOnCreate="true" />
收件人:
<com.google.android.gms.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginTop="300dp"
ads:adSize="BANNER"
ads:adUnitId="***************" />
请注意 ads:loadAdOnCreate 不再可用,因此您必须通过 onCreate() 中的 java 代码加载广告:
AdView adView = (AdView)this.findViewById(R.id.ad);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
然后在你的清单的应用标签中,更改:
<activity android:name="com.google.ads.AdActivity"/>
到:
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
添加:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
不要忘记权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>