From 1f63cfd7f97f2f468dbc300a215ee105d143c10f Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 7 Nov 2023 22:25:17 +0000 Subject: [PATCH 01/14] Initial Commit --- .../Properties/Resources.Designer.cs | 13 ++++++-- .../Properties/Resources.resx | 6 +++- .../Utilities/MonoAndroidHelper.cs | 30 ++++++++++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index 525498f9096..7ccde18d31b 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -1457,9 +1457,9 @@ public static string XA5207 { /// /// Looks up a localized string similar to Tools > Open Android SDK Manager.... /// - public static string XA5207_SDK_Manager_macOS { + public static string XA5207_SDK_Manager_VSCode { get { - return ResourceManager.GetString("XA5207_SDK_Manager_macOS", resourceCulture); + return ResourceManager.GetString("XA5207_SDK_Manager_VSCode", resourceCulture); } } @@ -1472,6 +1472,15 @@ public static string XA5207_SDK_Manager_Windows { } } + /// + /// Looks up a localized string similar to Tools > Open Android SDK Manager.... + /// + public static string XA5207_SDK_Manager_CLI { + get { + return ResourceManager.GetString("XA5207_SDK_Manager_CLI", resourceCulture); + } + } + /// /// Looks up a localized string similar to Embedded Wear app package name differs from handheld app package name ({0} != {1}).. /// diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 5eeed4389f3..0cd522e3a71 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -873,7 +873,7 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {1} - The expected path of the android.jar file {2} - The menu location in Visual Studio that can be used to launch the Android SDK Manager - + Tools > Open Android SDK Manager... This string is the location of a menu command in Visual Studio for Mac. @@ -881,6 +881,10 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins Tools > Android > Android SDK Manager... This string is the location of a menu command in Visual Studio. + + Tools > Android > Android SDK Manager... + This string is the location of a menu command in Visual Studio. + Embedded Wear app package name differs from handheld app package name ({0} != {1}). The following are literal names and should not be translated: Wear diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index d72b347d5e9..b61a008e521 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -488,7 +488,35 @@ public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platfor if (platformPath == null) { if (!designTimeBuild) { var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform); - var sdkManagerMenuPath = OS.IsWindows ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_macOS; + var sdkManagerMenuPath = OS.IsWindows ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_VSCode; + log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath); + } + return null; + } + return Path.Combine (platformPath, "android.jar"); + } + + internal enum IDE { + CLI, + VisualStudio, + VSCode, + } + + public static string TryGetAndroidJarPathForIDE (TaskLoggingHelper log, string platform, bool designTimeBuild = false, IDE ide = IDE.CLI) + { + var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions); + if (platformPath == null) { + if (!designTimeBuild) { + var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform); + var sdkManagerMenuPath = Properties.Resources.XA5207_SDK_Manager_CLI; + switch (ide) { + case IDE.VSCode: + sdkManagerMenuPath = Properties.Resources.XA5207_SDK_Manager_VSCode; + break; + case IDE.VisualStudio: + sdkManagerMenuPath =Properties.Resources.XA5207_SDK_Manager_Windows + break; + } log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath); } return null; From 9dba5ec89b49e1c875fccdd53a3ae1c4e4234c82 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 9 Nov 2023 15:37:38 +0000 Subject: [PATCH 02/14] Update error text --- .../Properties/Resources.Designer.cs | 9 ------ .../Properties/Resources.resx | 16 ++++------ .../Tasks/GetJavaPlatformJar.cs | 4 ++- .../Utilities/MonoAndroidHelper.cs | 32 ++----------------- 4 files changed, 11 insertions(+), 50 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index 7ccde18d31b..3a072ef0e35 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -1454,15 +1454,6 @@ public static string XA5207 { } } - /// - /// Looks up a localized string similar to Tools > Open Android SDK Manager.... - /// - public static string XA5207_SDK_Manager_VSCode { - get { - return ResourceManager.GetString("XA5207_SDK_Manager_VSCode", resourceCulture); - } - } - /// /// Looks up a localized string similar to Tools > Android > Android SDK Manager.... /// diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 0cd522e3a71..4daebb9b10a 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -867,23 +867,19 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The missing tool name - Could not find android.jar for API level {0}. This means the Android SDK platform for API level {0} is not installed. Either install it in the Android SDK Manager ({2}), or change the Xamarin.Android project to target an API version that is installed. ({1} missing.) + Could not find android.jar for API level {0}. This means the Android SDK platform for API level {0} is not installed. {2} ({1} missing.) The following are literal names and should not be translated: android.jar {0} - The API level name {1} - The expected path of the android.jar file -{2} - The menu location in Visual Studio that can be used to launch the Android SDK Manager - - - Tools > Open Android SDK Manager... - This string is the location of a menu command in Visual Studio for Mac. +{2} - The instructions to install the missing component - Tools > Android > Android SDK Manager... - This string is the location of a menu command in Visual Studio. + Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the Xamarin.Android project to target an API version that is installed. + This string is the instrucitons to install the component - Tools > Android > Android SDK Manager... - This string is the location of a menu command in Visual Studio. + You can install the missing APU level by running `dotnet build -t:InstallAndroidDependencies -f net8.0-android`, or change the Xamarin.Android project to target an API version that is installed. + This string is the instrucitons to install the component Embedded Wear app package name differs from handheld app package name ({0} != {1}). diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs index 171913f78e3..7a0808b886d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs @@ -25,6 +25,8 @@ public class GetJavaPlatformJar : AndroidTask public bool DesignTimeBuild { get; set; } + public bool BuildingInsideVisualStudio { get; set; } + public string SupportedOSPlatformVersion { get; set; } [Output] @@ -95,7 +97,7 @@ public override bool RunTask () } platform = GetTargetSdkVersion (platform, target_sdk); - JavaPlatformJarPath = MonoAndroidHelper.TryGetAndroidJarPath (Log, platform, designTimeBuild: DesignTimeBuild); + JavaPlatformJarPath = MonoAndroidHelper.TryGetAndroidJarPath (Log, platform, designTimeBuild: DesignTimeBuild, buildingInsideVisualStudio: BuildingInsideVisualStudio); TargetSdkVersion = MonoAndroidHelper.SupportedVersions.GetApiLevelFromId (platform).ToString (); if (JavaPlatformJarPath == null) return !Log.HasLoggedErrors; diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index b61a008e521..3c1212f1a0c 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -482,41 +482,13 @@ public static IEnumerable Executables (string executable) yield return executable; } - public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform, bool designTimeBuild = false) + public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform, bool designTimeBuild = false, bool buildingInsideVisualStudio = false) { var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions); if (platformPath == null) { if (!designTimeBuild) { var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform); - var sdkManagerMenuPath = OS.IsWindows ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_VSCode; - log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath); - } - return null; - } - return Path.Combine (platformPath, "android.jar"); - } - - internal enum IDE { - CLI, - VisualStudio, - VSCode, - } - - public static string TryGetAndroidJarPathForIDE (TaskLoggingHelper log, string platform, bool designTimeBuild = false, IDE ide = IDE.CLI) - { - var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions); - if (platformPath == null) { - if (!designTimeBuild) { - var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform); - var sdkManagerMenuPath = Properties.Resources.XA5207_SDK_Manager_CLI; - switch (ide) { - case IDE.VSCode: - sdkManagerMenuPath = Properties.Resources.XA5207_SDK_Manager_VSCode; - break; - case IDE.VisualStudio: - sdkManagerMenuPath =Properties.Resources.XA5207_SDK_Manager_Windows - break; - } + var sdkManagerMenuPath = buildingInsideVisualStudio ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_CLI; log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath); } return null; From 86fe6e5e07b177a340e4897ec87a431f85517fbb Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 10 Nov 2023 13:41:57 +0000 Subject: [PATCH 03/14] Add missing task argument --- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets index ff86b19b484..ac0d22d81d6 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets @@ -101,6 +101,7 @@ projects. AndroidSdkPlatform="$(_AndroidApiLevel)" AndroidManifest="$(_AndroidManifestAbs)" DesignTimeBuild="$(DesignTimeBuild)" + BuildingInsideVisualStudio="$(BuildingInsideVisualStudio)" SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)" > From 11b2871b49f65446df9727f65bb94ade7f9f555c Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 23 Nov 2023 11:23:07 +0000 Subject: [PATCH 04/14] fix up error message to be helpful --- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 6 ++++-- .../Tasks/GetJavaPlatformJar.cs | 8 +++++++- .../Utilities/MonoAndroidHelper.cs | 4 ++-- .../Xamarin.Android.Tooling.targets | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 4daebb9b10a..90c61a763af 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -878,8 +878,10 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins This string is the instrucitons to install the component - You can install the missing APU level by running `dotnet build -t:InstallAndroidDependencies -f net8.0-android`, or change the Xamarin.Android project to target an API version that is installed. - This string is the instrucitons to install the component + You can install the missing API level by running `dotnet build -t:InstallAndroidDependencies -f {0} -p:AndroidSdkDirectory={1}`, or change the Xamarin.Android project to target an API version that is installed. + This string is the instrucitons to install the component +{0} - The TargetFramework the app is targeting. +{1} - The current AndroidSdkDirectory path. Embedded Wear app package name differs from handheld app package name ({0} != {1}). diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs index 7a0808b886d..cb9b22f88da 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetJavaPlatformJar.cs @@ -29,6 +29,10 @@ public class GetJavaPlatformJar : AndroidTask public string SupportedOSPlatformVersion { get; set; } + public string TargetFramework { get; set; } + + public string AndroidSdkDirectory { get; set; } + [Output] public string JavaPlatformJarPath { get; set; } @@ -97,7 +101,9 @@ public override bool RunTask () } platform = GetTargetSdkVersion (platform, target_sdk); - JavaPlatformJarPath = MonoAndroidHelper.TryGetAndroidJarPath (Log, platform, designTimeBuild: DesignTimeBuild, buildingInsideVisualStudio: BuildingInsideVisualStudio); + JavaPlatformJarPath = MonoAndroidHelper.TryGetAndroidJarPath (Log, platform, + designTimeBuild: DesignTimeBuild, buildingInsideVisualStudio: BuildingInsideVisualStudio, + targetFramework: TargetFramework, androidSdkDirectory: AndroidSdkDirectory); TargetSdkVersion = MonoAndroidHelper.SupportedVersions.GetApiLevelFromId (platform).ToString (); if (JavaPlatformJarPath == null) return !Log.HasLoggedErrors; diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index 3c1212f1a0c..4efceda5141 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -482,14 +482,14 @@ public static IEnumerable Executables (string executable) yield return executable; } - public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform, bool designTimeBuild = false, bool buildingInsideVisualStudio = false) + public static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform, bool designTimeBuild = false, bool buildingInsideVisualStudio = false, string targetFramework = "", string androidSdkDirectory = "") { var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions); if (platformPath == null) { if (!designTimeBuild) { var expectedPath = MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform); var sdkManagerMenuPath = buildingInsideVisualStudio ? Properties.Resources.XA5207_SDK_Manager_Windows : Properties.Resources.XA5207_SDK_Manager_CLI; - log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), sdkManagerMenuPath); + log.LogCodedError ("XA5207", Properties.Resources.XA5207, platform, Path.Combine (expectedPath, "android.jar"), string.Format (sdkManagerMenuPath, targetFramework, androidSdkDirectory)); } return null; } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets index ac0d22d81d6..a0c0abd4262 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Tooling.targets @@ -99,10 +99,12 @@ projects. From 2cce4248a1cc55233d807874eb68821e62b4bc53 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 23 Nov 2023 14:22:50 +0000 Subject: [PATCH 05/14] Update Unit Test --- .../Tests/Xamarin.Android.Build.Tests/BuildTest.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 4c654b41637..f0819191393 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -778,7 +778,7 @@ public void BuildInDesignTimeMode ([Values(false, true)] bool useManagedParser) } [Test] - public void IfAndroidJarDoesNotExistThrowXA5207 () + public void IfAndroidJarDoesNotExistThrowXA5207 ([Values(true, false)] bool buildingInsideVisualStudio) { var path = Path.Combine ("temp", TestName); var AndroidSdkDirectory = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"), "24.0.1", new ApiInfo [] { new ApiInfo { Id = "30" } }); @@ -788,6 +788,7 @@ public void IfAndroidJarDoesNotExistThrowXA5207 () using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), false, false)) { builder.ThrowOnBuildFailure = false; + builder.BuildingInsideVisualStudio = buildingInsideVisualStudio; Assert.IsTrue (builder.DesignTimeBuild (proj), "DesignTime build should succeed."); Assert.IsFalse (builder.LastBuildOutput.ContainsText ("error XA5207:"), "XA5207 should not have been raised."); builder.Target = "AndroidPrepareForBuild"; @@ -797,6 +798,10 @@ public void IfAndroidJarDoesNotExistThrowXA5207 () }), "Build should have failed"); Assert.IsTrue (builder.LastBuildOutput.ContainsText ("error XA5207:"), "XA5207 should have been raised."); Assert.IsTrue (builder.LastBuildOutput.ContainsText ($"Could not find android.jar for API level {proj.TargetSdkVersion}"), "XA5207 should have had a good error message."); + if (buildingInsideVisualStudio) + Assert.IsTrue (builder.LastBuildOutput.ContainsText ($"Either install it in the Android SDK Manager"), "XA5207 should have an error message for Visual Studio."); + else + Assert.IsTrue (builder.LastBuildOutput.ContainsText ($"You can install the missing API level by running"), "XA5207 should have an error message for the command line."); } Directory.Delete (AndroidSdkDirectory, recursive: true); } From 0e4f019373bb891857dd988e922175d7cf85825f Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 27 Nov 2023 09:55:15 +0000 Subject: [PATCH 06/14] Update docs --- Documentation/guides/building-apps/build-targets.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/guides/building-apps/build-targets.md b/Documentation/guides/building-apps/build-targets.md index fc6697ce83f..4939390dcfa 100644 --- a/Documentation/guides/building-apps/build-targets.md +++ b/Documentation/guides/building-apps/build-targets.md @@ -91,6 +91,17 @@ MSBuild /t:Install ProjectName.csproj /p:AdbTarget=-e Calls the [`GetAndroidDependencies`](#getandroiddependencies) target, then installs the Android SDK packages specified in the `@(AndroidDependency)` item group. +```dotnetcli +dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory= +``` + +The `-f net8.0-android` is required as this target is an .net Android specific target. If you omit this argument +you will get the following error + +`error MSB4057: The target "InstallAndroidDependencies" does not exist in the project` + +The `AndroidSdkDirectory` is required as we need to know where to install the required components. + The [`$(AndroidManifestType)`](~/android/deploy-test/building-apps/build-properties.md#androidmanifesttype) MSBuild property controls which [Visual Studio SDK Manager repository](~/android/get-started/installation/android-sdk.md?tabs=windows#repository-selection) From 838628082071d7d112a637987997932133949f7f Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 27 Nov 2023 15:44:27 +0000 Subject: [PATCH 07/14] Update Documentation/guides/building-apps/build-targets.md Co-authored-by: Jonathan Peppers --- Documentation/guides/building-apps/build-targets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/guides/building-apps/build-targets.md b/Documentation/guides/building-apps/build-targets.md index 4939390dcfa..f71691f61a0 100644 --- a/Documentation/guides/building-apps/build-targets.md +++ b/Documentation/guides/building-apps/build-targets.md @@ -95,7 +95,7 @@ the Android SDK packages specified in the `@(AndroidDependency)` item group. dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory= ``` -The `-f net8.0-android` is required as this target is an .net Android specific target. If you omit this argument +The `-f net8.0-android` is required as this target is a .NET Android specific target. If you omit this argument you will get the following error `error MSB4057: The target "InstallAndroidDependencies" does not exist in the project` From 029b6edeef3ffb391763e0e1a557e868e6e9c0b6 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 27 Nov 2023 15:44:46 +0000 Subject: [PATCH 08/14] Update src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Co-authored-by: Jonathan Peppers --- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 90c61a763af..b4584129fec 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -878,7 +878,7 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins This string is the instrucitons to install the component - You can install the missing API level by running `dotnet build -t:InstallAndroidDependencies -f {0} -p:AndroidSdkDirectory={1}`, or change the Xamarin.Android project to target an API version that is installed. + You can install the missing API level by running `dotnet build -t:InstallAndroidDependencies -f {0} -p:AndroidSdkDirectory={1}`, or change the project to target an API version that is installed. This string is the instrucitons to install the component {0} - The TargetFramework the app is targeting. {1} - The current AndroidSdkDirectory path. From cfad838a3b9996bb99ba40cf67d9ce0ea764c073 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 28 Nov 2023 09:36:43 +0000 Subject: [PATCH 09/14] Update Docs --- Documentation/guides/building-apps/build-targets.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/guides/building-apps/build-targets.md b/Documentation/guides/building-apps/build-targets.md index f71691f61a0..70ba4ddd461 100644 --- a/Documentation/guides/building-apps/build-targets.md +++ b/Documentation/guides/building-apps/build-targets.md @@ -92,7 +92,7 @@ Calls the [`GetAndroidDependencies`](#getandroiddependencies) target, then insta the Android SDK packages specified in the `@(AndroidDependency)` item group. ```dotnetcli -dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory= +dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory= -p:JavaSdkDirectory= ``` The `-f net8.0-android` is required as this target is a .NET Android specific target. If you omit this argument @@ -100,7 +100,8 @@ you will get the following error `error MSB4057: The target "InstallAndroidDependencies" does not exist in the project` -The `AndroidSdkDirectory` is required as we need to know where to install the required components. +The `AndroidSdkDirectory` and `JavaSdkDirectory` are required as we need to know where to install the required components. These directories can be empty or existing. Sdk components +will be installed on top on an existing sdk installation. The [`$(AndroidManifestType)`](~/android/deploy-test/building-apps/build-properties.md#androidmanifesttype) MSBuild property controls which From 80201de193f9719df0931544de508e716a582cc0 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Wed, 29 Nov 2023 09:59:26 +0000 Subject: [PATCH 10/14] Updated error docs and include aka.ms link --- Documentation/guides/messages/xa5207.md | 25 ++++++++++++++++--- .../Properties/Resources.resx | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Documentation/guides/messages/xa5207.md b/Documentation/guides/messages/xa5207.md index 56ac2937fcd..7bb2be512a1 100644 --- a/Documentation/guides/messages/xa5207.md +++ b/Documentation/guides/messages/xa5207.md @@ -7,14 +7,33 @@ ms.date: 06/26/2019 ## Example messages -``` +```dotnetcli XA5207: Could not find android.jar for API Level 28. This means the Android SDK platform for API Level 28 is not installed. Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change your Xamarin.Android project to target an API version that is installed. ``` ## Issue -In order to build a project, the Android SDK Platform matching the target API level must be installed. +In order to build a project, the Android SDK Platform matching the target API level must be installed. ## Solution -Use the Android SDK Manager to install the Android SDK Platform for the desired API level. +Use the Android SDK Manager (Tools > Android > Android SDK Manager...) to install the Android SDK Platform for the desired API level. Alternatively you can install the missing API level by running the following from a terminal or command prompt + +`dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory=` + +Part of the new .net android system is when upgrading projects you will automatically be +upgraded to the latest API level. For example net7.0-android allowed you to target API 33, +but net8.0-android will automatically target API 34. If you want to keep your current +target API level you will need to add the 'uses-sdk' `android:targetSdkVersion` to your `AndroidManifest.xml` file. + +```xml + + + + +``` + +You might then need to run the `InstallAndroidDependencies` target as mentioned above to ensure that the required API level is installed. diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index b4584129fec..211efd8c872 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -867,7 +867,7 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The missing tool name - Could not find android.jar for API level {0}. This means the Android SDK platform for API level {0} is not installed. {2} ({1} missing.) + Could not find android.jar for API level {0}. This means the Android SDK platform for API level {0} is not installed. {2} ({1} missing.) See https://aka.ms/xa5207 for more details. The following are literal names and should not be translated: android.jar {0} - The API level name {1} - The expected path of the android.jar file From 1206d0147cac737b83cabdd3e465befa130a1695 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 29 Nov 2023 14:10:37 -0500 Subject: [PATCH 11/14] Update build-targets.md Wrap MSBuild properties which may contain spaces in double-quotes. Fix message formatting. --- Documentation/guides/building-apps/build-targets.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/guides/building-apps/build-targets.md b/Documentation/guides/building-apps/build-targets.md index 70ba4ddd461..4e62ceab39e 100644 --- a/Documentation/guides/building-apps/build-targets.md +++ b/Documentation/guides/building-apps/build-targets.md @@ -92,15 +92,17 @@ Calls the [`GetAndroidDependencies`](#getandroiddependencies) target, then insta the Android SDK packages specified in the `@(AndroidDependency)` item group. ```dotnetcli -dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory= -p:JavaSdkDirectory= +dotnet build -t:InstallAndroidDependencies -f net8.0-android "-p:AndroidSdkDirectory=" "-p:JavaSdkDirectory=" ``` The `-f net8.0-android` is required as this target is a .NET Android specific target. If you omit this argument -you will get the following error +you will get the following error: -`error MSB4057: The target "InstallAndroidDependencies" does not exist in the project` +``` +error MSB4057: The target "InstallAndroidDependencies" does not exist in the project. +``` -The `AndroidSdkDirectory` and `JavaSdkDirectory` are required as we need to know where to install the required components. These directories can be empty or existing. Sdk components +The `AndroidSdkDirectory` and `JavaSdkDirectory` properties are required as we need to know where to install the required components. These directories can be empty or existing. Sdk components will be installed on top on an existing sdk installation. The [`$(AndroidManifestType)`](~/android/deploy-test/building-apps/build-properties.md#androidmanifesttype) From d0d28116080d4bcb3db994b41e9280219ed0108d Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 29 Nov 2023 14:12:24 -0500 Subject: [PATCH 12/14] Update xa5207.md --- Documentation/guides/messages/xa5207.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/guides/messages/xa5207.md b/Documentation/guides/messages/xa5207.md index 7bb2be512a1..90e89e21925 100644 --- a/Documentation/guides/messages/xa5207.md +++ b/Documentation/guides/messages/xa5207.md @@ -17,9 +17,11 @@ In order to build a project, the Android SDK Platform matching the target API le ## Solution -Use the Android SDK Manager (Tools > Android > Android SDK Manager...) to install the Android SDK Platform for the desired API level. Alternatively you can install the missing API level by running the following from a terminal or command prompt +Use the Android SDK Manager (Tools > Android > Android SDK Manager...) to install the Android SDK Platform for the desired API level. Alternatively you can install the missing API level by running the following command from a terminal or command prompt: -`dotnet build -t:InstallAndroidDependencies -f net8.0-android -p:AndroidSdkDirectory=` +```dotnetcli +dotnet build -t:InstallAndroidDependencies -f net8.0-android "-p:AndroidSdkDirectory=" +``` Part of the new .net android system is when upgrading projects you will automatically be upgraded to the latest API level. For example net7.0-android allowed you to target API 33, @@ -31,8 +33,8 @@ target API level you will need to add the 'uses-sdk' `android:targetSdkVersion` android:versionCode="1" android:versionName="1.0" package="com.companyname.myapp"> - - + + ``` From acdd70ccb0f1acf57e1c776e5e3b140e04f224a0 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 5 Dec 2023 17:09:55 +0000 Subject: [PATCH 13/14] Fix some feedback issues --- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 211efd8c872..29d09e41263 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -867,7 +867,9 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins {0} - The missing tool name - Could not find android.jar for API level {0}. This means the Android SDK platform for API level {0} is not installed. {2} ({1} missing.) See https://aka.ms/xa5207 for more details. + Could not find android.jar for API level {0}. This means the Android SDK platform for API level {0} is not installed; it was expected to be in `{1}`. +{2} +See https://aka.ms/xa5207 for more details. The following are literal names and should not be translated: android.jar {0} - The API level name {1} - The expected path of the android.jar file @@ -878,7 +880,7 @@ Remove the '{0}' reference from your project and add the '{1}' NuGet package ins This string is the instrucitons to install the component - You can install the missing API level by running `dotnet build -t:InstallAndroidDependencies -f {0} -p:AndroidSdkDirectory={1}`, or change the project to target an API version that is installed. + You can install the missing API level by running `dotnet build -t:InstallAndroidDependencies -f {0} "-p:AndroidSdkDirectory={1}"`, or change the project to target an API version that is installed. This string is the instrucitons to install the component {0} - The TargetFramework the app is targeting. {1} - The current AndroidSdkDirectory path. From a1b3354706492c7042263fc23a40f66a85230817 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Wed, 6 Dec 2023 13:01:30 +0000 Subject: [PATCH 14/14] Replace Xamarin.Android with .NET Android --- .../Properties/Resources.resx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 29d09e41263..c5f522f58ef 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -416,7 +416,7 @@ The capitalized word "Portable" that appears earlier in the message is plain tex `LibraryProjectProperties` file `{0}` is located in a parent directory of the bindings project's intermediate output directory. Please adjust the path to use the original `project.properties` file directly from the Android library project directory. The following are literal names and should not be translated: LibraryProjectProperties, project.properties, Android -In this message, the term "binding" means a piece of generated code that makes it easy to access an Android API written in Java from a Xamarin.Android project written in C# or F#. +In this message, the term "binding" means a piece of generated code that makes it easy to access an Android API written in Java from a .NET Android project written in C# or F#. {0} - The path of the LibraryProjectProperties file @@ -438,8 +438,8 @@ In this message, the term "binding" means a piece of generated code that makes i The following are literal names and should not be translated: DX, DEX, d8, AndroidDexTool. - Ignoring configuration file '{0}'. .NET configuration files are not supported in Xamarin.Android projects that target .NET 6 or higher. - The following are literal names and should not be translated: .NET, Xamarin.Android. + Ignoring configuration file '{0}'. .NET configuration files are not supported in .NET Android projects that target .NET 6 or higher. + The following are literal names and should not be translated: .NET, .NET Android. {0} - The file name such as 'Foo.dll.config' @@ -451,7 +451,7 @@ In this message, the term "binding" means a piece of generated code that makes i The following are literal names and should not be translated: AAPT, AAPT2, Android, AndroidUseAapt2, true. - Using AAPT is not supported in Xamarin.Android projects that target .NET 6 or higher. Please enable 'Use incremental Android packaging system (aapt2)' in the Visual Studio project property pages or edit the project file in a text editor and set the 'AndroidUseAapt2' MSBuild property to 'true'. + Using AAPT is not supported in .NET Android projects that target .NET 6 or higher. Please enable 'Use incremental Android packaging system (aapt2)' in the Visual Studio project property pages or edit the project file in a text editor and set the 'AndroidUseAapt2' MSBuild property to 'true'. The following are literal names and should not be translated: AAPT, Android, AndroidUseAapt2, true. @@ -511,7 +511,7 @@ Either change the value in the AndroidManifest.xml to match the $(SupportedOSPla {1} - The SupportedOSPlatformVersion property value - Use of AppDomain.CreateDomain() detected in assembly: {0}. .NET 6 and higher will only support a single AppDomain, so this API will no longer be available in Xamarin.Android once .NET 6 is released. + Use of AppDomain.CreateDomain() detected in assembly: {0}. .NET 6 and higher will only support a single AppDomain, so this API will no longer be available in .NET Android once .NET 6 is released. The following are literal names and should not be translated: AppDomain.CreateDomain(), AppDomain {0} - The name of the assembly @@ -710,12 +710,12 @@ In this message, "root element" refers to the root element of an XML file. {0} - The exception message and stack trace of the associated exception - The Android class parser value '{0}' is deprecated and will be removed in a future version of Xamarin.Android. Update the project properties to use 'class-parse'. + The Android class parser value '{0}' is deprecated and will be removed in a future version of .NET Android. Update the project properties to use 'class-parse'. The following are literal names and should not be translated: class-parse {0} - The name of the current class parser value - The Android code generation target '{0}' is deprecated and will be removed in a future version of Xamarin.Android. Update the project properties to use 'XAJavaInterop1'. + The Android code generation target '{0}' is deprecated and will be removed in a future version of .NET Android. Update the project properties to use 'XAJavaInterop1'. The following are literal names and should not be translated: XAJavaInterop1 {0} - The name of the current code generation target @@ -796,7 +796,7 @@ The following are literal names and should not be translated: ABI, 'libs/armeabi "Wear" is a short version of the full product name "Wear OS" and so should not be translated. - Referencing the Android Wear application project '{0}' from an Android application project is deprecated and will no longer be supported in a future version of Xamarin.Android. Remove the Android Wear application project reference from the Android application project and distribute the Wear application as a standalone application instead. + Referencing the Android Wear application project '{0}' from an Android application project is deprecated and will no longer be supported in a future version of .NET Android. Remove the Android Wear application project reference from the Android application project and distribute the Wear application as a standalone application instead. The following are literal names and should not be translated: Android Wear, Android, Wear. {0} - The referenced Android Wear project. @@ -876,7 +876,7 @@ See https://aka.ms/xa5207 for more details. {2} - The instructions to install the missing component - Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the Xamarin.Android project to target an API version that is installed. + Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the .NET Android project to target an API version that is installed. This string is the instrucitons to install the component