Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] default to only 64-bit targets (#9179)
Browse files Browse the repository at this point in the history
We currently build for all 4 Android architectures by default.  While
modern apps are more likely to run on `android-arm64` modern devices
or `android-x64` default emulator on x64 machines.

Let's drop 32-bit targets by default, and let customers opt into them.
This could significatly help `Release` build times, etc.

Customers could opt into all 4 by adding in their `.csproj`:

	<RuntimeIdentifiers>android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>

Or in the case of a multi-targeted .NET MAUI project:

	<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>
  • Loading branch information
jonathanpeppers authored Aug 16, 2024
1 parent 339c6a1 commit 6be8531
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<SuppressTrimAnalysisWarnings Condition=" '$(SuppressTrimAnalysisWarnings)' == '' and ('$(TrimMode)' == 'full' or '$(IsAotCompatible)' == 'true') ">false</SuppressTrimAnalysisWarnings>
<SuppressTrimAnalysisWarnings Condition=" '$(SuppressTrimAnalysisWarnings)' == '' ">true</SuppressTrimAnalysisWarnings>
<!-- Prefer $(RuntimeIdentifiers) plural -->
<RuntimeIdentifiers Condition=" '$(RuntimeIdentifier)' == '' And '$(RuntimeIdentifiers)' == '' ">android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition=" '$(RuntimeIdentifier)' == '' And '$(RuntimeIdentifiers)' == '' ">android-arm64;android-x64</RuntimeIdentifiers>
<RuntimeIdentifier Condition=" '$(RuntimeIdentifiers)' != '' And '$(RuntimeIdentifier)' != '' " />
<AndroidManifest Condition=" '$(AndroidManifest)' == '' and Exists ('Properties\AndroidManifest.xml') and !Exists ('AndroidManifest.xml') ">Properties\AndroidManifest.xml</AndroidManifest>
<AndroidManifest Condition=" '$(AndroidManifest)' == '' ">AndroidManifest.xml</AndroidManifest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,6 @@ public void BuildAMassiveApp ()
app1.Imports.Add (new Import ("foo.targets") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project ToolsVersion=""4.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Target Name=""_CheckAbis"" BeforeTargets=""_DefineBuildTargetAbis"">
<PropertyGroup>
<AndroidSupportedAbis>armeabi-v7a;x86</AndroidSupportedAbis>
<AndroidSupportedAbis Condition=""Exists('$(MSBuildThisFileDirectory)..\..\..\..\Debug\lib\xamarin.android\xbuild\Xamarin\Android\lib\arm64-v8a\libmono-android.release.so')"">$(AndroidSupportedAbis);arm64-v8a</AndroidSupportedAbis>
<AndroidSupportedAbis Condition=""Exists('$(MSBuildThisFileDirectory)..\..\..\..\Debug\lib\xamarin.android\xbuild\Xamarin\Android\lib\x86_64\libmono-android.release.so')"">$(AndroidSupportedAbis);x86_64</AndroidSupportedAbis>
</PropertyGroup>
<Message Text=""$(AndroidSupportedAbis)"" />
</Target>
<Target Name=""_Foo"" AfterTargets=""_SetLatestTargetFrameworkVersion"">
<PropertyGroup>
<AotAssemblies Condition=""!Exists('$(MonoAndroidBinDirectory)" + Path.DirectorySeparatorChar + @"cross-arm')"">False</AotAssemblies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Foo ()
});
libB.OtherBuildItems.Add (new AndroidItem.AndroidNativeLibrary (default (Func<string>)) {
Update = () => "libfoo.so",
MetadataValues = "Link=x86\\libfoo.so",
MetadataValues = "Link=x86_64\\libfoo.so",
BinaryContent = () => Array.Empty<byte> (),
});
libB.AddReference (libC);
Expand Down Expand Up @@ -183,7 +183,7 @@ public Foo ()
aar.AssertContainsEntry (aarPath, "libs/A1AFA985571E728E.jar");
aar.AssertContainsEntry (aarPath, $"libs/{projectJarHash}.jar");
aar.AssertContainsEntry (aarPath, "jni/arm64-v8a/libfoo.so");
aar.AssertContainsEntry (aarPath, "jni/x86/libfoo.so");
aar.AssertContainsEntry (aarPath, "jni/x86_64/libfoo.so");
// proguard.txt from Library C should not flow to Library B and "double"
aar.AssertEntryEquals (aarPath, "proguard.txt", "# LibraryB");
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public Foo ()
apk.AssertContainsEntry (aarPath, "res/layout/mylayout.xml");
apk.AssertContainsEntry (apkPath, "res/raw/bar.txt");
apk.AssertContainsEntry (apkPath, "lib/arm64-v8a/libfoo.so");
apk.AssertContainsEntry (apkPath, "lib/x86/libfoo.so");
apk.AssertContainsEntry (apkPath, "lib/x86_64/libfoo.so");
}

// Check classes.dex contains foo.jar
Expand All @@ -242,7 +242,7 @@ public Foo ()
Assert.IsTrue (DexUtils.ContainsClass (className, dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}`!");

// Check environment variable
var environmentFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediate, "x86", required: true);
var environmentFiles = EnvironmentHelper.GatherEnvironmentFiles (intermediate, "x86_64", required: true);
var environmentVariables = EnvironmentHelper.ReadEnvironmentVariables (environmentFiles);
Assert.IsTrue (environmentVariables.TryGetValue (env_var, out string actual), $"Environment should contain {env_var}");
Assert.AreEqual (env_val, actual, $"{env_var} should be {env_val}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ public abstract class MyRunner {
}"
});
var proj = new XamarinAndroidApplicationProject { IsRelease = true, ProjectName = "App1" };
proj.SetRuntimeIdentifiers(["armeabi-v7a", "arm64-v8a", "x86", "x86_64"]);
proj.References.Add(new BuildItem.ProjectReference (Path.Combine ("..", "Lib1", "Lib1.csproj"), "Lib1"));
proj.MainActivity = proj.DefaultMainActivity.Replace (
"base.OnCreate (bundle);",
Expand Down

0 comments on commit 6be8531

Please sign in to comment.