googlesamples/google-signin-unity

JNI Abort Error occurs on Google Sign In from Android App built using Unity if minifyEnabled is true

SundeepThirumuru opened this issue · 2 comments

Reporting this issue as a FYI if anyone else encounters this.

With minifyEnabled as part of Android publishing settings in Unity for release or debug , I encountered JNI Abort Error when initiating Google Sign In.

I think the reason is the C# scripts converted to C++ (by IL2CPP) and made as a .so file tries to look for original Java method signatures. When minified, they would not be available with the original method names. Hence, I believe JNI Abort Errors happen.

C++ method calling the Java method

    [DllImport(DllName)]
    static extern bool GoogleSignIn_Configure(HandleRef self,
      bool useGameSignIn, string webClientId,
      bool requestAuthCode, bool forceTokenRefresh, bool requestEmail,
      bool requestIdToken, bool hidePopups, string[] additionalScopes,
      int scopeCount, string accountName);

JNI Abort Error

06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at libc.abort(abort:164)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at libart.art::Runtime::Abort(char const*)(Abort:2308)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at libbase.0x13be4(Native Method)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at libbase.android::base::LogMessage::~LogMessage()(~LogMessage:320)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at libart.art::JavaVMExt::JniAbort(char const*, char const*)(JniAbort:2572)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at libart.art::JNI<false>::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list)(CallStaticVoidMethodV:1564)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at split_config._JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)(CallStaticVoidMethod:120)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at split_config.googlesignin::GoogleSignIn::GoogleSignInImpl::CallConfigure()(CallConfigure:600)
06-22 18:41:33.039 12707 29810 E AndroidRuntime: 	at split_config.GoogleSignIn_Configure(GoogleSignIn_Configure:468)

Fix
I overcame this issue by disabling minification (minifyEnabled = false) in Unity publishing settings for Android for both release and debug. We might be losing some APK size reduction and code ambiguity gains. But if all of the app code is in c#, it might not be a problem.
Happy to hear other fixes to this issue.

use proguard file to list all rules for GoogleSignIn plugin
avoid classes & methods stripped by building script

use proguard file to list all rules for GoogleSignIn plugin avoid classes & methods stripped by building script

Great! more targeted and definitely better.