Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Android Target SDK API 23 (currently Google Sign In crashes) #30

Closed
trevoriancox opened this issue May 17, 2017 · 25 comments

Comments

@trevoriancox
Copy link

If you target API 23+ the app must prompt the user for GetAccounts permission:

https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/

We need to add a call to CheckSelfPermission.

Without that, I am finding that Authenticate() throws an exception, which I catch, but even so my app terminates with:

System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
  at System.Threading.Tasks.TaskCompletionSource`1[TResult].SetResult (TResult result) [0x0000c] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/TaskCompletionSource.cs:322
  at Android.Gms.Extensions.GoogleApiClientExtensions+<BuildAndConnectAsync>c__AnonStorey0.<>m__0 (Android.OS.Bundle hint) [0x00000] in <1db671c6182d42a7b22c48ed6b33a584>:0
  at Android.Gms.Common.Apis.GoogleApiClientConnectionCallbacksImpl.OnConnected (Android.OS.Bundle bundle) [0x0000d] in <1db671c6182d42a7b22c48ed6b33a584>:0
  at Android.Gms.Common.Apis.GoogleApiClient+IConnectionCallbacksInvoker.n_OnConnected_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_connectionHint) [0x00011] in <1db671c6182d42a7b22c48ed6b33a584>:0
  at at (wrapper dynamic-method) System.Object:a6b03050-593a-4ddc-9bdf-441125fda0bf (intptr,intptr,intptr)
@Clancey
Copy link
Owner

Clancey commented May 17, 2017

Is this using the https://github.com/Clancey/SimpleAuth/tree/master/src/SimpleAuth.Google.Droid
Or just the default?

@trevoriancox
Copy link
Author

I'm using Clancey.SimpleAuth.Google.Droid nuget v 1.0.1 and Clancey.SimpleAuth 1.0.35

It was working fine until I made some changes including explicitly setting uses-sdk/targetSdkVersion... still investigating where it broke.

Sorry for being premature; I no longer think that we need to prompt for GetAccounts permission.

@trevoriancox
Copy link
Author

It's crashing after OnActivityResult, so perhaps I should try your latest changes and new Native.OnActivityResult.

@Clancey
Copy link
Owner

Clancey commented May 17, 2017

The latest changes just simplify the API. No internal changes. Updating a device to marshmallow now.

@trevoriancox
Copy link
Author

I am getting the crash on a device with Android 6.0, in a project targeted to 7.0 (API 24).

@Clancey
Copy link
Owner

Clancey commented May 18, 2017

It is working on 7.1.1 Downgrading to 6.0 and trying again

@Clancey
Copy link
Owner

Clancey commented May 18, 2017

I was having some issues with the code in Android 6.0 as well. Just pushed a new version. This is working for me. Want to test it?

@Clancey Clancey closed this as completed May 18, 2017
@Clancey
Copy link
Owner

Clancey commented May 18, 2017

If you confirm this fixes it for you, I can push out a new nuget today.

@trevoriancox
Copy link
Author

No confirmation yet, sorry. I have just built SimpleAuth.Samples targeting API 25 (7.1) using Xamarin Studio 6.3 and Xamarin.Android 7.3.0.13. I am getting an "Update Google Play services" dialog which could be a clue.

@Clancey
Copy link
Owner

Clancey commented May 18, 2017

Yes, that is the issue. You will need to update the app. I have had that on all my devices with a fresh os install. The latest makes it so it can recover after that. You just need to log in again once the update is complet

@trevoriancox
Copy link
Author

Great! I need to test the "Update Google Play" scenario so pls let me know if you update nuget... in the meantime I am still trying to build from source.

@Clancey
Copy link
Owner

Clancey commented May 19, 2017

Nugets are live! Along with updated readme, with steps on how to implement.

@trevoriancox
Copy link
Author

It's still not working on a Nexus 5 with the latest update (6.0.1) and Google Play Services 9.8.77 (cannot be updated, not listed for this device in Google Play). Error is:

Method 'Android.Gms.Common.Zzc.IsGooglePlayServicesAvailable' not found.

@Clancey
Copy link
Owner

Clancey commented May 25, 2017

Are you on the latest?

https://github.com/Clancey/SimpleAuth/blob/master/src/SimpleAuth.Google.Droid/Google.cs#L193-L201

That code fixes that error you ran into. It happens due to google changing the obfuscated namespace underneath. Xamarin is working on a better fix to prevent this from happening.

Also if you build against Xamarin.GooglePlayServices.Auth 42.1021.1 you should be fine.

Would you mind updating or trying the from source?

@trevoriancox
Copy link
Author

Trying to build from source (current github master), but I'm getting "Error while trying to load the project: Unknown solution type" for SimpleAuth.Droid, SimpleAuth, and SimpleAuth.Google.Droid. I'm using Xamarin Studio on macOS.

@Clancey
Copy link
Owner

Clancey commented May 25, 2017

Sorry, I upgraded it to VS 4 Mac, I may downgrade it again. Do you have VS 4 mac installed?

@trevoriancox
Copy link
Author

We do not have VS 4 mac, and since we need to a custom command line build process, we're not in a hurry to make changes.

@Clancey
Copy link
Owner

Clancey commented May 26, 2017

It now builds on XS Again.

@trevoriancox
Copy link
Author

Thanks but I don't see the change... last commit was May 25, and it does not build for me in XS.

@Clancey
Copy link
Owner

Clancey commented May 27, 2017

like a noob, I forgot to push the update Try again

@trevoriancox
Copy link
Author

I'm still struggling with this. Now I see that your nugets are built with Xamarin.Android.Support.... 25.3.1 which are still in beta (you have to pick "Show pre-release packages" in Nuget). The current stable builds from Xamarin are 23.1.1.

@Clancey
Copy link
Owner

Clancey commented May 31, 2017 via email

@Clancey
Copy link
Owner

Clancey commented May 31, 2017

Actually, 25.3.1 is the latest: https://www.nuget.org/packages/Xamarin.Android.Support.v4/25.3.1 and it is not preview.

@trevoriancox
Copy link
Author

Yes, sorry! I may have been confused by a Xamarin Studio bug.

@Clancey
Copy link
Owner

Clancey commented Jun 2, 2017

I was also thinking about a way for you to avoid all this. If you remove the nuget for the Google Auth, just add the files to your project. And then it will build against any versions of the support lib you include! Google.cs and ActivityLifecycleManager.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants