Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] remove checks for $(UsingAndroidNETSdk)
Browse files Browse the repository at this point in the history
In .NET 6+, `$(UsingAndroidNETSdk)` is always `true` as the general
identifier that this project is .NET and not Xamarin.Android. We used
this flag as a way to share code between .NET Android and
Xamarin.Android.

* Remove checks for `$(UsingAndroidNETSdk)`

* No longer need to pass in this value to MSBuilds tasks or other C#
  classes

* Checks if `true` leave in place, and remove the condition

* Checks if `false` can just be completely removed now

In a future PR, we may also be able to remove
`$(_AndroidIsBindingProject)`, which is slightly related. We removed the
"binding project" as a concept in .NET 6+.

I left the `$(UsingAndroidNETSdk)` property in place, even though it is
not used in these targets. Other general MSBuild targets may continue to
use it in perpetuity.
  • Loading branch information
jonathanpeppers committed Jan 18, 2024
1 parent 2f19238 commit 84b59b6
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,15 @@ This item group populates the Build Action drop-down in IDEs.
<AvailableItemName Include="ProjectReference" />
<AvailableItemName Include="AndroidManifestOverlay" />
</ItemGroup>
<!-- Legacy, non-binding projects -->
<ItemGroup Condition=" '$(_AndroidIsBindingProject)' != 'true' and '$(UsingAndroidNETSdk)' != 'true' ">
<AvailableItemName Include="AndroidAarLibrary" />
<AvailableItemName Include="AndroidJavaLibrary" />
</ItemGroup>
<!-- Legacy, non-application projects -->
<ItemGroup Condition=" '$(AndroidApplication)' != 'true' and '$(UsingAndroidNETSdk)' != 'true' ">
<AvailableItemName Include="EmbeddedNativeLibrary" />
</ItemGroup>
<!-- Legacy binding projects or .NET 6 -->
<ItemGroup Condition=" '$(_AndroidIsBindingProject)' == 'true' or '$(UsingAndroidNETSdk)' == 'true' ">

<!-- All project types -->
<ItemGroup>
<AvailableItemName Include="TransformFile" />
<AvailableItemName Include="LibraryProjectProperties" />
<AvailableItemName Include="JavaDocIndex" />
<AvailableItemName Include="JavaDocJar" />
<AvailableItemName Include="JavaSourceJar" />
</ItemGroup>
<!-- Legacy binding projects -->
<ItemGroup Condition=" '$(_AndroidIsBindingProject)' == 'true' and '$(UsingAndroidNETSdk)' != 'true' ">
<AvailableItemName Include="EmbeddedJar" />
<AvailableItemName Include="EmbeddedNativeLibrary" />
<AvailableItemName Include="EmbeddedReferenceJar" />
<AvailableItemName Include="InputJar" />
<AvailableItemName Include="ReferenceJar" />
<AvailableItemName Include="LibraryProjectZip" />
</ItemGroup>

<!-- Default item metadata -->
<ItemDefinitionGroup>
Expand All @@ -64,13 +47,13 @@ This item group populates the Build Action drop-down in IDEs.
</AndroidResource>
<AndroidLibrary>
<Bind>true</Bind>
<Pack Condition=" '$(UsingAndroidNETSdk)' == 'true' ">true</Pack>
<Pack>true</Pack>
</AndroidLibrary>
<LibraryProjectZip>
<Pack Condition=" '$(UsingAndroidNETSdk)' == 'true' ">true</Pack>
<Pack>true</Pack>
</LibraryProjectZip>
<AndroidJavaSource>
<Bind Condition=" '$(UsingAndroidNETSdk)' == 'true' ">true</Bind>
<Bind>true</Bind>
</AndroidJavaSource>
<AndroidAarLibrary>
<!-- NOTE: .aar items should skip %(AndroidSkipResourceProcessing) by default -->
Expand All @@ -80,38 +63,26 @@ This item group populates the Build Action drop-down in IDEs.

<!-- Convert @(AndroidLibrary) to the legacy item group names -->
<Target Name="_CategorizeAndroidLibraries">
<!-- Applications, or legacy class libraries -->
<ItemGroup Condition=" '$(AndroidApplication)' == 'true' or ('$(_AndroidIsBindingProject)' != 'true' and '$(UsingAndroidNETSdk)' != 'true') ">
<!-- Applications -->
<ItemGroup Condition=" '$(AndroidApplication)' == 'true' ">
<AndroidAarLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' " />
<AndroidJavaLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' " />
<InputJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' == 'true' " />
</ItemGroup>
<!-- Any library that is not an app -->
<!-- Class libraries, not an application -->
<ItemGroup Condition=" '$(AndroidApplication)' != 'true' ">
<EmbeddedNativeLibrary Include="@(AndroidNativeLibrary)" />
</ItemGroup>
<!-- Any .NET 6 project -->
<ItemGroup Condition=" '$(UsingAndroidNETSdk)' == 'true' ">
<LibraryProjectZip Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' == 'true' " />
</ItemGroup>
<!-- .NET 6 application projects -->
<ItemGroup Condition=" '$(AndroidApplication)' == 'true' and '$(UsingAndroidNETSdk)' == 'true' ">
<InputJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' == 'true' " />
</ItemGroup>
<!-- .NET 6 class libraries-->
<ItemGroup Condition=" '$(AndroidApplication)' != 'true' and '$(UsingAndroidNETSdk)' == 'true' ">
<AndroidAarLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' != 'true' " />
<AndroidJavaLibrary Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' != 'true' " />
<EmbeddedJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' == 'true' " />
<!-- .aar files should be copied to $(OutputPath) in .NET 6-->
<!-- .aar files should be copied to $(OutputPath) in .NET 6+ -->
<None Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' " TfmSpecificPackageFile="%(AndroidLibrary.Pack)" Pack="false" CopyToOutputDirectory="PreserveNewest" Link="%(Filename)%(Extension)" />
<!-- @(LibraryProjectZip) items that are not in @(AndroidLibrary) -->
<None Include="@(LibraryProjectZip)" Exclude="@(AndroidLibrary)" TfmSpecificPackageFile="%(LibraryProjectZip.Pack)" Pack="false" CopyToOutputDirectory="PreserveNewest" Link="%(Filename)%(Extension)" />
</ItemGroup>
<!-- Legacy binding projects -->
<ItemGroup Condition=" '$(_AndroidIsBindingProject)' == 'true' and '$(UsingAndroidNETSdk)' != 'true' ">
<LibraryProjectZip Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' == 'true' " />
<EmbeddedJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' == 'true' " />
<EmbeddedReferenceJar Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.jar' and '%(AndroidLibrary.Bind)' != 'true' " />
<!-- All projects -->
<ItemGroup>
<LibraryProjectZip Include="@(AndroidLibrary)" Condition=" '%(AndroidLibrary.Extension)' == '.aar' and '%(AndroidLibrary.Bind)' == 'true' " />
</ItemGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ It is shared between "legacy" binding projects and .NET 5 projects.
<GeneratedOutputPath Condition=" '$(GeneratedOutputPath)' == '' ">$(IntermediateOutputPath)generated\</GeneratedOutputPath>
<AndroidJavadocVerbosity Condition=" '$(AndroidJavadocVerbosity)' == '' ">intellisense</AndroidJavadocVerbosity>
<ApiOutputFile Condition=" '$(ApiOutputFile)' == '' ">$(IntermediateOutputPath)api.xml</ApiOutputFile>
<ClassParseToolExe Condition=" '$(UsingAndroidNETSdk)' == 'true' ">class-parse.dll</ClassParseToolExe>
<ClassParseToolExe Condition=" '$(ClassParseToolExe)' == '' ">class-parse.exe</ClassParseToolExe>
<BindingsGeneratorToolExe Condition=" '$(UsingAndroidNETSdk)' == 'true' ">generator.dll</BindingsGeneratorToolExe>
<BindingsGeneratorToolExe Condition=" '$(BindingsGeneratorToolExe)' == '' ">generator.exe</BindingsGeneratorToolExe>
<ClassParseToolExe Condition=" '$(ClassParseToolExe)' == '' ">class-parse.dll</ClassParseToolExe>
<BindingsGeneratorToolExe Condition=" '$(BindingsGeneratorToolExe)' == '' ">generator.dll</BindingsGeneratorToolExe>
<JavadocToMdocToolExe Condition=" '$(JavadocToMdocToolExe)' == '' ">javadoc-to-mdoc.exe</JavadocToMdocToolExe>
<_GeneratorStampFile>$(_AndroidStampDirectory)generator.stamp</_GeneratorStampFile>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<MonoAndroidAssetsPrefix Condition=" '$(MonoAndroidAssetsPrefix)' == '' ">Assets</MonoAndroidAssetsPrefix>
<AndroidResgenClass Condition=" '$(AndroidResgenClass)' == '' ">Resource</AndroidResgenClass>
<AndroidEnableSGenConcurrent Condition=" '$(AndroidEnableSGenConcurrent)' == '' ">true</AndroidEnableSGenConcurrent>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' and '$(UsingAndroidNETSdk)' == 'true' ">Xamarin.Android.Net.AndroidMessageHandler</AndroidHttpClientHandlerType>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' and '$(UsingAndroidNETSdk)' != 'true' ">Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<AndroidHttpClientHandlerType Condition=" '$(AndroidHttpClientHandlerType)' == '' ">Xamarin.Android.Net.AndroidMessageHandler</AndroidHttpClientHandlerType>
<AndroidGenerateResourceDesigner Condition=" '$(AndroidGenerateResourceDesigner)' == '' ">true</AndroidGenerateResourceDesigner>
<AndroidUseDesignerAssembly Condition=" '$(AndroidUseDesignerAssembly)' == '' ">true</AndroidUseDesignerAssembly>
<AndroidUseIntermediateDesignerFile Condition=" '$(AndroidUseDesignerAssembly)' == 'True' ">false</AndroidUseIntermediateDesignerFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class GeneratePackageManagerJava : AndroidTask
public string TlsProvider { get; set; }
public string AndroidSequencePointsMode { get; set; }
public bool EnableSGenConcurrent { get; set; }
public bool UsingAndroidNETSdk { get; set; }

[Output]
public string BuildId { get; set; }
Expand Down Expand Up @@ -195,7 +194,7 @@ void AddEnvironment ()
BrokenExceptionTransitions = false,
UsesAssemblyPreload = EnablePreloadAssembliesDefault,
};
environmentParser.Parse (Environments, sequencePointsMode, UsingAndroidNETSdk, Log);
environmentParser.Parse (Environments, sequencePointsMode, Log);

foreach (string line in environmentParser.EnvironmentVariableLines) {
AddEnvironmentVariableLine (line);
Expand All @@ -219,13 +218,6 @@ void AddEnvironment ()
AddEnvironmentVariable ("XA_HTTP_CLIENT_HANDLER_TYPE", HttpClientHandlerType.Trim ());
}

if (!UsingAndroidNETSdk && !environmentParser.HaveTlsProvider) {
if (TlsProvider == null)
AddEnvironmentVariable (defaultTlsProvider[0], defaultTlsProvider[1]);
else
AddEnvironmentVariable ("XA_TLS_PROVIDER", TlsProvider.Trim ());
}

if (!environmentParser.HaveMonoGCParams) {
if (EnableSGenConcurrent)
AddEnvironmentVariable ("MONO_GC_PARAMS", "major=marksweep-conc");
Expand Down Expand Up @@ -355,19 +347,6 @@ void AddEnvironment ()
}
}

// In "classic" Xamarin.Android, we need to add libaot-*.dll.so files
if (!UsingAndroidNETSdk && usesMonoAOT) {
foreach (var assembly in ResolvedAssemblies) {
string name = $"libaot-{Path.GetFileNameWithoutExtension (assembly.ItemSpec)}.dll.so";
if (seenNativeLibraryNames.Contains (name)) {
continue;
}

seenNativeLibraryNames.Add (name);
uniqueNativeLibraries.Add (new TaskItem (name));
}
}

bool haveRuntimeConfigBlob = !String.IsNullOrEmpty (RuntimeConfigBinFilePath) && File.Exists (RuntimeConfigBinFilePath);
var appConfState = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<ApplicationConfigTaskState> (ProjectSpecificTaskObjectKey (ApplicationConfigTaskState.RegisterTaskObjectKey), RegisteredTaskObjectLifetime.Build);
var jniRemappingNativeCodeInfo = BuildEngine4.GetRegisteredTaskObjectAssemblyLocal<GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfo> (ProjectSpecificTaskObjectKey (GenerateJniRemappingNativeCode.JniRemappingNativeCodeInfoKey), RegisteredTaskObjectLifetime.Build);
Expand Down
22 changes: 5 additions & 17 deletions src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class LinkAssembliesNoShrink : AndroidTask
[Required]
public string TargetName { get; set; } = "";

public bool UsingAndroidNETSdk { get; set; }

public bool AddKeepAlives { get; set; }

public bool UseDesignerAssembly { get; set; }
Expand Down Expand Up @@ -70,15 +68,15 @@ public override bool RunTask ()
// Set up the FixAbstractMethodsStep and AddKeepAlivesStep
var cache = new TypeDefinitionCache ();
var fixAbstractMethodsStep = new FixAbstractMethodsStep (resolver, cache, Log);
var addKeepAliveStep = new AddKeepAlivesStep (resolver, cache, Log, UsingAndroidNETSdk);
var addKeepAliveStep = new AddKeepAlivesStep (resolver, cache, Log);
var fixLegacyResourceDesignerStep = new FixLegacyResourceDesignerStep (resolver, Log);
for (int i = 0; i < SourceFiles.Length; i++) {
var source = SourceFiles [i];
var destination = DestinationFiles [i];
var assemblyName = Path.GetFileNameWithoutExtension (source.ItemSpec);

// In .NET 6+, we can skip the main assembly
if (UsingAndroidNETSdk && !AddKeepAlives && assemblyName == TargetName) {
if (!AddKeepAlives && assemblyName == TargetName) {
CopyIfChanged (source, destination);
continue;
}
Expand All @@ -87,17 +85,9 @@ public override bool RunTask ()
continue;
}

// Check AppDomain usage on any non-Product or Sdk assembly
AssemblyDefinition? assemblyDefinition = null;
if (!UsingAndroidNETSdk) {
assemblyDefinition = resolver.GetAssembly (source.ItemSpec);
fixAbstractMethodsStep.CheckAppDomainUsage (assemblyDefinition, (string msg) => Log.LogCodedWarning ("XA2000", msg));
}

// Only run the step on "MonoAndroid" assemblies
if (MonoAndroidHelper.IsMonoAndroidAssembly (source) && !MonoAndroidHelper.IsSharedRuntimeAssembly (source.ItemSpec)) {
if (assemblyDefinition == null)
assemblyDefinition = resolver.GetAssembly (source.ItemSpec);
var assemblyDefinition = resolver.GetAssembly (source.ItemSpec);

bool save = fixAbstractMethodsStep.FixAbstractMethods (assemblyDefinition);
if (UseDesignerAssembly)
Expand Down Expand Up @@ -185,19 +175,17 @@ class AddKeepAlivesStep : MonoDroid.Tuner.AddKeepAlivesStep
{
readonly DirectoryAssemblyResolver resolver;
readonly TaskLoggingHelper logger;
readonly bool hasSystemPrivateCoreLib;

public AddKeepAlivesStep (DirectoryAssemblyResolver resolver, TypeDefinitionCache cache, TaskLoggingHelper logger, bool hasSystemPrivateCoreLib)
public AddKeepAlivesStep (DirectoryAssemblyResolver resolver, TypeDefinitionCache cache, TaskLoggingHelper logger)
: base (cache)
{
this.resolver = resolver;
this.logger = logger;
this.hasSystemPrivateCoreLib = hasSystemPrivateCoreLib;
}

protected override AssemblyDefinition GetCorlibAssembly ()
{
return resolver.GetAssembly (hasSystemPrivateCoreLib ? "System.Private.CoreLib.dll" : "mscorlib.dll");
return resolver.GetAssembly ("System.Private.CoreLib.dll");
}

public override void LogMessage (string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public bool AreBrokenExceptionTransitionsEnabled (ITaskItem[] environments)
return false;
}

public void Parse (ITaskItem[] environments, SequencePointsMode sequencePointsMode, bool usingAndroidNETSdk, TaskLoggingHelper log)
public void Parse (ITaskItem[] environments, SequencePointsMode sequencePointsMode, TaskLoggingHelper log)
{
foreach (ITaskItem env in environments ?? Array.Empty<ITaskItem> ()) {
foreach (string line in File.ReadLines (env.ItemSpec)) {
Expand All @@ -56,9 +56,6 @@ public void Parse (ITaskItem[] environments, SequencePointsMode sequencePointsMo
if (lineToWrite.StartsWith ("XA_HTTP_CLIENT_HANDLER_TYPE=", StringComparison.Ordinal))
HaveHttpMessageHandler = true;

if (!usingAndroidNETSdk && lineToWrite.StartsWith ("XA_TLS_PROVIDER=", StringComparison.Ordinal))
HaveTlsProvider = true;

if (lineToWrite.StartsWith ("mono.enable_assembly_preload=", StringComparison.Ordinal)) {
int idx = lineToWrite.IndexOf ('=');
uint val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!-- Android Sdk Tool versions are sourced from this file. This is maintained in the xamarin-android-tools repo. -->
<Import Project="$(MSBuildThisFileDirectory)\Xamarin.Android.Tools.Versions.props" />
<PropertyGroup>
<XamarinAndroidVersion Condition=" '$(UsingAndroidNETSdk)' != 'true' ">@PACKAGE_VERSION@-@PACKAGE_VERSION_BUILD@</XamarinAndroidVersion>
<_JavaInteropReferences>Java.Interop;System.Runtime</_JavaInteropReferences>
<Debugger Condition=" '$(Debugger)' == '' ">Xamarin</Debugger>
<DependsOnSystemRuntime Condition=" '$(DependsOnSystemRuntime)' == '' ">true</DependsOnSystemRuntime>
Expand Down
Loading

0 comments on commit 84b59b6

Please sign in to comment.