CapacitorGoogleAuth icon indicating copy to clipboard operation
CapacitorGoogleAuth copied to clipboard

java.lang.NullPointerException when Google Play is used to build the APK from an app bundle

Open walljm opened this issue 4 years ago • 1 comments

I'm getting a null pointer exception when i run the app after deploying it to the play store. It works when i deploy a debug build to the phone.

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3303)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: java.lang.NullPointerException: 
  at com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth.load (GoogleAuth.java:54)
  at com.getcapacitor.PluginHandle.load (PluginHandle.java:27)
  at com.getcapacitor.PluginHandle.<init> (PluginHandle.java:52)
  at com.getcapacitor.Bridge.registerPlugin (Bridge.java:62)
  at com.getcapacitor.Bridge.registerAllPlugins (Bridge.java:133)
  at com.getcapacitor.Bridge.<init> (Bridge.java:102)
  at com.getcapacitor.BridgeActivity.load (BridgeActivity.java:78)
  at com.getcapacitor.BridgeActivity.init (BridgeActivity.java:59)
  at com.getcapacitor.BridgeActivity.init (BridgeActivity.java:1)
  at walljm.dynamicbible.MainActivity.onCreate (MainActivity.java:8)
  at android.app.Activity.performCreate (Activity.java:7383)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1218)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3256)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3411)
  at android.app.ActivityThread.-wrap12 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1994)
  at android.os.Handler.dispatchMessage (Handler.java:108)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

walljm avatar Mar 04 '21 12:03 walljm

OK,

I found the issue. When Google Play builds the APKs for app bundle, it minimizes the code and does so by renaming the class names to simple letters (a, b, c, etc...)

That causes the capacitor code that gets the config to not use "GoogleAuth" as the name it uses when it tries to lookup the JSON config in the capacitor.config.json file.

You need to add a name property to the NativePlugin attribute like so:

@NativePlugin(name="GoogleAuth", requestCodes = GoogleAuth.RC_SIGN_IN)

to fix the issue.

In the mean time, you can add a proguard rule to your proguard-rules.pro file to mitigate the issue, or just disable the minify option in your build.gradle.

walljm avatar Mar 04 '21 14:03 walljm