mAt mAt - 2 months ago 35
Android Question

SecurityException: Binder invocation to an incorrect interface on signed APK

I am developing a location aware application. I integrated Google Play Location Services and Google Maps into my application. My application runs without an issue in debug mode. When I generate a signed APK in release mode and run the application, it crashes on startup with following exception:

Process: com.example.akif, PID: 4233
java.lang.RuntimeException: Unable to resume activity {com.example.akif/com.example.akif.activities.MainActivity}: java.lang.SecurityException: Binder invocation to an incorrect interface
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3400)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3440)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2713)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.SecurityException: Binder invocation to an incorrect interface
at android.os.Parcel.nativeEnforceInterface(Native Method)
at android.os.Parcel.enforceInterface(Parcel.java:482)
at vz.onTransact(:com.google.android.gms.DynamiteModulesB:81)
at android.os.Binder.transact(Binder.java:499)
at com.google.android.gms.maps.a.bt.c(Unknown)
at com.google.android.gms.maps.i.b(Unknown)
at com.google.android.gms.b.d.b(Unknown)
at com.google.android.gms.b.j.a(Unknown)
at com.google.android.gms.maps.h.b(Unknown)
at com.google.android.gms.maps.h.a(Unknown)
at com.google.android.gms.b.a.c(Unknown)
at com.google.android.gms.b.a.e(Unknown)
at com.google.android.gms.maps.g.f(Unknown)
at android.support.v4.app.k.ay(Unknown)
at android.support.v4.app.x.l(Unknown)
at android.support.v4.app.ax.h(Unknown)
at android.support.v4.app.ax.i(Unknown)
at android.support.v4.app.ax.run(Unknown)
at android.support.v4.app.x.ae(Unknown)
at android.support.v4.app.i.aa(Unknown)
at android.support.v4.app.a.onPostResume(Unknown)
at android.support.v7.app.a.onPostResume(Unknown)
at android.app.Activity.performResume(Activity.java:6792)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3377)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3440) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2713) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 


I noticed by following logs at each lifecycle method that this happens in my fragment's onResume method where I check for Google Play Services availability as following:

@Override public void onResume() {
Log.debug(getClass(), "onResume()");

GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();

int googlePlayServicesAvailabilityResult = googleApiAvailability.isGooglePlayServicesAvailable(getContext());

if (googlePlayServicesAvailabilityResult != ConnectionResult.SUCCESS) {
if (!googleApiAvailability.isUserResolvableError(googlePlayServicesAvailabilityResult)) {
Toast.makeText(getContext(), "Your device doesn't support Google Play location services. This application cannot run without it!", Toast.LENGTH_LONG).show();

getActivity().finish();

return;
}

Dialog errorDialog = googleApiAvailability.getErrorDialog(getActivity(), googlePlayServicesAvailabilityResult, GOOGLE_PLAY_SERVICES_REQUEST_CODE);

if (errorDialog != null) {
errorDialog.setCancelable(false);
errorDialog.setCanceledOnTouchOutside(false);
errorDialog.setOnDismissListener((DialogInterface dialogInterface) -> {
Toast.makeText(getContext(), "You need Google Play location services to run this application!", Toast.LENGTH_LONG).show();

getActivity().finish();
});

errorDialog.show();
}
} else if (googleApiClient.isConnected() && !isUpdatingLocation) {
startLocationUpdates();
}

super.onResume();
}


My gradle file looks like following:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"

defaultConfig {
applicationId "com.example.akif"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "0.1"

jackOptions {
enabled true
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
debug {
applicationIdSuffix '.test'
}

release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:preference-v7:24.2.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.github.mehmetakiftutuncu:toolbelt:1.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'joda-time:joda-time:2.9.4'
}


I have two Google Maps API keys set up according to my package names
com.example.akif.test
and
com.example.akif
respectively for debug and release modes. So, I don't think it's related to package names but then again, it could very well be about that as I didn't understand anything from the error.

Any idea what is happening?

mAt mAt
Answer

After doing a lot of research with almost no results, I was able to fix the issue with following Proguard rules:

-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**

I still don't know the real reason why I had this issue but it seems fixed with this.

Hope this helps.