Java Google Play 服务更新到版本 13 后出现错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19723811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
After Google Play Service update to version 13 I got an error
提问by Igor Kostenko
How can I resolve this 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:
引起:java.lang.illegalargumentexception 11-01 11:08:12.845:E/AndroidRuntime(28885):引起:java.lang.IllegalStateException:您应用程序的 AndroidManifest.xml 中的元数据标记没有正确的值. 预期为 4030500,但发现为 0。您必须在元素中具有以下声明:
google-play-services_lib Manifest:
google-play-services_lib 清单:
<?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>
public void loginGooglePlus() {
aHelper.setup(this, GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_GAMES);
mHelper = aHelper.getAppStateClient();
//crash is here
mHelper.connect();
}
Full error log:
完整的错误日志:
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 <application> 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.access0(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 <application> 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
采纳答案by Benoit
You need to add the following in your manifest:
您需要在清单中添加以下内容:
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
</application>
EDIT:
编辑:
This information can be found in the logcat error msg as well as on Setting Up Google Play Services(Thanks Brais Gabin)
此信息可以在 logcat 错误消息以及设置 Google Play 服务中找到(感谢 Brais Gabin)
回答by Tarsem Singh
@Benoit'a answer has exact solution i am answering with additional knowledge:
@Benoit'a 答案有确切的解决方案,我正在用其他知识回答:
1.one way as Benoit answered is add following inside application tag of AndroidManifest.xml
1.Benoit 回答的一种方法是在应用程序标签中添加以下内容AndroidManifest.xml
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
2.we can directly add the version code like
2.我们可以直接添加版本代码如
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
4030500 is version code which is stored inside
4030500 是存储在里面的版本代码
google-play-services_lib>res>values>version.xml
google-play-services_lib>res>values>version.xml
Like
喜欢
<integer name="google_play_services_version">4030500</integer>
Conclusion: Latest google play services requires a version name, which is to be mentioned using <meta-data .. />
inside AndroidManifest.xml
结论:最新的 google play 服务需要版本名称,<meta-data .. />
在里面使用时会提到AndroidManifest.xml
Note:I would strongly recommend to use 1st way
注意:我强烈建议使用第一种方式
回答by user3072712
I did create a file "version.xml" in the res/values folder of the included copy of google services and pasted the code:
我确实在包含的谷歌服务副本的 res/values 文件夹中创建了一个文件“version.xml”并粘贴了代码:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<integer name="google_play_services_version">4030500</integer>
</resources>
the original copy missed the file and it did solve my problem
原始副本错过了文件,它确实解决了我的问题
回答by Assasin_ng
Add <meta-data>
after closing <application>
tag. This solved my problem
添加<meta-data>
结束后<application>
标签。这解决了我的问题
回答by vaaa
Just make sure to add the below two meta-data tags to 'your' application's AndroidManifest.xml
只需确保将以下两个元数据标记添加到“您的”应用程序的 AndroidManifest.xml
<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"/>
This solution worked for me.
这个解决方案对我有用。
回答by Aqib Mumtaz
I imported my existing project from Eclipse to Android Studio, In Eclipse project Integers.xml
was containing hardcoded value as following
我将现有项目从 Eclipse 导入到 Android Studio,在 Eclipse 项目Integers.xml
中包含如下硬编码值
<integer name="google_play_services_version">5089000</integer>
causing version conflict with latest version of Play Services being built by Android Studio. after removing this line from Integers.xml
it started working for me.
导致与 Android Studio 构建的最新版本的 Play 服务发生版本冲突。从Integers.xml
它删除这条线后开始为我工作。
回答by EyesClear
A few things changed since you asked that question. If you're using Google Play services 7.0 or newer, Gradle will automatically merge manifests and include the required meta-data for you.
自从你问这个问题以来,一些事情发生了变化。如果您使用的是 Google Play 服务 7.0 或更高版本,Gradle 将自动合并清单并为您包含所需的元数据。
Citing Ian Lake:
引用伊恩湖:
(...) Google Play services 7.0 also has one other time saving feature if you're using Gradle: it automatically includes the
(...) 如果您使用 Gradle,Google Play 服务 7.0 还具有另一种节省时间的功能:它会自动包含
<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.
在您的 AndroidManifest.xml 中为您输入 - 无需手动添加!简单 Manifest 合并的完美示例,库可以在其中添加所需的元数据、接收器、权限以及他们需要的任何其他内容 - 少一件要忘记的事情!
注意:这不适用于 full play-services 或 play-services-all-wear AAR - 只有粒度 AAR 内置了这个。
回答by Ahmed Mujtaba
If you still having error try this one.
如果你仍然有错误,试试这个。
it worked for me
它对我有用
<meta-data
tools:replace="android:value"
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />