关于Java:Google Play服务更新至版本13后,出现错误

After Google Play Service update to version 13 I got an error

如何解决此错误?

Caused by: java.lang.illegalargumentexception
11-01 11:08:12.845: E/AndroidRuntime(28885): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the element:

google-play-services_lib清单:

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.android.gms"
    android:versionCode="4030530"
    android:versionName="4.0.30 (889083-30)">

    <uses-sdk android:minSdkVersion="8"/>

</manifest>

1
2
3
4
5
6
public void loginGooglePlus() {
    aHelper.setup(this, GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_GAMES);
    mHelper = aHelper.getAppStateClient();
    //crash is here
    mHelper.connect();
}

完整的错误日志:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
11-01 11:38:13.507: E/AndroidRuntime(31297): FATAL EXCEPTION: main
11-01 11:38:13.507: E/AndroidRuntime(31297): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.application.android.aja/com.company.application.android.aja.BeetleBattleAndroidActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the  element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.os.Looper.loop(Looper.java:154)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.ActivityThread.main(ActivityThread.java:4624)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at java.lang.reflect.Method.invokeNative(Native Method)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at java.lang.reflect.Method.invoke(Method.java:511)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:965)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:732)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at dalvik.system.NativeStart.main(Native Method)
11-01 11:38:13.507: E/AndroidRuntime(31297): Caused by: java.lang.IllegalStateException: The meta-data tag in your app'
s AndroidManifest.xml does not have the right value.  Expected 4030500 but found 0.  You must have the following declaration within the  element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.google.android.gms.internal.de.connect(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.google.android.gms.appstate.AppStateClient.connect(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.company.application.android.aja.BeetleBattleAndroidActivity.loginGooglePlus(BeetleBattleAndroidActivity.java:153)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at com.company.application.android.aja.BeetleBattleAndroidActivity.onCreate(BeetleBattleAndroidActivity.java:143)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.Activity.performCreate(Activity.java:4509)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
11-01 11:38:13.507: E/AndroidRuntime(31297):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
11-01 11:38:13.507: E/AndroidRuntime(31297):    ... 11 more


您需要在清单中添加以下内容:

1
2
3
4
5
    <meta-data
       android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />
    ...
</application>

编辑:

可以在logcat错误消息以及设置Google Play服务中找到此信息(感谢Brais Gabin)


@ Benoit'a答案有确切的解决方案,我正在用其他知识回答:

1. Benoit回答的一种方法是在AndroidManifest.xml的应用程序标签内添加以下内容

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

2.我们可以直接添加类似的版本代码

1
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />

4030500是存储在内部的版本代码

google-play-services_lib> res> values> version.xml

喜欢

1
<integer name="google_play_services_version">4030500</integer>

结论:最新的Google Play服务需要一个版本名称,要在AndroidManifest.xml中使用来提及

注意:我强烈建议您使用第一种方法


自从您问了这个问题以来,有些事情发生了变化。如果您使用的是Google Play服务7.0或更高版本,Gradle将自动合并清单并为您提供所需的元数据。

引用伊恩湖:

(...) Google Play services
7.0 also has one other time saving feature if you're using Gradle: it automatically includes the

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

entry in your AndroidManifest.xml for you - no need to manually add
it! Perfect example of simple Manifest merging where libraries can
add required meta-data, receivers, permissions, and anything else they
made need - one less thing to forget!

Note: this does not apply to the full play-services or
play-services-all-wear AARs - only the granular AARs have this built
in.


我将现有项目从Eclipse导入到Android Studio,在Eclipse项目Integers.xml中包含如下的硬编码值

1
<integer name="google_play_services_version">5089000</integer>

导致与Android Studio正在构建的Play服务的最新版本发生版本冲突。从Integers.xml删除此行后,它开始为我工作。


只要确保将以下两个元数据标签添加到"您的"应用程序的AndroidManifest.xml中即可

1
2
3
4
5
6
<meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR_API_KEY"/>
<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

这个解决方案对我有用。


如果仍然有错误,请尝试此操作。

它对我有用

1
2
3
4
<meta-data
    tools:replace="android:value"
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

我确实在包含的Google服务副本的res / values文件夹中创建了一个文件" version.xml",并粘贴了代码:

1
2
3
4
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<integer name="google_play_services_version">4030500</integer>
</resources>

原始副本错过了文件,它确实解决了我的问题


关闭标签后添加。这解决了我的问题