2

アプリにAdMobを実装しようとしていますが、追加した後、アプリを起動できませんでした。

これはアクティビティコードです: http ://code.google.com/p/zhuang-dict/source/browse/trunk/ZhuangDict/src/cn/wangdazhuang/zdict/ZhuangDictActivity.java

main.xml:

<?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:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    >
        <ImageButton
            android:id="@+id/ts"
            android:contentDescription="@string/tts_contentDescription"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" 
            android:src="@android:drawable/ic_btn_speak_now"
        />
        <ImageButton
            android:id="@+id/search"
            android:contentDescription="@string/search_contentDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/ts"
            android:src="@android:drawable/ic_search_category_default"
        />
        <AutoCompleteTextView
            android:id="@+id/edit"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:focusable="true"
            android:singleLine="true"
            android:layout_toLeftOf="@id/search"
            android:hint="@string/edit_hint"
        />
    </RelativeLayout>
    <WebView
        android:id="@+id/result"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
    <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="myId"
                     ads:adSize="BANNER"
                     ads:loadAdOnCreate="true"
     />
</LinearLayout>
4

4 に答える 4

4

これをマニフェストに追加しましたか?

    <activity android:name="com.google.ads.AdActivity"
          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

グーグルによるチュートリアルに示されているように:

    <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="MY_AD_UNIT_ID"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     ads:loadAdOnCreate="true"/>

adUnitIdはアプリのIDである必要があります。このIDを設定しましたか、それとも上記のコードのように実際に「myid」を設定しましたか?

編集

ここにいくつかの追加情報があります。AdMobLibがプロジェクトにバンドルされていないようです。これは多くの異なる理由を引き起こす可能性があります。手順を読んで確認してください。そうでない場合は、実際にこれを実行しました。

EclipseとAndroidSDKを更新します。

  1. 管理者としてEclipseを開きます
  2. [ヘルプ]->[更新の確認]に移動して、更新を実行します
  3. 次のウィンドウに表示されるすべてのチェック済みを設定します。必須ではありませんが、すべてを更新することは間違いありません
  4. 利用規約とライセンシーに同意し、[完了]を押します...更新が開始され、しばらく時間がかかります
  5. 更新が終了したら、Eclipseを管理者として再起動します。すべての更新を実行できなかったというエラーメッセージが表示される可能性があります...先に進んでください

Android SDKの更新:

  1. Eclipseのgotoウィンドウ->AndroidSDK Manager
  2. [ステータス]列で更新が利用可能かどうかを確認します。すべての更新を選択...
  3. 終了したら、Eclipseを再起動します

Admobでの作業-jarファイルを配置してパスを設定します:

  1. GoogleサイトからAdMobSDKをダウンロードします(国によって異なるリンクになる可能性があります) https://developers.google.com/mobile-ads-sdk/download?hl=de
  2. ファイルをディレクトリに解凍します(場所に関係なく)
  3. Eclispeのプロジェクト内に「libs」フォルダーを作成します。フォルダの名前が「lib」ではなく「libs」であることを確認してください。この間違いはよくあることです


  4. jarファイルをadmobフォルダーからプロジェクトのlibsフォルダーにコピーします

  5. libフォルダー内のjarファイルを右クリックして、[ビルドパス]->[ビルドパスに追加]を選択します。
  6. すべてが実際に行われたことを確認するには、プロジェクト上でマウスの右ボタンをクリックして、プロパティを選択します
  7. Java-Build-Pathを選択し、[ライブラリ]タブに移動します
  8. [外部jarの追加]を選択し、admobフォルダーからこのjarを選択します
  9. [OK]を選択します

始めましょう

  1. これをManifest.xmlに入れます

    <activity android:name="com.google.ads.AdActivity"
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
     </application>
    

Manifest.xmlは次のようになります。

       <?xml version="1.0" encoding="utf-8"?>
         <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.company"
          android:versionCode="1" android:versionName="1.0">
       <application android:icon="@drawable/icon" android:label="@string/app_name"
           android:debuggable="true">
       <activity android:label="@string/app_name" android:name="BannerExample">
           <intent-filter>
           <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
       </activity>
      <activity android:name="com.google.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
        </application>
        </manifest>

注:この行は、内部ではなく、アクティビティの下に配置してください

  1. マニフェスト.xml内に権限を設定します

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
  2. たとえば、チュートリアルに示されているようなxmlレイアウトを作成します

    <?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:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
        <com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="MY_AD_UNIT_ID"
                     ads:adSize="BANNER"
                     ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                     ads:loadAdOnCreate="true"/>
       </LinearLayout>
    
  3. さらに、上記の手順が機能しなかった場合は、AdMobを表示するアクティビティ内でこれを行うことができます。アクティビティのonCreate()でAdMobxmlidを参照してください。

        public class AdMobActivity extends Activity {
    
       private AdView adView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
    
            // Create the adView
       adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
    
           // Lookup your LinearLayout assuming it’s been given
          // the attribute android:id="@+id/mainLayout"
        LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
    
           // Add the adView to it
         layout.addView(adView);
    
           // Initiate a generic request to load it with an ad
        adView.loadAd(new AdRequest());
    
         }
    

私のアプリでは、両方を実行しました。通常はXMLまたはコードで実行するだけで済みますが、どちらでも問題なく動作します。

于 2013-03-21T15:11:27.920 に答える
1

AdMobを初期化していることを確認してください。そうしないと、次のエラーが発生します。

isAdIdFakeForDebugLoggingの取得に失敗しました

MobileAds.initialize(this, AD_MOB_ID);
于 2018-08-09T17:09:33.140 に答える
0

次の手順を試してください。

  1. libsプロジェクトにフォルダを作成します。
  2. GoogleAdMobsjarファイルをlibsフォルダに追加します。
  3. フォルダからAdMobライブラリをインポートしlibsます。
  4. librayを追加する新しい方法が機能することを確認します。[プロジェクト]->[ビルドパス]->[ビルドパスの構成]->[ライブラリ]タブに切り替え、GoogleAdMobsライブラリがリストに存在することを確認します。

ADTの15番目または16番目のバージョンにアップグレードした後にこの問題が発生しました。どちらか覚えてない。

上記を実行する前に、ライブラリへの以前の参照を削除することを忘れないでください。

于 2013-03-21T15:33:01.347 に答える
0

パレットからGoogleAdViewを追加し、アプリが機能しなくなった場合。

Android Studioの「GradleScripts」フォルダーに移動しますbuild.gradle(Module:app)を見つけます

ファイルの終わりからこの行を削除します

実装'com.google.android.gms:play-services-ads:18.1.1'

ファイルを保存して、プロジェクトを再度ビルドします。すべてが再び正常に動作します

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-ads:18.1.1'
}
于 2020-04-14T15:32:12.723 に答える