【问题标题】:AdView - Missing adActivity with android:configChanges in AndroidManifest.xmlAdView - AndroidManifest.xml 中缺少带有 android:configChanges 的 adActivity
【发布时间】:2014-02-23 19:31:07
【问题描述】:

我刚刚使用添加添加 (AdMob) 的 Google Play 库方法设置了我的应用。当我运行模拟器时,添加有错误消息:

Missing adActivity with android:configChanges in AndroidManifest.xml

我在以下位置找到了修复:

Missing adActivity with android:configChanges in AndroidManifest.xml

该修复声明执行以下操作:

“com.google.ads.AdActivity”是在使用“libs”文件夹中的 admob sdk jar 时声明的。 >您似乎正在通过 google play services 库使用 admob,因此请更改:

活动 android:name="com.google.ads.AdActivity"

活动 android:name="com.google.android.gms.ads.AdActivity"

还要确保添加元数据标签:

我试过了,CatLog 说要把元标记改回:

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

我的 LogCat:

02-23 14:30:27.091: E/AndroidRuntime(1278): FATAL EXCEPTION: main
02-23 14:30:27.091: E/AndroidRuntime(1278): Process: biz.midl.debtcalculator, PID: 1278
02-23 14:30:27.091: E/AndroidRuntime(1278): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.midl.debtcalculator/biz.midl.debtcalculator.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.os.Looper.loop(Looper.java:136)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at java.lang.reflect.Method.invokeNative(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at java.lang.reflect.Method.invoke(Method.java:515)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at dalvik.system.NativeStart.main(Native Method)
02-23 14:30:27.091: E/AndroidRuntime(1278): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.internal.u.a(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.internal.ag.U(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.internal.ag.a(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at biz.midl.debtcalculator.MainActivity.onCreate(MainActivity.java:41)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.Activity.performCreate(Activity.java:5231)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-23 14:30:27.091: E/AndroidRuntime(1278):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-23 14:30:27.091: E/AndroidRuntime(1278):     ... 11 more

这是我的 .java:

import java.text.DecimalFormat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

public class MainActivity extends Activity {

private AdView adView;

double interestRate;
double r, r1;
int nRemaining, nStarting, nDifference, originalBalance,
        outstandingBalance, originalTerm;
double minPayment, additionalPayment, newPmt;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    adView = new AdView(this);
    adView.setAdUnitId("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //edited out my unitID
    adView.setAdSize(AdSize.BANNER);

    LinearLayout layout = (LinearLayout) findViewById(R.id.ll);
    layout.addView(adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1" >

    <com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />

我也有我的清单:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

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

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

        <activity
            android:name="biz.midl.debtcalculator.MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="biz.midl.debtcalculator.About"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.ABOUT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • 确保您的设备和库上安装了与您在 Eclipse 项目中添加的相同版本的 Google Play 服务,让我知道
  • 您既要为AdMob 定义布局,还要以编程方式添加它。为什么?可能这不是问题,但尝试从布局文件中删除它并简单地以编程方式添加它,因为通过布局定义它可能是一个非常令人头疼的生产者,因为它很棘手。如果这不能解决问题,您能否在问题中说明您采取了哪些步骤来包含 Google Play 服务库?

标签: android xml admob logcat


【解决方案1】:

您需要保持元数据标签不变:

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

另外,你需要替换这个标签:

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

有了这个(如您链接的答案中所建议的那样):

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

由于您使用的是 Google Play 服务而不是旧版 AdMob SDK,因此您需要将活动类的名称从 com.google.ads.AdActivity 替换为 com.google.android.gms.ads.AdActivity

【讨论】:

    【解决方案2】:

    这可能是问题的一部分。看来你不见了……

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

    在你的 AndroidManifest.xml 中

    【讨论】:

      【解决方案3】:

      确保您只包含 Google Play 服务库,而不是 Google Play 服务和 Admob SDK。

      看起来@integer/google_play_services_version 的值为零。您的应用中是否包含 Google Play 服务资源?

      【讨论】:

      • google-play-services_lib 是我包含的唯一库。我的导入添加在顶部
      【解决方案4】:

      如果你正在使用统一,你应该使用它。

       <!-- Google Mobile Ads Permissions -->
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      

      【讨论】:

        【解决方案5】:

        删除布局声明并保留程序化声明。还有一些不相关的问题导致 Eclipse 出现问题。

        【讨论】:

          【解决方案6】:

          从播放服务更新到版本 22,您无需进行上述更改即可,我将代码粘贴在此处以供将来参考

           <meta-data
                  android:name="com.google.android.gms.version"
                  android:value="@integer/google_play_services_version" />
          
                  <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
          

          在 androidmanifest.xml 文件中,将 google play 服务作为 lib。项目改为使用 admobsdk.jar 文件

          【讨论】:

            【解决方案7】:

            您所要做的就是将其添加到您的 AndroidManifest.xml 文件中:

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

            【讨论】:

              【解决方案8】:

              在 Android manifestxml 中似乎缺少 android configchanges 的活动

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2012-10-28
                • 2012-10-01
                • 1970-01-01
                • 1970-01-01
                • 2011-11-03
                • 2012-09-08
                • 2013-04-27
                相关资源
                最近更新 更多