1

I just released an app on the play store and have gotten a crash report from a galaxy note 4 with this stack trace:

java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode
at android.support.v4.app.q.a(Unknown Source)
at android.support.v4.app.q.startIntentSenderForResult(Unknown Source)
at android.support.v4.app.x.startIntentSenderForResult(Unknown Source)
at com.google.android.gms.common.ConnectionResult.a(Unknown Source)
at com.google.android.gms.common.api.internal.ba.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
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)

I have tested my app on multiple devices and have never gotten an error like this! I do have proguard on which i believe may be the culprit? What do you guys think? The app crashed on the first activity and i only have one requestCode whose value is 111. I don't understand why i could be getting this exception. Google sign in is implemented in the first activity and here is where the requestCode is being used:

private static final int SIGN_IN_REQUEST_CODE = 111 ; (instance variable)



private void signIn() {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, SIGN_IN_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == SIGN_IN_REQUEST_CODE) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }

}

Thanks, Sameer

sameer54321
  • 325
  • 2
  • 8
  • First I see of this error. Seems weird. Hope you find a solution, upvoted for others to see. – Vucko Aug 17 '16 at 19:35
  • Are you sure your SIGN_IN_REQUEST_CODE is 111? It seems that is not the case. – kosa Aug 17 '16 at 19:36
  • Yes, it is 111 I just checked again, the weird thing is that it's only crashing on a few devices. – sameer54321 Aug 17 '16 at 19:39
  • Can proguard play any role in this? – sameer54321 Aug 17 '16 at 19:40
  • There is high probability, If you have access to those devices, I would add log to your code and monitor this value while running your code. I am pretty sure that wouldn't be 111. – kosa Aug 17 '16 at 19:41
  • I don't have access to the device that reported the trace and i don't believe i can emulate a galaxy note 4! – sameer54321 Aug 17 '16 at 19:45
  • If anyone is willing to try my app and see if it works on their device i would really appreciate it! https://play.google.com/store/apps/details?id=com.magnetdev.magnet – sameer54321 Aug 17 '16 at 19:47
  • @sameer54321 can yout edit your question with your `SIGN_IN_REQUEST_CODE` declaration ? The error is related to this variable, so if we see all the uses of the variable maybe we can find something – Lucas Queiroz Ribeiro Aug 17 '16 at 19:55
  • what in this stack trace makes you point to this signIn() code as the possible culprit? This appears to be related to Google Play Services. – CSmith Aug 17 '16 at 19:56
  • @CSmith this is where the request code is being used but yes you are correct it may be an issue with Google Play Services. – sameer54321 Aug 17 '16 at 20:00
  • @LucasQueirozRibeiro Added the declaration for you! – sameer54321 Aug 17 '16 at 20:05

1 Answers1

1

I found some others questions in the SO with the same problem, seems for some Reason your request code is greater than the maximum you can.

The problem occurs in only few devices may be because the problem is solved in later versions.

This code is from the android.support.v4.app.FragmentActivity:

/**
* Modifies the standard behavior to allow results to be delivered to fragments.
* This imposes a restriction that requestCode be <= 0xffff.
*/
@Override
public void startActivityForResult(Intent intent, int requestCode) {
    if (requestCode != -1 && (requestCode&0xffff0000) != 0) {
        throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
    }
    super.startActivityForResult(intent, requestCode);
}

The code above throw a exception if your problem will occurs, so you can test in any device, just override the method on your activity.

I have seem in a comment that the problem may not occurs if you use an Integer beside an int

Another workaround may be use some of the APP Compat Libraries.

Link to the post with the answer above.

Community
  • 1
  • 1