yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
890 stars 131 forks source link

NativeShare.Share() throwing exception on Android prod builds only (Unity NativeShare not doing anything on Android prod builds) #162

Closed dginovker closed 1 year ago

dginovker commented 1 year ago

Description of the bug

Hello! Thanks for the package.

I've got an app using NativeShare and it works great both on development builds and all iOS builds. Unfortunately, on Android prod I'm getting the following exception:

UnityEngine.AndroidJavaException: java.lang.NullPointerException: Expected to unbox a 'boolean' primative type but was returned null at
UnityEngine.AndroidJNISafe.CheckException()
AndroidJNISafe.CallStaticVoidMethod
UnityEngine.AndroidJavaObject._CallStatic 
UnityNativeShare.cs

From this line here: https://github.com/yasirkula/UnityNativeShare/blob/master/Plugins/NativeShare/NativeShare.cs#L208

Reproduction steps

Very confused, here's what I'm doing

new NativeShare()
.SetSubject("Hi!")
.SetUrl("Wee")
.SetCallback((result, _) =>
{
  switch (result)
  {
    // Stuff that works on iOS and Android development builds
  }
}).Share();

Platform specs

Please provide the following info if this is a Unity 3D repository.

Additional info

It was hard to figure out even an exception was being thrown but I'm mostly making this to keep track of my thoughts as I debug it

yasirkula commented 1 year ago

Hi! Is there a C# script called UnityNativeShare.cs in your project? NativeShare.Share's native source code doesn't have a boolean which gets me confused: https://github.com/yasirkula/UnityNativeShare/blob/13ad5af7c378f6b47c0ec4ad34b55bce38883526/.github/AAR%20Source%20(Android)/java/com/yasirkula/unity/NativeShare.java#L40

dginovker commented 1 year ago

Yup! I'm confused too. It seems like the boolean is further inside the AJC.CallStatic's stacktrace.

(None of the parameters passed into CallStatic are null either)

yasirkula commented 1 year ago

Can I see the full stacktrace? Is there a C# script called UnityNativeShare.cs in your project?

dginovker commented 1 year ago

I can't get the full stacktrace, I've been printing it out via a message dialog in my app since it isn't appearing in the logs lol.

I do not have a UnityNativeShare.cs in my project. Should I?

I'm utmost confused since it works on development builds

dginovker commented 1 year ago

Looks like we have additional obfuscation at play (BeeByte Obfuscator). Will update later with the config change needed to make it work, thanks for all your help and the package @yasirkula :hugs:

I Unity   : UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
I Unity   : UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
I Unity   : UnityEngine.EventSystems.StandaloneInputModule:Process()
I Unity   : 
E Unity   : Exception: No such proxy method: GOPHNOOANPB.HasManagedCallback()
E Unity   : 
E Unity   : 
E Unity   : UnityEngine.AndroidJavaException: java.lang.NullPointerException: Expected to unbox a 'boolean' primitive type but was returned null
E Unity   :   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 
E Unity   :   at UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 
E Unity   :   at DuckyShare.OnShareClick () [0x00000] in <00000000000000000000000000000000>:0 
yasirkula commented 1 year ago

Ah, looks like it yeah. Good catch 😃

dginovker commented 1 year ago

Solution is to add NativeShareNamespace.NSShareResultCallbackAndroid to the SkipClasses of the Beebyte ObfuscatorOptions.asset object