【问题标题】:Admob crashing the appAdmob 让应用程序崩溃
【发布时间】:2014-09-15 06:13:49
【问题描述】:

我尝试先在没有 admob 的情况下运行我的代码。它工作正常。然后我尝试使用 admob 运行我的代码,该应用程序在启动时崩溃,甚至没有显示消息,只是崩溃了。 我已经提供了活动 main 和 layout.xml 和清单的代码。如果您需要查看 imageAdapter 和 GalleryFlow,我也会发布。 这是我的代码:

   public class ActivityMain extends Activity {
   private GalleryFlow mGalleryFlow;
   private AdView adView;
   private InterstitialAd interstitial;

      private int[] imageIds = new int[] { R.drawable.gal1, R.drawable.gal2,
            R.drawable.gal3, R.drawable.gal4, R.drawable.gal5,
            R.drawable.gal6, R.drawable.gal7, R.drawable.gal8,
            R.drawable.gal9, R.drawable.gal10, R.drawable.gal11,
            R.drawable.gal12, R.drawable.gal13, R.drawable.gal14,
            R.drawable.gal15, R.drawable.gal16, R.drawable.gal17,};
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_gallery);

    findViews();
     initViews();
    adView = new AdView(this);
    adView.setAdSize(AdSize.SMART_BANNER);
    adView.setAdUnitId("MY ID HERE");


     RelativeLayout layout = (RelativeLayout) findViewById(R.id.layoutAdView);
     layout.addView(adView);


     AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();


    adView.loadAd(adRequest);

    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId("MY ID HERE");

      AdRequest adRequest1 = new AdRequest.Builder().build();
    interstitial.loadAd(adRequest);
    interstitial.setAdListener(new AdListener() {
        public void onAdLoaded() {
            displayInterstitial();
        }
    });
    }

    public void displayInterstitial() {
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
    }






    private void findViews() {
        mGalleryFlow = (GalleryFlow) findViewById(R.id.Gallery01);
    }

    private void initViews() {
        ImageAdapter adapter = new ImageAdapter(this, imageIds);

        adapter.createReflectedImages();
        mGalleryFlow.setAdapter(adapter);
    }


}    

布局xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  xmlns:ads="http://schemas.android.com/apk/res-auto" 
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".Runhere"
  android:background="#FFA500" >


 <com.norka.gallery.GalleryFlow 
 android:id="@+id/Gallery01" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent"/>

  <RelativeLayout 
android:id="@+id/layoutAdView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp" 
android:layout_alignParentBottom="true"
android:gravity="center_horizontal" />

</RelativeLayout>

我的清单.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.norka.gallery"
    android:versionCode="1"
    android:versionName="1.0">

      <uses-permission android:name="android.permission.INTERNET"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="10" />



     <application android:icon="@drawable/icon" android:label="@string/app_name">

     <activity android:name="com.google.android.gms.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
      <activity android:name="com.norka.gallery.ActivityMain"
              android:label="@string/app_name">


        <meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version"/>


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

   </application>


</manifest> 

LogCat

09-15 07:32:38.798: I/MultiDex(30217): install
09-15 07:32:38.798: I/MultiDex(30217): MultiDexExtractor.load(/data/downloads/PrebuiltGmsCore.apk, false)
09-15 07:32:38.808: I/MultiDex(30217): loading existing secondary dex files
09-15 07:32:38.808: I/MultiDex(30217): load found 1 secondary dex files
09-15 07:32:38.808: I/MultiDex(30217): install done
09-15 07:32:38.808: I/ProviderInstaller(30217): Insert disabled by gate 'gms:security:enable_conscrypt_in_gms_application'
09-15 07:32:38.828: I/MultiDex(30234): install
09-15 07:32:38.828: I/MultiDex(30234): MultiDexExtractor.load(/data/downloads/PrebuiltGmsCore.apk, false)
09-15 07:32:38.838: D/PackageBroadcastService(30217): Received broadcast action=android.intent.action.PACKAGE_REMOVED and uri=com.norka.gallery
09-15 07:32:38.838: D/dalvikvm(30217): Trying to load lib /data/downloads/libAppDataSearch.so 0x95fb0a40
09-15 07:32:38.838: E/dalvikvm(30217): dlopen("/data/downloads/libAppDataSearch.so") failed: dlopen failed: "/data/downloads/libAppDataSearch.so" has unexpected e_machine: 40
09-15 07:32:38.838: E/Icing(30217): Native load error: dlopen failed: "/data/downloads/libAppDataSearch.so" has unexpected e_machine: 40
09-15 07:32:38.838: I/MultiDex(30234): loading existing secondary dex files
09-15 07:32:38.838: I/MultiDex(30234): load found 1 secondary dex files
09-15 07:32:38.838: I/MultiDex(30234): install done
09-15 07:32:38.848: I/Icing(30217): Storage manager: low false usage 9.34KB avail 6.17GB capacity 6.59GB
09-15 07:32:38.858: I/ProviderInstaller(30234): Insert disabled by gate 'gms:security:enable_conscrypt_in_gms_application'
09-15 07:32:38.868: D/dalvikvm(30217): GC_FOR_ALLOC freed 430K, 21% free 2955K/3728K, paused 0ms, total 0ms
09-15 07:32:38.938: E/Icing(30217): Error initializing, resetting corpora: Could not create native index
09-15 07:32:38.938: E/Icing(30217): Internal init failed
09-15 07:32:38.938: E/Icing(30217): Couldn't handle android.intent.action.PACKAGE_REMOVED intent due to initialization failure.
09-15 07:32:39.108: D/PackageBroadcastService(30217): Received broadcast action=android.intent.action.PACKAGE_ADDED and uri=com.norka.gallery
09-15 07:32:39.178: E/Icing(30217): Couldn't handle android.intent.action.PACKAGE_ADDED intent due to initialization failure.
09-15 07:32:39.218: I/PeopleContactsSync(30217): CP2 sync disabled
09-15 07:32:39.318: D/dalvikvm(30217): GC_FOR_ALLOC freed 590K, 17% free 3189K/3812K, paused 0ms, total 0ms
09-15 07:32:39.758: D/PackageBroadcastService(30217): Received broadcast action=android.intent.action.PACKAGE_REPLACED and uri=com.norka.gallery
09-15 07:32:39.758: E/Icing(30217): Couldn't handle android.intent.action.PACKAGE_REPLACED intent due to initialization failure.

09-15 07:32:39.758:I/PeopleContactsSync(30217):CP2 同步已禁用

【问题讨论】:

  • 发布你的完整错误日志
  • 这是完整的 LogCat 错误 ...
  • 这看起来不像是 Admob 错误。您在加载本机包时遇到错误。我认为这些是您的应用本地的。

标签: java android xml google-play admob


【解决方案1】:

在您的 XML 代码中声明您的 adView 会好得多。它将防止发生您所看到的奇怪事情。这是一个如何在 XML 中声明它的示例。

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" 
  android:orientation="vertical" style="@style/background">

  <com.google.ads.AdView android:id="@+id/adView"
     ads:loadAdOnCreate="true" 
     ads:adSize="BANNER" 
     ads:adUnitId="@string/admob_unit_id"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >
   </com.google.ads.AdView>
 </RelativeLayout>

【讨论】:

  • 我相信首选的方法是实际上以编程方式设置 id 和 size,尽管它不会被贬值。
  • 这是指旧版 admob,但问题是关于新的 google play version of admob
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-27
  • 1970-01-01
  • 1970-01-01
  • 2014-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多