[英]IllegalStateException when using the Google Play Service Library
I'm getting an IllegalStateException when using the Google Play Service Library and I can't figure out why. 使用Google Play服务库时出现IllegalStateException,我不知道为什么。
I have the google-play-service-lib
project from the Android SDK copied to my working Git repository and imported in the workspace together with my project. 我将Android SDK中的
google-play-service-lib
项目复制到了工作的Git存储库,并与我的项目一起导入了工作区中。
I checked in Project Proprieties->Android and the google-play-service-lib
is added in the library section and I see a green check sign near it. 我检入了Project Proprieties-> Android,并且在库部分中添加了
google-play-service-lib
并且在其附近看到了绿色的复选标记。
AndroidManifest.xml looks like this: AndroidManifest.xml看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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"
android:resource="@xml/global_tracker"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</activity>
</application>
</manifest>
In my onCreate()
method from the MainActivity.java
file the exception is thrown when int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
在我的
MainActivity.java
文件的onCreate()
方法中,当int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
抛出异常int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
is executed. 被执行。
try {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
LoggerUtils.d(LOG,"Google Play services is available, create Ad");
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
FrameLayout layout = (FrameLayout) findViewById(R.id.FragmentContainer);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
} else {
// Google Play services was not available, print reason
LoggerUtils.d(LOG, "Google Play services is not available. " + String.valueOf(resultCode));
}
} catch (Exception e) {
LoggerUtils.e(LOG, e.getMessage());
}
I LogCat I get this message and I can't figure out what the problem is 我收到LogCat我收到此消息,但我不知道是什么问题
07-31 20:54:31.140: E/com.example.test.MainActivity.LOG(3269): The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 5077000 but found 2131034114. 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" />
I checked the google_play_services_version
in the version.xml
from the res->values
folder of google-play-service-lib
project and it contains the expected number 5077000
. 我从
google-play-service-lib
项目的5077000
res->values
文件夹中的version.xml
检查了google_play_services_version
,它包含预期的数字5077000
。 I can only find a reference of 2131034114
in my proguard
folder in the dump.txt
file. 我在
dump.txt
文件的proguard
文件夹中只能找到2131034114
的引用。 This file was created from my previous build of an apk for release where the google_play_services_version
was part of the project but only Google Analytics was introduced not AdMob. 该文件是根据我先前发布的apk版本创建的,其中
google_play_services_version
是该项目的一部分,但仅引入了Google Analytics(分析),而没有引入AdMob。 For the tests I did, I always build a debug apk which as far as I know this is not done with proguard. 对于我所做的测试,我总是构建一个调试apk,据我所知,它不是使用proguard完成的。
I tried cleaning the projects from the workspace several times, closing and opening again Eclipse. 我尝试多次清理工作区中的项目,然后再次关闭并打开Eclipse。 I even uninstalled Google SDK, ADT and installed them again and removed
google-play-service-lib
project from workspace, delete it and copied it from the Google SDK after re-installing. 我什至卸载了Google SDK,ADT并再次安装它们,并从工作区中删除了
google-play-service-lib
项目,将其删除并在重新安装后从Google SDK中复制了它。
I tested on a phone running Android 4.3(Samsung stock ROM on a Galaxy S3) and Android 4.4.4(Samsung Galaxy S2 with CyanogenMod) and on both phones I get the same error. 我在运行Android 4.3(Galaxy S3上的三星股票ROM)和Android 4.4.4(带有CyanogenMod的Samsung Galaxy S2)的手机上进行了测试,在这两款手机上我都遇到了相同的错误。
The value of Google Play Services version is incorrect, inside res/value/integers.xml
, change the value from: Google Play服务版本的值不正确,请在
res/value/integers.xml
中将值更改为:
<integer name="google_play_services_version">2131034114</integer>
to: 至:
<integer name="google_play_services_version">5077000</integer>
The version of Google Play Services that you have is 5077000
not 2131034114
您拥有的Google Play服务版本是
5077000
而不是2131034114
then Refresh -> Clean -> Build
:) 然后
Refresh -> Clean -> Build
:)
Wohoooo! 哇!
android:resource="@xml/global_tracker"/
was causing the problem. android:resource="@xml/global_tracker"/
引起了问题。
I don't remember what tutorial about integration of Google Analytics I found that said to add this tag, but when I had a look again over the Overview of Google Analytics it didn't mention about it. 我不记得我发现有哪本有关Google Analytics(分析)集成的教程说要添加此标签,但是当我再次浏览Google Analytics(分析) 概述时 ,并没有提及它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.