我有在其中运行 admob 广告的应用程序。最近我切换到新的 admob SDK (6.3.1) 并设置中介键而不是标准的 admob 键。除了 key 之外,我没有更改代码中的任何内容。现在我通过开发者控制台收到了这个错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp/com.mycompany.myapp.WebBrowser}: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.ads.AdView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.ads.AdView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.mycompany.myapp.AdHandler.loadAdmobAd(AdHandler.java:61)
at com.mycompany.myapp.AdHandler.loadAd(AdHandler.java:28)
at com.mycompany.myapp.WebBrowser.onCreate(WebBrowser.java:173)
at android.app.Activity.performCreate(Activity.java:5163)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
... 22 more
Caused by: java.lang.IllegalArgumentException: Optimized data directory /storage/sdcard0/Android/data/com.mycompany.myapp/cache is not owned by the current user. Shared storage cannot protect your application from code injection attacks.
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.loadDex(DexFile.java:149)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:261)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:229)
at dalvik.system.DexPathList.<init>(DexPathList.java:96)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:52)
at dalvik.system.DexClassLoader.<init>(DexClassLoader.java:57)
at com.google.ads.ak.f(SourceFile:354)
at com.google.ads.ak.b(SourceFile:95)
at com.google.ads.ak.a(SourceFile:69)
at com.google.ads.n.<init>(SourceFile:158)
at com.google.ads.internal.d.<init>(SourceFile:267)
at com.google.ads.AdView.a(SourceFile:508)
at com.google.ads.AdView.a(SourceFile:370)
at com.google.ads.AdView.<init>(SourceFile:125)
... 25 more
用户给我留言:再次打开时崩溃
这是 AdHandler 类:
public class AdHandler {
private Activity act;
private AppClass appState;
public AdHandler(Activity _act,AppClass _appState){
act=_act;
appState=_appState;
}
public void loadAd() {
loadAdmobAd();
}
public void loadAdmobAd_() {
//no ads!
return;
}
public void loadAdmobAd() {
AdView adView=(AdView) act.findViewById(R.id.vw_adview_admob);
if(adView==null) {
LinearLayout adBlock=(LinearLayout)act.findViewById(R.id.ad_block);
LayoutInflater vi = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.vw_admobcontainer, adBlock);
adView = (AdView) v.findViewById(R.id.vw_adview_admob);
}
act.findViewById(R.id.vw_admobcontainer).setVisibility(View.VISIBLE);
act.findViewById(R.id.ad_block).setVisibility(View.VISIBLE);
AdRequest ar = new AdRequest();
ar.addTestDevice(AdRequest.TEST_EMULATOR);
adView.loadAd(ar);
adView.setAdListener(new AdListener() {
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
act.findViewById(R.id.ad_block).setVisibility(View.GONE);
if(WebBrowser.class.isInstance(act)){
appState.browserAddLoaded=false;
((WebBrowser)act).setAllWebBrowserButtons();
}
}
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
public void onReceiveAd(Ad arg0) {
if(WebBrowser.class.isInstance(act)){
appState.browserAddLoaded=true;
act.findViewById(R.id.ad_block).setVisibility(View.VISIBLE);
act.findViewById(R.id.ad_block).invalidate();
((WebBrowser)act).setWebBrowserButtons();
}
}
});
}
}
这是 admob xml (vw_admobcontainer):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/vw_admobcontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Admob - MEDIATION -->
<com.google.ads.AdView
android:id="@+id/vw_adview_admob"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|bottom"
ads:adSize="BANNER"
ads:adUnitId="8xxxxxxxxxxx1" />
</LinearLayout>
这是 admob 容器 xml (ad_block):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/ad_block"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal|center"
android:orientation="vertical"
android:padding="0dp"
android:visibility="gone"
android:background="#FFFFFFFF">
</LinearLayout>
这是包含 ad_block 布局的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/sky" >
<FrameLayout android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<WebView android:id="@+id/web_browser"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFFFF"
/>
<ProgressBar android:id="@+id/web_browser_bussy"
android:layout_width="50dp"
android:layout_height="50dp"
style="@style/android:Widget.ProgressBar.Inverse"
android:layout_gravity="center"
/>
</FrameLayout>
<include layout="@layout/ad_block" />
<ProgressBar android:id="@+id/web_browser_progress_bar"
android:layout_width="fill_parent"
android:layout_height="5dp"
style="@style/android:Widget.ProgressBar.Horizontal"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:progressDrawable="@drawable/progress_bar"
/>
<include layout="@layout/web_browser_footer" android:id="@+id/browser_footer" />
</LinearLayout>
Admob SDK 位于 lib 文件夹内,广告工作正常。我从未成功在我的设备上创建此错误。
谁能告诉我是什么问题?