Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Play Achievements "IOException: Address already in use"

New Errors

Have app working (loads but states that the google play services is incorrectly set up). Looking at the monitor it states E/ViewRootImpl: sendUserActionEvent() mView == null

And also see the below erorr when trying to award achievement:

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:

  • I've made Hangman game for Android in Android Studio. Code here
  • I want to use Achievements in the game.
  • Following googles guides hasn't worked for me so far.
  • What to do now?

Answer

  • Simple typo. Seriously.

FREQUENTLY UPDATED AT BOTTOM

Before I begin; I'm new to Android development and this is my first time doing this - imagine I know very little! I've been stuck on this for a few days and have done a lot of reading about it - mainly on articles that are all very similar and say the same things. Also, all of those articles from what I can tell are quite dated?

I've seen these

  • https://developers.google.com/games/services/android/init
  • https://developers.google.com/games/services/android/achievements
  • https://github.com/playgameservices/android-basic-samples/tree/master/BasicSamples

I keep on falling over right at the start... After another day I've got a little further though...

  • Setup Google Play Games Services
  • Gradle version 2.2 is required. Current version is 2.10
  • SDK Location not found Android Studio + Gradle

When using the samples from here firstly they all say on them

Updating samples to not use PLUS scope. Also de-linted.

Unsure what this actually means, but it makes me think they're out dated? Knowing how often everything moves on, they've not been edited for 4 months now (is that a long time for stuff like this?).

In the samples when trying to use them I get the following errors (when loading TrivialQuest which is the one that's linked to Achievements):

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.

When using the wrapper:

Error:(23, 0) SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

Which in the other topics it states for this I need to change the directory in local.properties which is already correct.

Where I want help:

I have the app published on the PlayStore already, I have drafted achievements into it, and I just want to get them working with it.

I need help finding out how to get BaseGameUtils working in my app, I have imported the module, and have followed this guide up till "Accessing additional Google Play services APIs".

When trying to run the app in the emulator (Nexus 5, SDK23) through Android Studio it prompts me to update google play services (which can't be done on an emulator). I don't know where this message is even coming from, as there isn't a string for it throughout the whole application, it must be from google play services it's self.

When trying it on a Galaxy S7edge (6.0.2) it crashes instantly with the following error:

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)

When trying it on a Galaxy S4 (5.0.1) it hangs for a while with a white screen, then crashes out and the monitor says:

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)

... then it says

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)

My code for the application is all available on GitHub (MainActivity - where the problems are).

Code that I've done so far from the guide (where I presume the issue is):

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);
}

Code on GitHub all updated.

I've also added to the BaseGameUtils build.gradle file:

...buildToolsVersion android_version

defaultConfig {
    minSdkVersion 17
}

This has seemed to be a solution for getting around build fail saying minSdkVersion 1 is too low for library version 7 etc etc.

Latest update

After doing a bit more reading, I found something which looks to be very simple as solution in the AndroidManifest of the app (not the lib).

<!--<meta-data android:name="com.gooogle.android.gms.games.APP_ID" android:value="@string/app_id"/>-->

I took out the comment marks, and it still displayed the above error "A fatal developer error". I changed it to:

<meta-data android:name="com.gooogle.android.gms.games.com.gfaiers.hangman" android:value="@string/app_id"/>

Completely unsure if this is what I was meant to do, and it still did the same error.

But reading into this further... it states:

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.

which would make me think it's the AdMob which is causing the crash?!

Requested local.properties file

ndk.dir=D\:\\Users\\Geoff\\AppData\\Local\\Android\\Sdk\\ndk-bundle
sdk.dir=D\:\\Users\\Geoff\\AppData\\Local\\Android\\Sdk

Updates from answers so far

Changed dependencies to:

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'

Errors now appear as:

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) 
like image 568
Geoff Avatar asked Jun 26 '16 13:06

Geoff


2 Answers

Just a shot in the dark, but it might be the first step in solving some of the issues...

In your gradle build file you are requesting inclusion of all of Google Play Services:

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'
}

This pulls in many capabilities that you probably are not using and do not need. You get all the Play Services and Firebase libraries. In particular, you get the new Firebase Crash Reporting, which is still in Beta. I see entries in some of your stack traces which contain the tag background_crash which is one of the Crash Reporting components.

Many people (myself included) have had problems with app hangs caused by pulling in all of PlayServices/Firebase. See this related issue.

As a starting point, I'd recommend editing your dependencies to remove play-services:9.2.0 and then retain or add only the specific libraries needed to get your app to build successfully. It probably won't fix all the crashes, but may help. Plus, I think you'll find your app builds faster and produces a smaller APK.

Update

One of your crash call stacks is similar to the one in this related issue. That crash was caused by not having the metadata for APP_ID defined. I don't the meta data defined in your manifest. Don't you need it? Adding it is one of the steps in this guide for using Games Services.

Update 2

I confirmed the problem is the missing metadata for APP_ID. You had it at one time in your AndroidManifest file but there was a typo. You had an extra 'o' in google:

com.gooogle.android.gms.games.APP_ID

Uncomment the metadata in the manifest and correct the typo. The app should then run without crashing. It did for me.

<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"/>

If it still crashes, look at the unfiltered logcat output. To do that select No Filters in the Android Monitor window.. If there is still a problem with the APP_ID metadata, you will see this message:

 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

You might also want to do further cleanup of your build dependencies:

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'
}
like image 113
Bob Snyder Avatar answered Nov 15 '22 00:11

Bob Snyder


In regards to your issue, I solved mine by adding the debug SHA-1 in Google Play Games.

See "c. Specify client ID settings" in this link to get set up correctly.

like image 36
Mike Scamell Avatar answered Nov 14 '22 23:11

Mike Scamell