From f37613f0627e6a2d06e14887fa999b455ac8855c Mon Sep 17 00:00:00 2001 From: Jonathan Dick Date: Thu, 20 Feb 2020 13:35:38 -0500 Subject: [PATCH] AndroidX (#1095) * Use AndroidX references for Android 10+ * Directly use AndroidX api's on API 29 + * Bump sample/device tests to api 29 * Migrate resource files in device tests / sample to androidx * Fix nuget references * Fix test with api 29 deprecations * Go STABLE!!! * Drop Android 6.0-7.1 as targets This is just the compile targets, it still runs all the way to 4.4 - and probably earlier Co-authored-by: Matthew Leibowitz --- .../DeviceTests.Android/DeviceTests.Android.csproj | 6 +++++- .../Properties/AndroidManifest.xml | 2 +- .../Resources/layout/Tabbar.axml | 2 +- .../Resources/layout/Toolbar.axml | 2 +- .../DeviceTests.Android/Tests/FileProvider_Tests.cs | 6 ++++++ .../Samples.Android/Properties/AndroidManifest.xml | 2 +- .../Samples.Android/Resources/layout/Tabbar.axml | 2 +- .../Samples.Android/Resources/layout/Toolbar.axml | 2 +- Samples/Samples.Android/Samples.Android.csproj | 7 ++++++- Xamarin.Essentials/Browser/Browser.android.cs | 6 ++++-- .../Permissions/Permissions.android.cs | 5 +++++ Xamarin.Essentials/Platform/Platform.android.cs | 1 - Xamarin.Essentials/Types/FileProvider.android.cs | 13 +++++++++---- .../WebAuthenticator/WebAuthenticator.android.cs | 4 ++++ Xamarin.Essentials/Xamarin.Essentials.csproj | 9 ++++++++- 15 files changed, 53 insertions(+), 16 deletions(-) diff --git a/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj b/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj index 91b90a1ca..3634e033b 100644 --- a/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj +++ b/DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj @@ -8,7 +8,7 @@ Library DeviceTests.Droid XamarinEssentialsDeviceTestsAndroid - v9.0 + v10.0 True Resources\Resource.designer.cs Resource @@ -57,6 +57,10 @@ + + + + diff --git a/DeviceTests/DeviceTests.Android/Properties/AndroidManifest.xml b/DeviceTests/DeviceTests.Android/Properties/AndroidManifest.xml index 9c53b14bb..ffaf3624a 100644 --- a/DeviceTests/DeviceTests.Android/Properties/AndroidManifest.xml +++ b/DeviceTests/DeviceTests.Android/Properties/AndroidManifest.xml @@ -1,6 +1,6 @@  - + diff --git a/DeviceTests/DeviceTests.Android/Resources/layout/Tabbar.axml b/DeviceTests/DeviceTests.Android/Resources/layout/Tabbar.axml index ad1f87d81..bc2faec48 100644 --- a/DeviceTests/DeviceTests.Android/Resources/layout/Tabbar.axml +++ b/DeviceTests/DeviceTests.Android/Resources/layout/Tabbar.axml @@ -1,5 +1,5 @@ - - + diff --git a/Samples/Samples.Android/Resources/layout/Tabbar.axml b/Samples/Samples.Android/Resources/layout/Tabbar.axml index ad1f87d81..bc2faec48 100644 --- a/Samples/Samples.Android/Resources/layout/Tabbar.axml +++ b/Samples/Samples.Android/Resources/layout/Tabbar.axml @@ -1,5 +1,5 @@ -Properties\AndroidManifest.xml Resources Assets - v9.0 + v10.0 true true Xamarin.Android.Net.AndroidClientHandler @@ -58,6 +58,7 @@ + @@ -67,6 +68,10 @@ + + + + diff --git a/Xamarin.Essentials/Browser/Browser.android.cs b/Xamarin.Essentials/Browser/Browser.android.cs index b3e682c9b..1d36cc927 100644 --- a/Xamarin.Essentials/Browser/Browser.android.cs +++ b/Xamarin.Essentials/Browser/Browser.android.cs @@ -1,9 +1,11 @@ using System; using System.Threading.Tasks; - using Android.Content; +#if __ANDROID_29__ +using AndroidX.Browser.CustomTabs; +#else using Android.Support.CustomTabs; - +#endif using AndroidUri = Android.Net.Uri; namespace Xamarin.Essentials diff --git a/Xamarin.Essentials/Permissions/Permissions.android.cs b/Xamarin.Essentials/Permissions/Permissions.android.cs index 92676480e..59fbb843d 100644 --- a/Xamarin.Essentials/Permissions/Permissions.android.cs +++ b/Xamarin.Essentials/Permissions/Permissions.android.cs @@ -5,8 +5,13 @@ using Android; using Android.Content.PM; using Android.OS; +#if __ANDROID_29__ +using AndroidX.Core.App; +using AndroidX.Core.Content; +#else using Android.Support.V4.App; using Android.Support.V4.Content; +#endif namespace Xamarin.Essentials { diff --git a/Xamarin.Essentials/Platform/Platform.android.cs b/Xamarin.Essentials/Platform/Platform.android.cs index 2f6b8dd9d..e0e53fcbe 100644 --- a/Xamarin.Essentials/Platform/Platform.android.cs +++ b/Xamarin.Essentials/Platform/Platform.android.cs @@ -11,7 +11,6 @@ using Android.Net; using Android.Net.Wifi; using Android.OS; -using Android.Support.V4.Content; using AndroidUri = Android.Net.Uri; namespace Xamarin.Essentials diff --git a/Xamarin.Essentials/Types/FileProvider.android.cs b/Xamarin.Essentials/Types/FileProvider.android.cs index ea621e288..90fc0aa46 100644 --- a/Xamarin.Essentials/Types/FileProvider.android.cs +++ b/Xamarin.Essentials/Types/FileProvider.android.cs @@ -4,6 +4,11 @@ using Android.Content; using Android.OS; using AndroidEnvironment = Android.OS.Environment; +#if __ANDROID_29__ +using ContentFileProvider = AndroidX.Core.Content.FileProvider; +#else +using ContentFileProvider = Android.Support.V4.Content.FileProvider; +#endif namespace Xamarin.Essentials { @@ -13,9 +18,9 @@ namespace Xamarin.Essentials Exported = false, GrantUriPermissions = true)] [MetaData( - "android.support.FILE_PROVIDER_PATHS", + "android.support.FILE_PROVIDER_PATHS", // IMPORTANT: This string doesn't change with AndroidX Resource = "@xml/xamarin_essentials_fileprovider_file_paths")] - public class FileProvider : global::Android.Support.V4.Content.FileProvider + public class FileProvider : ContentFileProvider { internal static bool AlwaysFailExternalMediaAccess { get; set; } = false; @@ -89,9 +94,9 @@ internal static bool IsFileInPublicLocation(string filename) #if __ANDROID_29__ Platform.AppContext.GetExternalFilesDir(null).CanonicalPath, #else - #pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable CS0618 // Type or member is obsolete AndroidEnvironment.ExternalStorageDirectory.CanonicalPath, - #pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0618 // Type or member is obsolete #endif Platform.AppContext.ExternalCacheDir.CanonicalPath }; diff --git a/Xamarin.Essentials/WebAuthenticator/WebAuthenticator.android.cs b/Xamarin.Essentials/WebAuthenticator/WebAuthenticator.android.cs index b78b97846..1f2f7afdb 100644 --- a/Xamarin.Essentials/WebAuthenticator/WebAuthenticator.android.cs +++ b/Xamarin.Essentials/WebAuthenticator/WebAuthenticator.android.cs @@ -1,7 +1,11 @@ using System; using System.Threading.Tasks; using Android.Content; +#if __ANDROID_29__ +using AndroidX.Browser.CustomTabs; +#else using Android.Support.CustomTabs; +#endif namespace Xamarin.Essentials { diff --git a/Xamarin.Essentials/Xamarin.Essentials.csproj b/Xamarin.Essentials/Xamarin.Essentials.csproj index 9fcc1b348..0c9335ab5 100644 --- a/Xamarin.Essentials/Xamarin.Essentials.csproj +++ b/Xamarin.Essentials/Xamarin.Essentials.csproj @@ -1,6 +1,6 @@  - netstandard1.0;netstandard2.0;Xamarin.iOS10;Xamarin.TVOS10;Xamarin.WatchOS10;MonoAndroid60;MonoAndroid70;MonoAndroid71;MonoAndroid80;MonoAndroid81;MonoAndroid90;MonoAndroid10.0;tizen40; + netstandard1.0;netstandard2.0;Xamarin.iOS10;Xamarin.TVOS10;Xamarin.WatchOS10;MonoAndroid80;MonoAndroid81;MonoAndroid90;MonoAndroid10.0;tizen40; $(TargetFrameworks);uap10.0.16299; Xamarin.Essentials Xamarin.Essentials @@ -76,11 +76,18 @@ + + + + + + +