Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2087 from xamarin/target-monoandroid13
Browse files Browse the repository at this point in the history
Target MonoAndroid13.0
  • Loading branch information
jfversluis committed May 2, 2023
2 parents 48ebfcf + 5fb5402 commit d1d3b00
Show file tree
Hide file tree
Showing 26 changed files with 238 additions and 81 deletions.
9 changes: 5 additions & 4 deletions DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<RootNamespace>DeviceTests.Droid</RootNamespace>
<AssemblyName>XamarinEssentialsDeviceTestsAndroid</AssemblyName>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v13.0</TargetFrameworkVersion>
<AndroidApplication>True</AndroidApplication>
<AndroidUseIntermediateDesignerFile>true</AndroidUseIntermediateDesignerFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
Expand All @@ -19,6 +19,7 @@
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
<AndroidEnableMultiDex>true</AndroidEnableMultiDex>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -57,13 +58,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
<PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.23212.1" />
<PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.2.0.1" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0.6" />
<PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0.15" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Xamarin.Essentials\Xamarin.Essentials.csproj">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0.1.0" package="com.xamarin.essentials.devicetests" android:installLocation="auto">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="29" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="33" />
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Expand Down Expand Up @@ -41,5 +42,5 @@
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/MainTheme"></application>
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/MainTheme"></application>
</manifest>
7 changes: 4 additions & 3 deletions DeviceTests/DeviceTests.Shared/DeviceTests.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
<PropertyGroup>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">Xamarin.iOS10;MonoAndroid10.0;uap10.0.16299</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">Xamarin.iOS10;MonoAndroid10.0;</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">Xamarin.iOS10;MonoAndroid13.0;uap10.0.16299</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">Xamarin.iOS10;MonoAndroid13.0;</TargetFrameworks>
<AssemblyName>XamarinEssentialsDeviceTestsShared</AssemblyName>
<RootNamespace>DeviceTests.Shared</RootNamespace>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
Expand All @@ -13,6 +13,7 @@
<DefineConstants>$(DefineConstants);</DefineConstants>
<MDocDocumentationDirectory>$(MSBuildThisFileDirectory)..\docs\en</MDocDocumentationDirectory>
<Configurations>Debug;Release</Configurations>
<BuildWithMSBuildOnMono>true</BuildWithMSBuildOnMono>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugType>full</DebugType>
Expand All @@ -23,7 +24,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
<PackageReference Include="UnitTests.HeadlessRunner" Version="2.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion DeviceTests/DeviceTests.UWP/DeviceTests.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UnitTests.HeadlessRunner" Version="2.0.0" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.9" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
Expand Down
2 changes: 1 addition & 1 deletion DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
<PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.23212.1" />
Expand Down
112 changes: 101 additions & 11 deletions DeviceTests/build.cake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#addin nuget:?package=Cake.AppleSimulator&version=0.2.0
#addin nuget:?package=Cake.Android.Adb&version=3.2.0
#addin nuget:?package=Cake.Android.AvdManager&version=2.2.0
#addin nuget:?package=Cake.Android.SdkManager&version=3.0.2
#addin nuget:?package=Cake.FileHelpers&version=3.3.0
#addin nuget:?package=Cake.Boots&version=1.1.0.712-preview2

var TARGET = Argument("target", "Default");

Expand Down Expand Up @@ -33,15 +35,24 @@ var TCP_LISTEN_HOST = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName())
var OUTPUT_PATH = MakeAbsolute((DirectoryPath)"../output/");
var ANDROID_HOME = EnvironmentVariable("ANDROID_HOME");
// set up env
var ANDROID_SDK_ROOT = GetAndroidSDKPath();
var ANDROID_HOME = ANDROID_SDK_ROOT;
System.Environment.SetEnvironmentVariable("PATH",
$"{ANDROID_HOME}/tools/bin" + System.IO.Path.PathSeparator +
$"{ANDROID_HOME}/platform-tools" + System.IO.Path.PathSeparator +
$"{ANDROID_HOME}/emulator" + System.IO.Path.PathSeparator +
EnvironmentVariable("PATH"));
SetEnvironmentVariable("PATH", $"{ANDROID_SDK_ROOT}/tools/bin", prepend: true);
SetEnvironmentVariable("PATH", $"{ANDROID_SDK_ROOT}/cmdline-tools/5.0/bin", prepend: true);
SetEnvironmentVariable("PATH", $"{ANDROID_SDK_ROOT}/cmdline-tools/7.0/bin", prepend: true);
SetEnvironmentVariable("PATH", $"{ANDROID_SDK_ROOT}/cmdline-tools/latest/bin", prepend: true);
var RESTORE_CONFIG = MakeAbsolute((FilePath)"../devopsnuget.config").FullPath;
SetEnvironmentVariable("PATH", $"{ANDROID_SDK_ROOT}/platform-tools", prepend: true);
SetEnvironmentVariable("PATH", $"{ANDROID_SDK_ROOT}/emulator", prepend: true);
Information("Android SDK Root: {0}", ANDROID_SDK_ROOT);
string androidSdks = EnvironmentVariable("ANDROID_API_SDKS", "platform-tools,platforms;android-26,platforms;android-27,platforms;android-28,platforms;android-29,build-tools;29.0.3,platforms;android-30,build-tools;30.0.2,platforms;android-32,build-tools;32.0.0,platforms;android-33,build-tools;33.0.2");
Information("ANDROID_API_SDKS: {0}", androidSdks);
string[] androidSdkManagerInstalls = androidSdks.Split(',');
// utils
Expand Down Expand Up @@ -88,6 +99,28 @@ Task DownloadTcpTextAsync(int port, FilePath filename, Action waitAction = null)
});
}
void SetEnvironmentVariable(string name, string value, bool prepend = false)
{
var target = EnvironmentVariableTarget.Process;
if (prepend)
value = value + System.IO.Path.PathSeparator + EnvironmentVariable(name);
Environment.SetEnvironmentVariable(name, value, target);
Information("Setting environment variable: {0} = '{1}'", name, value);
}
string GetAndroidSDKPath()
{
var ANDROID_SDK_ROOT = Argument("android", EnvironmentVariable("ANDROID_SDK_ROOT") ?? EnvironmentVariable("ANDROID_HOME"));
if (string.IsNullOrEmpty(ANDROID_SDK_ROOT)) {
throw new Exception("Environment variable 'ANDROID_SDK_ROOT' or 'ANDROID_HOME' must be set to the Android SDK root.");
}

return ANDROID_SDK_ROOT;
}

// iOS tasks

Expand All @@ -100,7 +133,6 @@ Task("build-ios")
c.Properties["Platform"] = new List<string> { "iPhoneSimulator" };
c.Properties["BuildIpa"] = new List<string> { "true" };
c.Properties["ContinuousIntegrationBuild"] = new List<string> { "false" };
c.Properties["RestoreConfigFile"] = new List<string> { RESTORE_CONFIG };
c.Targets.Clear();
c.Targets.Add("Rebuild");
c.BinaryLogger = new MSBuildBinaryLogSettings {
Expand Down Expand Up @@ -138,14 +170,71 @@ Task("test-ios-emu")

// Android tasks

Task("boots")
.Does(async () =>
{
await Boots (Product.XamarinAndroid, ReleaseChannel.Stable);
});

Task("provision-androidsdk")
.Description("Install Xamarin.Android SDK")
.Does(() =>
{
Information ("ANDROID_HOME: {0}", ANDROID_HOME);
if(androidSdkManagerInstalls.Length > 0)
{
Information("Updating Android SDKs");
var androidSdkSettings = new AndroidSdkManagerToolSettings {
SkipVersionCheck = true
};
if(!String.IsNullOrWhiteSpace(ANDROID_HOME))
androidSdkSettings.SdkRoot = ANDROID_HOME;
try{
AcceptLicenses (androidSdkSettings);
}
catch(Exception exc)
{
Information("AcceptLicenses: {0}", exc);
}
try{
AndroidSdkManagerUpdateAll (androidSdkSettings);
}
catch(Exception exc)
{
Information("AndroidSdkManagerUpdateAll: {0}", exc);
}
try{
AcceptLicenses (androidSdkSettings);
}
catch(Exception exc)
{
Information("AcceptLicenses: {0}", exc);
}
try{
AndroidSdkManagerInstall (androidSdkManagerInstalls, androidSdkSettings);
}
catch(Exception exc)
{
Information("AndroidSdkManagerInstall: {0}", exc);
}
}
});

Task("build-android")
.IsDependentOn("provision-androidsdk")
.IsDependentOn("boots")
.Does(() =>
{
MSBuild(ANDROID_PROJ, c => {
c.Configuration = "Debug"; // needs to be debug so unit tests get discovered
c.Restore = true;
c.Properties["ContinuousIntegrationBuild"] = new List<string> { "false" };
c.Properties["RestoreConfigFile"] = new List<string> { RESTORE_CONFIG };
c.Targets.Clear();
c.Targets.Add("Rebuild");
c.Targets.Add("SignAndroidPackage");
Expand Down Expand Up @@ -188,12 +277,14 @@ Task("test-android-emu")
}
Information("Waited {0} seconds for the emulator to boot up.", waited);
var targetArch = ANDROID_EMU_TARGET.Split(';').Last();
// Run the tests
var resultCode = StartProcess("xharness", "android test " +
$"--app=\"{ANDROID_APK_PATH}\" " +
$"--package-name=\"{ANDROID_PKG_NAME}\" " +
$"--instrumentation=\"{ANDROID_INSTRUMENTATION_NAME}\" " +
$"--device-arch=\"x86\" " +
$"--device-arch=\"{targetArch}\" " +
$"--output-directory=\"{ANDROID_TEST_RESULTS_PATH}\" " +
$"--verbosity=\"Debug\" ");
Expand Down Expand Up @@ -225,7 +316,6 @@ Task("build-uwp")
c.Properties["AppxBundlePlatforms"] = new List<string> { "x86" };
c.Properties["AppxBundle"] = new List<string> { "Always" };
c.Properties["AppxPackageSigningEnabled"] = new List<string> { "true" };
c.Properties["RestoreConfigFile"] = new List<string> { RESTORE_CONFIG };
c.Targets.Clear();
c.Targets.Add("Rebuild");
c.BinaryLogger = new MSBuildBinaryLogSettings {
Expand Down
6 changes: 3 additions & 3 deletions Samples/Samples.Android/Samples.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v13.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
Expand Down Expand Up @@ -58,8 +58,8 @@
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="4.5.3" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2578" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Samples/Samples.Mac/Samples.Mac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="4.5.3" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2578" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Samples/Samples.UWP/Samples.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="4.5.3" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2578" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.9" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Samples/Samples.iOS/Samples.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="4.5.3" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2578" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Samples/Samples/Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.3" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="4.5.3" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2578" />
<PackageReference Include="Xamarin.Forms.Visual.Material" Version="5.0.0.2578" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>

Expand Down
4 changes: 4 additions & 0 deletions Xamarin.Essentials/AppInfo/AppInfo.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ static string PlatformGetVersionString()
{
var pm = Platform.AppContext.PackageManager;
var packageName = Platform.AppContext.PackageName;
#pragma warning disable CS0618 // Type or member is obsolete
using (var info = pm.GetPackageInfo(packageName, PackageInfoFlags.MetaData))
#pragma warning restore CS0618 // Type or member is obsolete
{
return info.VersionName;
}
Expand All @@ -36,7 +38,9 @@ static string PlatformGetBuild()
{
var pm = Platform.AppContext.PackageManager;
var packageName = Platform.AppContext.PackageName;
#pragma warning disable CS0618 // Type or member is obsolete
using (var info = pm.GetPackageInfo(packageName, PackageInfoFlags.MetaData))
#pragma warning restore CS0618 // Type or member is obsolete
{
#if __ANDROID_28__
return PackageInfoCompat.GetLongVersionCode(info).ToString(CultureInfo.InvariantCulture);
Expand Down
4 changes: 3 additions & 1 deletion Xamarin.Essentials/Connectivity/Connectivity.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ static NetworkAccess PlatformNetworkAccess

if (Platform.HasApiLevel(BuildVersionCodes.Lollipop))
{
#pragma warning disable CS0618 // Type or member is obsolete
var networks = manager.GetAllNetworks();
#pragma warning restore CS0618 // Type or member is obsolete

// some devices running 21 and 22 only use the older api.
if (networks.Length == 0 && (int)Build.VERSION.SdkInt < 23)
Expand Down Expand Up @@ -212,9 +214,9 @@ static IEnumerable<ConnectionProfile> PlatformConnectionProfiles
var manager = Platform.ConnectivityManager;
if (Platform.HasApiLevel(BuildVersionCodes.Lollipop))
{
#pragma warning disable CS0618 // Type or member is obsolete
foreach (var network in manager.GetAllNetworks())
{
#pragma warning disable CS0618 // Type or member is obsolete
NetworkInfo info = null;
try
{
Expand Down
2 changes: 2 additions & 0 deletions Xamarin.Essentials/DeviceDisplay/DeviceDisplay.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ static DisplayInfo GetMainDisplayInfo()
{
using var displayMetrics = new DisplayMetrics();
var display = GetDefaultDisplay();
#pragma warning disable CS0618 // Type or member is obsolete
display?.GetRealMetrics(displayMetrics);
#pragma warning restore CS0618 // Type or member is obsolete

return new DisplayInfo(
width: displayMetrics?.WidthPixels ?? 0,
Expand Down

0 comments on commit d1d3b00

Please sign in to comment.