加载失败请确保声明

时间:2015-05-03 08:09:48

标签: java android android-fragments webview admob

我正在尝试在我的应用中加载插页式广告但未加载。我已经在我的应用程序中声明了所有内容,但是logcat又说了另一个故事。

这是logcat

W/Ads     (24737):  Could not find com.google.android.gms.ads.AdActivity, please make sure it is declared in AndroidManifest.xml

 I/iu.UploadsManager(13004):  End new media; added: 0, uploading: 0, time: 134 ms
 I/iu.UploadsManager(13004):  End new media; added: 0, uploading: 0, time: 69 ms
 I/dex2oat (25072):  dex2oat took 20.680s (threads: 2)
 I/dex2oat (25184):  /system/bin/dex2oat --runtime-arg -classpath --runtime-     arg  --instruction-set=arm --instruction-set-features=div --runtime-arg -  Xrelocate --boot-image=/system/framework/boot.art --dex- file=/data/data/com.tech.slidechat/cache/ads-489919204.jar --oat-fd=31 --oat-location=/data/data/com.tech.slidechat/cache/ads-489919204.dex --runtime-arg - Xms64m --runtime-arg -Xmx512m
I/dex2oat (25184):  dex2oat took 78.925ms (threads: 2)
I/Ads     (25163):  CsiReporterFactory: CSI is not enabled. No CSI reporter  created.
I/Ads     (25163):  Starting ad request.
I/Ads     (25163):  Use  AdRequest.Builder.addTestDevice("3DA69D7DC8C309681C9A4C6D3386B798") to get test ads on this device.
I/Ads     (13004):  CsiReporterFactory: CSI is not enabled. No CSI reporter created.
I/Ads     (13004):  CsiReporterFactory: CSI is not enabled. No CSI reporter created.
I/chromium(13004):  [INFO:CONSOLE(0)] "Creating Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.appcache", source:   https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
I/chromium(13004):  [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
I/chromium(13004):  [INFO:CONSOLE(0)] "Application Cache Downloading event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
I/chromium(13004):  [INFO:CONSOLE(0)] "Application Cache Progress event (0 of 1) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
I/chromium(13004):  [INFO:CONSOLE(0)] "Application Cache Progress event (1 of 1) ", source:    https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
 I/chromium(13004):  [INFO:CONSOLE(0)] "Application Cache Cached event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40.html (0)
I/Ads     (25163):  Ad finished loading.
W/Ads     (25163):  It is not recommended to show an interstitial before  onAdLoaded completes.
 I/ActivityManager(669):  START u0 {cmp=com.tech.slidechat/com.google.android.gms.ads.AdActivity (has extras)} from uid 10072 on display 0
I/ActivityManager(669):  Start proc com.tech.slidechat for activity com.tech.slidechat/com.google.android.gms.ads.AdActivity: pid=25337 uid=10072 gids={50072, 9997, 3003, 1028, 1015} abi=armeabi-v7a
 W/Ads     (25337):  Could not get info for ad overlay.

这是我的AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tech.example" >

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/google"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:hardwareAccelerated="true"
    >
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    <activity
        android:launchMode="singleInstance"
        android:alwaysRetainTaskState="true"
        android:name=".MainActivity"
        android:process=":remote"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:label="@string/app_name"
        >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
</application>

我的主要活动

public class MainActivity extends ActionBarActivity {

  SlidingTabLayout tabs;
  ViewPager viewPager;
  TabsPagerAdapter adapter;
  Toolbar toolbar;
private InterstitialAd mInterstitialAd;


CharSequence Titles[]={ "tab1", "tab2", "tab3" };
int Numboftabs =3;

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getString(R.string.ad_unit_id));
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("AALUBHALU")
            .build();
    mInterstitialAd.loadAd(adRequest);



     toolbar = (Toolbar) findViewById(R.id.tool_bar);
      setSupportActionBar(toolbar);


    adapter = new TabsPagerAdapter(getSupportFragmentManager(), Titles, Numboftabs);

    // Assigning ViewPager View and setting the adapter
    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(2);
    // Assiging the Sliding Tab Layout View
    tabs = (SlidingTabLayout) findViewById(R.id.tabs);
    tabs.setDistributeEvenly(true);



    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.tabsScrollColor);
        }

        @Override
        public int getDividerColor(int i) {
            return 0;
        }
    });

    tabs.setViewPager(viewPager);
    // Prepare an Interstitial Ad Listener
    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            // Call displayInterstitial() function
            displayInterstitial();
        }
    });
}
public void displayInterstitial() {
    // If Ads are loaded, show Interstitial else show nothing.
    if (mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    }
}



}

ProGuard规则

For Google Play Services
-keep public class com.google.android.gms.ads.**{
 public *; 
} 

For old ads classes
-keep public class com.google.ads.**{
 public *;
 }

For mediation
-keepattributes *Annotation*

Other required classes for Google Play Services
Read more at http://developer.android.com/google/play-services/setup.html
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}

-keep public class     

 com.google.android.gms.common.internal.safeparcel.SafeParcelable {
 public static final *** NULL;
 }
-keep class * extends java.util.ListResourceBundle {
 protected Object[][] getContents();
 }

 -keep public class   

com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
 @com.google.android.gms.common.annotation.KeepName *;
 }

 -keepnames class * implements android.os.Parcelable {
 public static final ** CREATOR;
 }

我不知道有什么不对请帮我查一查。 感谢。

2 个答案:

答案 0 :(得分:2)

你应该像这样制作清单:

<activity android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent"
    android:process=":remote"/>

AdActivity必须与主要活动

处于同一过程中

答案 1 :(得分:0)

首先在应用中的自然断点处拨打interstitial.show(),而不是从onAdLoaded(),否则您将提供极端糟糕的用户体验,并且很可能会禁止您的Admob帐户。

在关于AdActivity的警告之前,您还没有包含任何日志,并且您还没有在logcat中包含时间戳,因此很难确切知道发生了什么。但首先要确保上面的AndroidManifest实际上已将其整合到您的APK中。