新错误
让应用有效(加载但声明Google Play服务设置不正确)。查看监视器,它指出E/ViewRootImpl: sendUserActionEvent() mView == null
在尝试奖励成就时也会看到以下内容:
07-19 20:51:42.696 16515-16515/com.gfaiers.hangman E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gfaiers.hangman, PID: 16515
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.google.android.gms.common.api.GoogleApiClient.isConnected()' on a null object reference
at com.gfaiers.hangman.HangmanActivity.endGameQuestion(HangmanActivity.java:842)
at com.gfaiers.hangman.HangmanActivity$2.run(HangmanActivity.java:682)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Tldr:
答案
在底部经常更新
在我开始之前;我是Android开发的新手,这是我第一次这样做 - 想象我知道的很少!我已经坚持了几天并且已经做了很多关于它的阅读 - 主要是关于非常相似并且说同样事情的文章。而且,我所能说的所有这些文章都过时了?
我见过这些
我一开始就一直摔倒......经过另一天我还有更进一步......
首次使用here中的样本时,他们都会说出来
更新样本以不使用PLUS范围。也是去掉了。
不确定这实际意味着什么,但这让我觉得他们已经过时了?知道所有事情经常发生的事情,他们现在还没有被编辑4个月(这样的事情需要很长时间吗?)。
在尝试使用它们的示例中,我收到以下错误(加载TrivialQuest时,这是与成就相关联的那个):
Error:Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in D:\Users\Geoff\AndroidStudioProjects\android-basic-samples-master\BasicSamples\TrivialQuest\gradle\wrapper\gradle-wrapper.properties to gradle-2.2-all.zip.
使用包装器时:
Error:(23, 0) SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
在其他主题中,我需要更改local.properties
中已经正确的目录。
我需要帮助的地方:
我已经在PlayStore上发布了该应用,我已经在其中起草了成就,我只想让他们使用它。
我需要帮助了解如何让BaseGameUtils在我的应用中运行,我已经导入了该模块,并且已经跟踪this guide直到“访问其他Google Play服务API”。
当尝试通过Android Studio在模拟器(Nexus 5,SDK23)中运行应用时,它会提示我更新Google Play服务(无法在模拟器上完成)。我不知道这条消息来自何处,因为整个应用程序中没有字符串,它必须来自google play services。
在Galaxy S7edge(6.0.2)上尝试时,它会立即崩溃并出现以下错误:
06-26 14:46:05.080 2240-2240/com.gfaiers.hangman:background_crash E/InstantRun: IO Error creating local socket at com.gfaiers.hangman java.io.IOException: Address already in use
at android.net.LocalSocketImpl.bindLocal(Native Method)
at android.net.LocalSocketImpl.bind(LocalSocketImpl.java:306)
at android.net.LocalServerSocket.<init>(LocalServerSocket.java:48)
at com.android.tools.fd.runtime.Server.<init>(Server.java:94)
at com.android.tools.fd.runtime.Server.create(Server.java:88)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:358)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1036)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6321)
at android.app.ActivityThread.access$1800(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
在Galaxy S4(5.0.1)上尝试时,它会在白屏上挂起一段时间,然后崩溃并且显示器显示:
06-30 23:56:50.718 2074-2074/com.gfaiers.hangman E/UncaughtException: java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
at com.google.android.gms.common.internal.zzd$zza.zzc(Unknown Source)
at com.google.android.gms.common.internal.zzd$zza.zzx(Unknown Source)
at com.google.android.gms.common.internal.zzd$zze.zzasb(Unknown Source)
at com.google.android.gms.common.internal.zzd$zzd.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
......然后它说
06-30 23:56:52.160 2074-2074/com.gfaiers.hangman E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gfaiers.hangman, PID: 2074
java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
at com.google.android.gms.common.internal.zzd$zza.zzc(Unknown Source)
at com.google.android.gms.common.internal.zzd$zza.zzx(Unknown Source)
at com.google.android.gms.common.internal.zzd$zze.zzasb(Unknown Source)
at com.google.android.gms.common.internal.zzd$zzd.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
06-30 23:56:52.290 3331-3331/com.gfaiers.hangman:background_crash D/ResourcesManager: creating new AssetManager and set to /data/app/com.gfaiers.hangman-1/base.apk
06-30 23:56:52.700 3331-3331/com.gfaiers.hangman:background_crash E/InstantRun: IO Error creating local socket at com.gfaiers.hangman
java.io.IOException: Address already in use
at android.net.LocalSocketImpl.bindLocal(Native Method)
at android.net.LocalSocketImpl.bind(LocalSocketImpl.java:306)
at android.net.LocalServerSocket.<init>(LocalServerSocket.java:52)
at com.android.tools.fd.runtime.Server.<init>(Server.java:94)
at com.android.tools.fd.runtime.Server.create(Server.java:88)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:358)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5122)
at android.app.ActivityThread.access$1600(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1510)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
我的应用程序代码全部在GitHub (MainActivity - where the problems are)上提供。
我迄今为止从指南中做过的代码(我认为问题出在哪里):
private GoogleApiClient mGoogleApiClient;
private static int RC_SIGN_IN = 9001;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInFlow = true;
private boolean mSignInClicked = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the Google Api Client with access to the Play Games services
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
// add other APIs and scopes here as needed
.build();
...
@Override
public void onConnected(Bundle connectionHint) {
// The player is signed in. Hide the sign-in button and allow the
// player to proceed.
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (mResolvingConnectionFailure) {
// already resolving
return;
}
// if the sign-in button was clicked or if auto sign-in is enabled,
// launch the sign-in flow
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
// Attempt to resolve the connection failure using BaseGameUtils.
// The R.string.sign_in_other_error value should reference a generic
// error string in your strings.xml file, such as "There was
// an issue with sign-in, please try again later."
if (!BaseGameUtils.resolveConnectionFailure(this,
mGoogleApiClient, connectionResult,
RC_SIGN_IN, getResources().getString(R.string.sign_in_other_error))) {
mResolvingConnectionFailure = false;
}
}
// Put code here to display the sign-in button
}
@Override
public void onConnectionSuspended(int i) {
// Attempt to reconnect
mGoogleApiClient.connect();
}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (requestCode == RC_SIGN_IN) {
mSignInClicked = false;
mResolvingConnectionFailure = false;
if (resultCode == RESULT_OK) {
mGoogleApiClient.connect();
} else {
// Bring up an error dialog to alert the user that sign-in
// failed. The R.string.sign_in_failure should reference an error
// string in your strings.xml file that tells the user they
// could not be signed in, such as "Unable to sign in."
BaseGameUtils.showActivityResultError(this,
requestCode, resultCode, R.string.sign_in_failure);
}
}
}
// Call when the sign-in button is clicked
private void signInClicked() {
mSignInClicked = true;
mGoogleApiClient.connect();
}
// Call when the sign-out button is clicked
private void signOutClicked() {
mSignInClicked = false;
Games.signOut(mGoogleApiClient);
}
GitHub上的代码全部更新。
我还添加了BaseGameUtils build.gradle文件:
...buildToolsVersion android_version
defaultConfig {
minSdkVersion 17
}
这似乎是解决构建失败的解决方案,说minSdkVersion 1对于库版本7等来说太低了。
最新更新
在做了一些阅读之后,我发现了一些看似非常简单的东西,作为应用程序的AndroidManifest(而不是lib)中的解决方案。
<!--<meta-data android:name="com.gooogle.android.gms.games.APP_ID" android:value="@string/app_id"/>-->
我取出了评论标记,但仍显示上述错误“致命的开发者错误”。我改成了:
<meta-data android:name="com.gooogle.android.gms.games.com.gfaiers.hangman" android:value="@string/app_id"/>
完全不确定这是否是我的意图,它仍然会出现同样的错误。
但是进一步阅读......它说:
07-01 22:15:02.196 24277-24277/com.gfaiers.hangman D/FirebaseCrashApiImpl: throwable java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information.
哪会让我觉得AdMob导致了崩溃?!
请求的local.properties文件
ndk.dir=D\:\\Users\\Geoff\\AppData\\Local\\Android\\Sdk\\ndk-bundle
sdk.dir=D\:\\Users\\Geoff\\AppData\\Local\\Android\\Sdk
目前为止的答案更新
将依赖项更改为:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':BaseGameUtils')
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.google.firebase:firebase-ads:9.2.0'
compile 'com.google.android.gms:play-services-ads:9.2.0'
compile 'com.google.android.gms:play-services-auth:9.2.0'
compile 'com.google.android.gms:play-services-gcm:9.2.0'
compile 'com.google.android.gms:play-services-games:9.2.0'
错误现在显示为:
07-02 09:36:16.061 2133-7644/? E/Ads: Error transporting the ad response
java.io.IOException: write failed: EPIPE (Broken pipe)
at libcore.io.IoBridge.write(IoBridge.java:502)
at java.io.FileOutputStream.write(FileOutputStream.java:186)
at java.io.DataOutputStream.write(DataOutputStream.java:98)
at java.io.OutputStream.write(OutputStream.java:82)
at com.google.android.gms.ads.internal.request.ac.run(:com.google.android.gms:150)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
at libcore.io.Posix.writeBytes(Native Method)
at libcore.io.Posix.write(Posix.java:223)
at libcore.io.BlockGuardOs.write(BlockGuardOs.java:313)
at libcore.io.IoBridge.write(IoBridge.java:497)
at java.io.FileOutputStream.write(FileOutputStream.java:186)
at java.io.DataOutputStream.write(DataOutputStream.java:98)
at java.io.OutputStream.write(OutputStream.java:82)
at com.google.android.gms.ads.internal.request.ac.run(:com.google.android.gms:150)
at java.lang.Thread.run(Thread.java:818)
答案 0 :(得分:4)
在黑暗中只是一枪,但这可能是解决一些问题的第一步......
在您的gradle构建文件中,您要求包含所有Google Play服务:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':BaseGameUtils')
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.google.android.gms:play-services:9.2.0' <-- NOT GOOD
compile 'com.google.firebase:firebase-ads:9.0.0'
compile 'com.google.android.gms:play-services-ads:9.2.0'
compile 'com.google.android.gms:play-services-auth:9.2.0'
compile 'com.google.android.gms:play-services-gcm:9.2.0'
}
这会带来许多你可能没有使用但不需要的功能。您将获得所有Play服务和Firebase libraries。特别是,您将获得新的Firebase崩溃报告,该报告仍处于测试阶段。我看到一些堆栈跟踪中的条目包含标记background_crash
,它是崩溃报告组件之一。
许多人(包括我自己)在拉入所有PlayServices / Firebase时导致应用程序挂起问题。 See this related issue
作为起点,我建议您修改依赖项以删除play-services:9.2.0
,然后仅保留或添加使您的应用成功构建所需的特定库。它可能无法修复所有崩溃,但可能有所帮助。另外,我认为你会发现你的应用程序构建速度更快,并生成更小的APK。
<强>更新强>
您的一个崩溃调用堆栈与this related issue中的崩溃堆栈类似。该崩溃是由于没有定义APP_ID的元数据引起的。我没有在您的清单中定义的元数据。你不需要吗?添加它是此guide for using Games Services中的其中一个步骤。
更新2
我确认问题是APP_ID缺少元数据。您在AndroidManifest文件中曾经有过这个,但是有一个错字。你有一个额外的&#39; o&#39;在谷歌:
com.gooogle.android.gms.games.APP_ID
取消注释清单中的元数据并更正拼写错误。然后应用程序应该运行而不会崩溃。它确实适合我。
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/NoActionBar">
<meta-data
android:name="com.google.android.gms.games.APP_ID" <-- typo was here
android:value="@string/app_id"/>
如果它仍然崩溃,请查看未过滤的logcat输出。为此,请在Android监视器窗口中选择No Filters
。如果APP_ID元数据仍然存在问题,您将看到以下消息:
E/ValidateServiceOp: Using Google Play games services requires a metadata tag with the name "com.google.android.gms.games.APP_ID" in the application tag of the manifest for com.gfaiers.hangman
您可能还想进一步清理构建依赖项:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':BaseGameUtils')
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.google.firebase:firebase-ads:9.2.0'
//compile 'com.google.android.gms:play-services-ads:9.2.0'
//compile 'com.google.android.gms:play-services-auth:9.2.0'
//compile 'com.google.android.gms:play-services-gcm:9.2.0'
compile 'com.google.android.gms:play-services-games:9.2.0'
}
答案 1 :(得分:1)
关于您的问题,我通过在Google Play游戏中添加调试SHA-1解决了我的问题。
请参阅此link中的“c。指定客户端ID设置”以正确设置。
答案 2 :(得分:0)
当我使用谷歌地图和GCM时
compile 'com.google.android.gms:play-services-maps:9.2.0'
compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.maps.android:android-maps-utils:0.4+'
compile 'com.google.android.gms:play-services-ads:9.2.0'
compile 'com.google.android.gms:play-services-auth:9.2.0'
compile 'com.google.android.gms:play-services-gcm:9.2.0'
我删除compile 'com.google.android.gms:play-services:9.2.0' <-- NOT GOOD