已解决:请参阅注释错误是如何修复的。这是一个非常常见的问题,该主题将修复错误。要证明解决方案有效,请参阅我的免费应用中的广告:https://play.google.com/store/apps/details?id=com.colour.colourguessfree
在我开始之前,我知道这是我晚上在stackoverflow上看到类似主题但没有用的常见问题。
我在使用admob并显示广告时遇到了很大麻烦。在我的应用程序加载时,adview是状态中的消息:缺少必需的XML属性“adSize”。我已经尝试了很多方法来尝试解决这个问题,所以我觉得最好的方法是展示我希望有人可以指出我正确的方向。
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.colourguessfree"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:theme="@style/NoActionBar">
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name=".gameover" android:theme="@style/NoActionBar"
android:screenOrientation="portrait">
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/home"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
ads:adSize="BANNER"
ads:adUnitId="************"
ads:loadAdOnCreate="true" >
单位:
属性: 构建路径:
更新:
这是我尝试过Google Play Services Migration的另一种方法。我试过的xml代码是:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
使用oncreate中的java代码:
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
但这会在adview中显示错误,表示在androidmanifest.xml中缺少与android.configchanges的adactivity
更新2
我很丢失不确定它是否正常工作,日志似乎指向它的一半工作主要问题是我根本看不到广告。
LOG:
10-02 23:26:42.088: W/GooglePlayServicesUtil(5260): Google Play services is missing.
10-02 23:26:42.118: I/Ads(5260): Starting ad request.
10-02 23:26:42.158: I/Ads(5260): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
10-02 23:26:42.178: D/WebSettings(5260): mDataPath: /data/data/com.example.colourguessfree
10-02 23:26:42.208: D/WebSettings(5260): mDataPath: /data/data/com.example.colourguessfree
10-02 23:26:42.378: I/Adreno200-EGLSUB(5260): <ConfigWindowMatch:2081>: Format RGBA_8888.
10-02 23:26:42.388: D/memalloc(5260): /dev/pmem: Mapped buffer base:0x5228d000 size:3686400 offset:3072000 fd:82
10-02 23:26:42.588: D/memalloc(5260): /dev/pmem: Mapped buffer base:0x528d9000 size:7405568 offset:6791168 fd:85
10-02 23:26:43.178: W/GooglePlayServicesUtil(5260): Google Play services is missing.
10-02 23:26:43.178: E/GooglePlayServicesUtil(5260): GooglePlayServices not available due to error 1
10-02 23:26:43.208: W/GooglePlayServicesUtil(5260): Google Play services is missing.
10-02 23:26:43.208: E/GooglePlayServicesUtil(5260): GooglePlayServices not available due to error 1
10-02 23:26:43.238: W/dalvikvm(5260): VFY: unable to resolve virtual method 640: Landroid/net/ConnectivityManager;.isActiveNetworkMetered ()Z
10-02 23:26:43.288: D/WebSettings(5260): mDataPath: /data/data/com.example.colourguessfree
10-02 23:26:43.328: V/chromium(5260): external/chromium/net/host_resolver_helper/host_resolver_helper.cc:66: [1002/232643:INFO:host_resolver_helper.cc(66)] DNSPreResolver::Init got hostprovider:0x4cb15230
10-02 23:26:43.328: V/chromium(5260): external/chromium/net/base/host_resolver_impl.cc:1515: [1002/232643:INFO:host_resolver_impl.cc(1515)] HostResolverImpl::SetPreresolver preresolver:0x01aeba08
10-02 23:26:43.328: D/(5260): external/chromium/net/socket/tcp_fin_aggregation_factory.cc: libtcpfinaggr.so successfully loaded
10-02 23:26:43.328: D/(5260): external/chromium/net/socket/tcp_fin_aggregation_factory.cc,: TCP Fin Aggregation initializing method was found in libtcpfinaggr.so
10-02 23:26:43.328: D/TCPFinAggregation(5260): system property net.tcp.fin.aggregation was set
10-02 23:26:43.328: D/TCPFinAggregation(5260): system property net.tcp.fin.aggregation.wait was set, value: 20
10-02 23:26:43.328: D/TCPFinAggregation(5260): system property net.tcp.fin.aggregation.close was set, value: 300
10-02 23:26:43.328: D/TCPFinAggregation(5260): system property net.close.unused.sockets was set, value: 1
10-02 23:26:43.328: D/TCPFinAggregation(5260): Failed to get network status! received ret: -2
10-02 23:26:43.338: V/WebRequest(5260): WebRequest::WebRequest, setPriority = 1
10-02 23:26:43.348: V/chromium(5260): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:52: [1002/232643:INFO:hostres_plugin_bridge.cc(52)] StatHubCreateHostResPlugin initializing...
10-02 23:26:43.348: V/chromium(5260): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:57: [1002/232643:INFO:hostres_plugin_bridge.cc(57)] StatHubCreateHostResPlugin lib loaded
10-02 23:26:43.348: V/chromium(5260): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:63: [1002/232643:INFO:hostres_plugin_bridge.cc(63)] StatHubCreateHostResPlugin plugin connected
10-02 23:26:43.348: V/chromium(5260): external/chromium/net/http/http_cache.cc:1173: [1002/232643:INFO:http_cache.cc(1173)] HttpCache::OnBackendCreated HostStat created
10-02 23:26:43.348: E/chromium(5260): external/chromium/net/disk_cache/stat_hub.cc:190: [1002/232643:ERROR:stat_hub.cc(190)] StatHub::Init - App com.example.colourguessfree isn't supported.
10-02 23:26:43.348: E/chromium(5260): external/chromium/net/disk_cache/stat_hub.cc:190: [1002/232643:ERROR:stat_hub.cc(190)] StatHub::Init - App com.example.colourguessfree isn't supported.
10-02 23:26:43.498: W/Ads(5260): AdWebView unable to handle URL: http://192.168.1.254/mobile-step0.html?org_url=http://googleads.g.doubleclick.net%2fmads%2fstatic%2fmad%2fsdk%2fnative%2fsdk%2dcore%2dv40%2ehtml
10-02 23:26:43.578: E/Ads(5260): JS: Uncaught ReferenceError: AFMA_buildAdURL is not defined (null:1)
10-02 23:26:43.578: E/Web Console(5260): Uncaught ReferenceError: AFMA_buildAdURL is not defined at null:1
谷歌文档太烦人了,所以经常提到他们不再支持的旧方法....
答案 0 :(得分:2)
尝试改变:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
到
xmlns:ads="http://schemas.android.com/apk/res-auto"
查看Google的本教程:Google Play Services Migration
答案 1 :(得分:0)
我目前有很多传统的admob代码与google play admob 代码。
除了已经提及的xmlns:ads
之外,您还应该更改为xmlns:ads="http://schemas.android.com/apk/res-auto"
:
在清单中更改此内容:
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
为:
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
在adview的xml布局中删除此属性,因为它不再受支持并以编程方式加载广告:
ads:loadAdOnCreate="true"
阅读指南Google Play Services Migration并确保代码中的所有内容与右栏
中描述的相似