elringus / unity-google-drive

Google Drive SDK for Unity game engine
https://forum.unity.com/threads/515360
MIT License
404 stars 64 forks source link

ActivityNotFoundException (com.elringus.unitygoogledriveandroid.AuthorizationActivity) for Android API >= 30 #122

Closed cdecron closed 1 year ago

cdecron commented 1 year ago

Hello, and first of all thank you for this plugin.

My Android app throws an exception when the authorization screen should appear. This exception happens only when targetting Android API >= 30. It works perfectly when targeting API 29 and below.

Here is the complete stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xyz.xyz/com.elringus.unitygoogledriveandroid.AuthorizationActivity}: android.content.ActivityNotFoundException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7924)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
    Caused by: android.content.ActivityNotFoundException
    at net.openid.appauth.AuthorizationService.prepareAuthorizationRequestIntent(AuthorizationService.java:372)
    at net.openid.appauth.AuthorizationService.getAuthorizationRequestIntent(AuthorizationService.java:267)
    at net.openid.appauth.AuthorizationService.getAuthorizationRequestIntent(AuthorizationService.java:296)
    at com.elringus.unitygoogledriveandroid.AuthorizationActivity.onCreate(AuthorizationActivity.java:50)
    at android.app.Activity.performCreate(Activity.java:8342)
    at android.app.Activity.performCreate(Activity.java:8321)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)

Is there a way to fix this? Thank you very much for your answer

elringus commented 1 year ago

Make sure to use latest versions of the auth libs.

DavidJH2 commented 1 year ago

I ran into this exact issue a while back. Sorry, I should have written up a StackOverflow answer for it.

The problem is that with API 30+ you need to give your app permission to "Query Chrome":

You do this by adding Query to a Custom Manifest: Query

If you don't give it this permission, when the API tries to query Chrome it can't find the activity

DavidJH2 commented 1 year ago

Make sure to use latest versions of the auth libs.

What and where are the 'auth libs'?

elringus commented 1 year ago

https://github.com/Elringus/UnityGoogleDrive/blob/master/Assets/UnityGoogleDrive/Editor/Dependencies.xml

elringus commented 1 year ago

Also google play services resolver grabs something, iirc.

DavidJH2 commented 1 year ago

Hello, and first of all thank you for this plugin.

My Android app throws an exception when the authorization screen should appear. This exception happens only when targetting Android API >= 30. It works perfectly when targeting API 29 and below.

Here is the complete stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xyz.xyz/com.elringus.unitygoogledriveandroid.AuthorizationActivity}: android.content.ActivityNotFoundException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
  at android.os.Handler.dispatchMessage(Handler.java:106)
  at android.os.Looper.loopOnce(Looper.java:201)
  at android.os.Looper.loop(Looper.java:288)
  at android.app.ActivityThread.main(ActivityThread.java:7924)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
  Caused by: android.content.ActivityNotFoundException
  at net.openid.appauth.AuthorizationService.prepareAuthorizationRequestIntent(AuthorizationService.java:372)
  at net.openid.appauth.AuthorizationService.getAuthorizationRequestIntent(AuthorizationService.java:267)
  at net.openid.appauth.AuthorizationService.getAuthorizationRequestIntent(AuthorizationService.java:296)
  at com.elringus.unitygoogledriveandroid.AuthorizationActivity.onCreate(AuthorizationActivity.java:50)
  at android.app.Activity.performCreate(Activity.java:8342)
  at android.app.Activity.performCreate(Activity.java:8321)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)

Is there a way to fix this? Thank you very much for your answer

Were you able to resolve this issue already?

DavidJH2 commented 1 year ago

I ran into this exact issue a while back. Sorry, I should have written up a StackOverflow answer for it.

The problem is that with API 30+ you need to give your app permission to "Query Chrome":

You do this by adding Query to a Custom Manifest: Query

If you don't give it this permission, when the API tries to query Chrome it can't find the activity

@Elringus, is this the proper way to resolve this issue?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 14 days with no activity. It will be automatically closed in 7 days.

cdecron commented 1 year ago

Hello, sorry for my late answer, and thank you for your answers.

Unfortunately, the solution given by @DavidJH2 doesn't work for me: adding the <queries> item in Manifest gives me the same exception.

@elringus, what are the latest version of the auth libs? I'm using 0.7.+ / 1.3.0, as shown in the file you provided

elringus commented 1 year ago

No idea, but definitely above the ones specified in the project.

cdecron commented 1 year ago

Indeed! I updated Android AppAuth version to 0.11.1, which seems to be the last one, but I still have the exception. However, this one slightly changed:

AndroidJavaException: java.lang.ClassNotFoundException: com.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener
java.lang.ClassNotFoundException: com.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
    at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:83)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
    Caused by: java.lang.ClassNotFoundException: com.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener
    ... 9 more
    at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 

Any thoughts on this...? Thank you

DavidJH2 commented 1 year ago

Indeed! I updated Android AppAuth version to 0.11.1, which seems to be the last one, but I still have the exception. However, this one slightly changed:

AndroidJavaException: java.lang.ClassNotFoundException: com.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener
java.lang.ClassNotFoundException: com.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener
  at java.lang.Class.classForName(Native Method)
  at java.lang.Class.forName(Class.java:454)
  at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
  at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
  at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:83)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loopOnce(Looper.java:201)
  at android.os.Looper.loop(Looper.java:288)
  at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
  Caused by: java.lang.ClassNotFoundException: com.elringus.unitygoogledriveandroid.AuthorizationActivity$OnAuthorizationResponseListener
  ... 9 more
  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 

Any thoughts on this...? Thank you

Did you delete your Library folder before rebuilding?

Also, are you targeting 33+

cdecron commented 1 year ago

Ok, so after a lot of tests, it seems that I have solved the problem and discovered some things:

I hope this is a bit clearer now!

cdecron commented 1 year ago

Unfortunately, my problem is still there because if I uncheck 'Development Build' in Build Settings (what I need to do to upload app on Play Store), even with AppAuth v0.11.1, Chrome installed and <queries> item included, the exception is thrown. And it's not related to Google API 'Test mode' because I switched to 'Production mode'... I'm stuck on this right now.

DavidJH2 commented 1 year ago

Unfortunately, my problem is still there because if I uncheck 'Development Build' in Build Settings (what I need to do to upload app on Play Store), even with AppAuth v0.11.1, Chrome installed and <queries> item included, the exception is thrown. And it's not related to Google API 'Test mode' because I switched to 'Production mode'... I'm stuck on this right now.

I have it working on Android with a published app so I know it's possible.

In that vain, here is my setup:

  1. I HAVE to use Unity 2023.1.17 in order to avoid a weird crash ONLY in Google Play Console testing ONLY on the Pixel 2
  2. I Had to recreate the Custom manifest file by unchecking the box, deleting it and rechecking the box and then re-adding the Queries option (not sure if it's still needed at this point)
  3. I have Chrome installed
  4. Works with Both Dev builds AND Release (I can publish it on the Google Play Store which was a whole thing in itself)
  5. Had to set Stripping level to minimal (Unity 2023.17 was breaking on build at Anything higher

Hope I didn't miss anything. It took quite a bit of trial and error to get it building so I'm not sure an exact procedure to get it working, but we should be able to get yours building at least for Android and hopefully it will either just work on iOS or you can carry it on to it.

DavidJH2 commented 1 year ago

Unfortunately, my problem is still there because if I uncheck 'Development Build' in Build Settings (what I need to do to upload app on Play Store), even with AppAuth v0.11.1, Chrome installed and <queries> item included, the exception is thrown. And it's not related to Google API 'Test mode' because I switched to 'Production mode'... I'm stuck on this right now.

If you like, I could help you to troubleshoot this. It was a bit convoluted to get it working on the Published app, but we should be able to resolve it partly by looking at the differences between your project and mine. I had something like 4 separate issues I had to resolve to get it working, one being I HAD to use 2023.1.17.

Let me know if you want me to help you work through it

cdecron commented 1 year ago

Thank you a lot! First of all, i'm updating to Unity 2023.1.17 because I was using an older version. For now I have some errors to fix, but hopefully it will work after the update.

I keep you updated Thank you again for your help

cdecron commented 1 year ago

It works!!

Thank you very much for your insights. I made it work with Unity version 2023.1.17, and with minimal Stripping level.

I did a few tests (Android only), and with AppAuth version 0.11.1, you don't need to have Chrome anymore installed (thus the <queries> item is not needed). Apparently, the opened web page is opened with Firefox on my phone, but I guess it's opening with the default browser.

However, I still have an exception thrown (but it's less annoying), when I close the browser page without choosing the desired Google Account.

Ambiguous overloads found for onAuthorizationResponse with given parameters
UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.IntPtr javaArgs) [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) [0x00000] in <00000000000000000000000000000000>:0 
Error Unity Rethrow as TargetInvocationException: UnityGoogleDrive.AndroidAccessTokenProvider+OnAuthorizationResponseListener.onAuthorizationResponse(System.Boolean,null,System.String,System.String,System.String)
Error Unity   at UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 
Error Unity   at UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.IntPtr javaArgs) [0x00000] in <00000000000

Maybe you managed to avoid this? Thank you again

DavidJH2 commented 1 year ago

It works!!

Thank you very much for your insights. I made it work with Unity version 2023.1.17, and with minimal Stripping level.

I did a few tests (Android only), and with AppAuth version 0.11.1, you don't need to have Chrome anymore installed (thus the <queries> item is not needed). Apparently, the opened web page is opened with Firefox on my phone, but I guess it's opening with the default browser.

However, I still have an exception thrown (but it's less annoying), when I close the browser page without choosing the desired Google Account.

Ambiguous overloads found for onAuthorizationResponse with given parameters
UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.IntPtr javaArgs) [0x00000] in <00000000000000000000000000000000>:0 
at UnityEngine._AndroidJNIHelper.InvokeJavaProxyMethod (UnityEngine.AndroidJavaProxy proxy, System.IntPtr jmethodName, System.IntPtr jargs) [0x00000] in <00000000000000000000000000000000>:0 
Error Unity Rethrow as TargetInvocationException: UnityGoogleDrive.AndroidAccessTokenProvider+OnAuthorizationResponseListener.onAuthorizationResponse(System.Boolean,null,System.String,System.String,System.String)
Error Unity   at UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 
Error Unity   at UnityEngine.AndroidJavaProxy.Invoke (System.String methodName, System.IntPtr javaArgs) [0x00000] in <00000000000

Maybe you managed to avoid this? Thank you again

Awesome, good to hear!

I'm not sure about this last exception. I get it as well. I didn't know about it until now since I haven't reached the point of hard-core testing yet. I agree, I'm not super concerned about it (yet!) since it seems very sensible. I'll let you know what I find out when I get there unless you find the answer first. Maybe not too far off. We should create a new issue if it is not just our failiar to error check.

Good work!!

cdecron commented 1 year ago

Hello, I'll keep you updated if I find a solution. Also I'm going to create a new thread.

By the way, do you test your app on Desktop, with Unity Editor, before testing it on mobile? That was I used to do, but with new recent updates I made, now I can't auth through Google (cf. this thread). Maybe you have some thoughts about this!

Thank you :)

DavidJH2 commented 1 year ago

Hello, I'll keep you updated if I find a solution. Also I'm going to create a new thread.

By the way, do you test your app on Desktop, with Unity Editor, before testing it on mobile? That was I used to do, but with new recent updates I made, now I can't auth through Google (cf. this thread). Maybe you have some thoughts about this!

Thank you :)

Yes, I do test on Desktop with the Unity Editor. I've yet to have a problem with it. I'll continue on the other thread