java - 加载失败,请确认其已声明

标签 java android android-fragments webview admob

我正在尝试在我的应用程序中加载插页式广告,但它没有加载。我已经在我的应用程序中声明了所有内容,但 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>

我的主要 Activity

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;
 }

我不知道哪里出了问题,请帮我看看。 谢谢。

最佳答案

你应该像这样制作 list :

<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 必须与主 Activity 位于同一进程中

关于java - 加载失败,请确认其已声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011610/

相关文章:

java - 为什么我不能为另一个类提取方法?

java - 线程安全的 HashMap ?

java - 下载监听器网页 View

android - 二进制 XML 文件第 26 行 : Duplicate id, 标记为空,或带有另一个 fragment 的父 ID

java - Activity被fragment隐藏了,无法使用

java - 如何使用此代码显示我的二维数组?

java - 安卓 : How to read file in bytes?

java - 无法解析导入 com.google.maps.android.R

java - 在 Android Java 中使用 wait/notify 是一个好习惯吗?

android - 如何从 RecyclerView.ViewHolder 调用 DialogFragment(带接口(interface)实现)