Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Documentation/docs-mobile/messages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ Either change the value in the AndroidManifest.xml to match the $(SupportedOSPla
+ [XA4250](xa4250.md): Manifest-referenced type '{type}' was not found in any scanned assembly. It may be a framework type.
+ [XA4252](xa4252.md): Insecure HTTP Maven repository URL '{url}' is not allowed. Use an HTTPS URL, or set AllowInsecureHttp="true" metadata on the item to override this check.
+ [XA4253](xa4253.md): Generated Java callable wrapper code changed: '{path}'
+ [XA4254](xa4254.md): Trimmable type map Java source input directory '{input}' and output directory '{output}' must be different.
+ [XA4255](xa4255.md): Generated trimmable type map Java source '{path}' was not found.
+ XA4300: Native library '{library}' will not be bundled because it has an unsupported ABI.
+ [XA4301](xa4301.md): Apk already contains the item `xxx`.
+ [XA4302](xa4302.md): Unhandled exception merging \`AndroidManifest.xml\`: {ex}
Expand Down
25 changes: 0 additions & 25 deletions Documentation/docs-mobile/messages/xa4254.md

This file was deleted.

27 changes: 0 additions & 27 deletions Documentation/docs-mobile/messages/xa4255.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public TrimmableTypeMapResult Execute (
ManifestConfig? manifestConfig = null,
XDocument? manifestTemplate = null,
string? packageNamingPolicy = null,
int maxArrayRank = 0,
bool generateTypeMapAssemblies = true)
int maxArrayRank = 0)
{
_ = assemblies ?? throw new ArgumentNullException (nameof (assemblies));
_ = systemRuntimeVersion ?? throw new ArgumentNullException (nameof (systemRuntimeVersion));
Expand All @@ -55,9 +54,7 @@ public TrimmableTypeMapResult Execute (
PropagateDeferredRegistrationToBaseClasses (allPeers);
PropagateCannotRegisterToDescendants (allPeers);

var generatedAssemblies = generateTypeMapAssemblies
? GenerateTypeMapAssemblies (allPeers, systemRuntimeVersion, useSharedTypemapUniverse, maxArrayRank)
: [];
var generatedAssemblies = GenerateTypeMapAssemblies (allPeers, systemRuntimeVersion, useSharedTypemapUniverse, maxArrayRank);
var jcwPeers = allPeers.Where (ShouldGenerateJcw).ToList ();
logger.LogGeneratingJcwFilesInfo (jcwPeers.Count, allPeers.Count);
var generatedJavaSources = GenerateJcwJavaSources (jcwPeers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,45 +48,6 @@
OutputFile="$(_ProguardProjectConfiguration)" />
</Target>

<Target Name="_GeneratePostTrimTrimmableTypeMapJavaSources"
Condition=" '$(_AndroidTypeMapImplementation)' == 'trimmable' and '$(PublishTrimmed)' == 'true' and Exists('$(IntermediateOutputPath)linked/Link.semaphore') "
AfterTargets="ILLink"
BeforeTargets="_GenerateJavaStubs;_CompileJava;_CompileToDalvik"
Inputs="$(IntermediateOutputPath)linked/Link.semaphore"
Outputs="$(_PostTrimTrimmableTypeMapJavaStamp)">
<ItemGroup>
<_PostTrimTrimmableTypeMapInputAssemblies Include="@(ResolvedFileToPublish)"
Condition=" '%(Extension)' == '.dll' " />
</ItemGroup>

<GenerateTrimmableTypeMap
ResolvedAssemblies="@(_PostTrimTrimmableTypeMapInputAssemblies)"
FrameworkAssemblyNames="@(ResolvedFrameworkAssemblies->'%(Filename)')"
OutputDirectory="$(_TypeMapOutputDirectory)"
JavaSourceOutputDirectory="$(_PostTrimTypeMapJavaOutputDirectory)"
JavaSourceInputDirectory="$(_TypeMapJavaOutputDirectory)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
PackageNamingPolicy="$(_TrimmableTypeMapPackageNamingPolicy)"
MaxArrayRank="$(_AndroidTrimmableTypeMapMaxArrayRank)"
GenerateTypeMapAssemblies="false"
CleanJavaSourceOutputDirectory="true"
AcwMapOutputFile="$(IntermediateOutputPath)acw-map.txt"
ApplicationRegistrationOutputFile="$(IntermediateOutputPath)android/src/net/dot/android/ApplicationRegistration.java">
<Output TaskParameter="GeneratedJavaFiles" ItemName="_PostTrimGeneratedJavaFiles" />
</GenerateTrimmableTypeMap>

<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(_PostTrimTrimmableTypeMapJavaStamp)'))" />
<Touch Files="$(_PostTrimTrimmableTypeMapJavaStamp)" AlwaysCreate="true" />

<ItemGroup>
<FileWrites Include="@(_PostTrimGeneratedJavaFiles)" />
<FileWrites Include="$(IntermediateOutputPath)acw-map.txt" />
<FileWrites Include="$(IntermediateOutputPath)android/src/net/dot/android/ApplicationRegistration.java" />
<FileWrites Include="$(_PostTrimTrimmableTypeMapJavaStamp)" />
<_PostTrimTrimmableTypeMapInputAssemblies Remove="@(_PostTrimTrimmableTypeMapInputAssemblies)" />
<_PostTrimGeneratedJavaFiles Remove="@(_PostTrimGeneratedJavaFiles)" />
</ItemGroup>
</Target>
<!-- Add linked TypeMap DLLs to the normal publish assembly pipeline. The SDK R2R
target only compiles ResolvedFileToPublish items with PostprocessAssembly=true. -->
<Target Name="_AddTrimmableTypeMapToResolvedFileToPublish"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
<_TypeMapOutputDirectory>$(_TypeMapBaseOutputDir)typemap/</_TypeMapOutputDirectory>
<_TypeMapJavaOutputDirectory>$(_TypeMapBaseOutputDir)typemap/java</_TypeMapJavaOutputDirectory>
<_TypeMapAssembliesListFile>$(_TypeMapOutputDirectory)typemap-assemblies.txt</_TypeMapAssembliesListFile>
<_PostTrimTypeMapJavaOutputDirectory>$(_TypeMapBaseOutputDir)typemap/linked-java</_PostTrimTypeMapJavaOutputDirectory>
<_TypeMapJavaStubsSourceDirectory Condition=" '$(_TypeMapJavaStubsSourceDirectory)' == '' and '$(_AndroidRuntime)' == 'CoreCLR' and '$(PublishTrimmed)' == 'true' ">$(_PostTrimTypeMapJavaOutputDirectory)</_TypeMapJavaStubsSourceDirectory>
<_TypeMapJavaStubsSourceDirectory Condition=" '$(_TypeMapJavaStubsSourceDirectory)' == '' ">$(_TypeMapJavaOutputDirectory)</_TypeMapJavaStubsSourceDirectory>
<_PostTrimTrimmableTypeMapJavaStamp>$(_TypeMapBaseOutputDir)stamp/_GeneratePostTrimTrimmableTypeMapJavaSources.stamp</_PostTrimTrimmableTypeMapJavaStamp>
<_TrimmableJavaSourceStamp Condition=" '$(_TrimmableJavaSourceStamp)' == '' and '$(_AndroidRuntime)' == 'CoreCLR' and '$(PublishTrimmed)' == 'true' ">$(_PostTrimTrimmableTypeMapJavaStamp)</_TrimmableJavaSourceStamp>
<_TrimmableJavaSourceStamp Condition=" '$(_TrimmableJavaSourceStamp)' == '' ">$(_TypeMapOutputDirectory)$(_TypeMapAssemblyName).dll</_TrimmableJavaSourceStamp>
<!-- Max array rank for __ArrayMapRank{N} sentinel emission. Defaults to 3 when
dynamic code is unavailable, so array creation uses the typemap path;
defaults to 0 otherwise, where dynamic code can use Array.CreateInstance directly. -->
Expand Down Expand Up @@ -257,7 +251,7 @@
Outputs="$(_AndroidStampDirectory)_GenerateJavaStubs.stamp">

<ItemGroup>
<_TypeMapJavaFiles Include="$(_TypeMapJavaStubsSourceDirectory)/**/*.java" />
<_TypeMapJavaFiles Include="$(_TypeMapJavaOutputDirectory)/**/*.java" />
</ItemGroup>
<Copy SourceFiles="@(_TypeMapJavaFiles)" DestinationFolder="$(IntermediateOutputPath)android/src/%(RecursiveDir)" />

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1145,17 +1145,6 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
<value>Generated Java callable wrapper code changed: '{0}'</value>
<comment>{0} - The path to the generated Java callable wrapper file</comment>
</data>
<data name="XA4254" xml:space="preserve">
<value>Trimmable type map Java source input directory '{0}' and output directory '{1}' must be different.</value>
<comment>The following are literal names and should not be translated: Trimmable type map, Java.
{0} - Full path to the Java source input directory
{1} - Full path to the Java source output directory</comment>
</data>
<data name="XA4255" xml:space="preserve">
<value>Generated trimmable type map Java source '{0}' was not found.</value>
<comment>The following are literal names and should not be translated: trimmable type map, Java.
{0} - Full path to the generated Java source file</comment>
</data>
<data name="XA0142" xml:space="preserve">
<value>Command '{0}' failed.\n{1}</value>
<comment>'{0}' is a failed command name (potentially with path) followed by all the arguments passed to it. {1} is the combined output on the standard error and standard output streams.</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void LogJniAddNativeMethodRegistrationAttributeError (string managedTypeN
public string OutputDirectory { get; set; } = "";
[Required]
public string JavaSourceOutputDirectory { get; set; } = "";
public string? JavaSourceInputDirectory { get; set; }
[Required]
public string TargetFrameworkVersion { get; set; } = "";

Expand Down Expand Up @@ -93,8 +92,6 @@ public void LogJniAddNativeMethodRegistrationAttributeError (string managedTypeN
public string? ManifestPlaceholders { get; set; }
public string? CheckedBuild { get; set; }
public string? ApplicationJavaClass { get; set; }
public bool GenerateTypeMapAssemblies { get; set; } = true;
public bool CleanJavaSourceOutputDirectory { get; set; }

[Output]
public ITaskItem [] GeneratedAssemblies { get; set; } = [];
Expand All @@ -119,19 +116,8 @@ public override bool RunTask ()
foreach (var assemblyName in FrameworkAssemblyNames) {
frameworkAssemblyNames.Add (assemblyName);
}
if (CleanJavaSourceOutputDirectory && !JavaSourceInputDirectory.IsNullOrEmpty ()) {
var inputDirectory = Path.GetFullPath (JavaSourceInputDirectory);
var outputDirectory = Path.GetFullPath (JavaSourceOutputDirectory);
if (string.Equals (inputDirectory, outputDirectory, StringComparison.OrdinalIgnoreCase)) {
Log.LogCodedError ("XA4254", Properties.Resources.XA4254, inputDirectory, outputDirectory);
return false;
}
}

Directory.CreateDirectory (OutputDirectory);
if (CleanJavaSourceOutputDirectory && Directory.Exists (JavaSourceOutputDirectory)) {
Directory.Delete (JavaSourceOutputDirectory, recursive: true);
}
Directory.CreateDirectory (JavaSourceOutputDirectory);
Comment on lines 120 to 121

var peReaders = new List<PEReader> ();
Expand Down Expand Up @@ -182,16 +168,11 @@ public override bool RunTask ()
manifestConfig: manifestConfig,
manifestTemplate: manifestTemplate,
packageNamingPolicy: PackageNamingPolicy,
maxArrayRank: MaxArrayRank,
generateTypeMapAssemblies: GenerateTypeMapAssemblies);
maxArrayRank: MaxArrayRank);

if (GenerateTypeMapAssemblies) {
GeneratedAssemblies = WriteAssembliesToDisk (result.GeneratedAssemblies, assemblyInputs.Select (i => i.Path).ToList ());
WriteGeneratedAssembliesListFile (GeneratedAssemblies);
}
GeneratedJavaFiles = JavaSourceInputDirectory.IsNullOrEmpty ()
? WriteJavaSourcesToDisk (result.GeneratedJavaSources)
: CopyJavaSourcesFromInputDirectory (result.GeneratedJavaSources);
GeneratedAssemblies = WriteAssembliesToDisk (result.GeneratedAssemblies, assemblyInputs.Select (i => i.Path).ToList ());
WriteGeneratedAssembliesListFile (GeneratedAssemblies);
GeneratedJavaFiles = WriteJavaSourcesToDisk (result.GeneratedJavaSources);

// Write manifest to disk if generated
if (result.Manifest is not null && !MergedAndroidManifestOutput.IsNullOrEmpty ()) {
Expand Down Expand Up @@ -266,29 +247,6 @@ void WriteGeneratedAssembliesListFile (IReadOnlyList<ITaskItem> assemblies)
Files.CopyIfStringChanged (text, GeneratedAssembliesListFile);
}

ITaskItem [] CopyJavaSourcesFromInputDirectory (IReadOnlyList<GeneratedJavaSource> javaSources)
{
var items = new List<ITaskItem> ();
foreach (var source in javaSources) {
string inputPath = Path.Combine (JavaSourceInputDirectory ?? "", source.RelativePath);
if (!File.Exists (inputPath)) {
Log.LogCodedError ("XA4255", Properties.Resources.XA4255, inputPath);
continue;
}

string outputPath = Path.Combine (JavaSourceOutputDirectory, source.RelativePath);
string? dir = Path.GetDirectoryName (outputPath);
if (!string.IsNullOrEmpty (dir)) {
Directory.CreateDirectory (dir);
}
using (var stream = File.OpenRead (inputPath)) {
Files.CopyIfStreamChanged (stream, outputPath);
}
items.Add (new TaskItem (outputPath));
}
return items.ToArray ();
}

ITaskItem [] WriteAssembliesToDisk (IReadOnlyList<GeneratedAssembly> assemblies, IReadOnlyList<string> assemblyPaths)
{
// Build a map from assembly name -> source path for timestamp comparison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,6 @@ public void ReleaseCoreClrTrimmableTypeMap_SingleRuntimeIdentifier_PackagesLinke
var typeMapDirectory = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "typemap"));
var linkedAssemblyDirectory = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "linked"));
var readyToRunAssemblyDirectory = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "R2R"));
var javaSourceDirectory = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "android", "src"));
var dexFile = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "android", "bin", "classes.dex"));
var acwMapPath = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "acw-map.txt"));
var proguardPrimaryPath = builder.Output.GetIntermediaryPath (Path.Combine ("android-arm64", "proguard", "proguard_project_primary.cfg"));

DirectoryAssert.Exists (typeMapDirectory, "trimmable build should generate typemap assemblies.");
DirectoryAssert.Exists (linkedAssemblyDirectory, "Release trimmable build should run ILLink.");

Expand Down Expand Up @@ -363,8 +358,6 @@ public void ReleaseCoreClrTrimmableTypeMap_SingleRuntimeIdentifier_PackagesLinke
expectedHash.SequenceEqual (packagedHash),
$"{apkPath} should package post-link typemap assembly {pair.Key} from {pair.Value}, not the generated pre-link copy.");
}

AssertPostTrimR8InputsExcludeDeadFrameworkImplementor (dexFile, javaSourceDirectory, acwMapPath, proguardPrimaryPath);
}

[Test]
Expand Down Expand Up @@ -652,35 +645,6 @@ ISet<string> ReadPackagedManagedAssemblyNames (string apkPath, AndroidTargetArch
.ToHashSet (StringComparer.Ordinal);
}

void AssertPostTrimR8InputsExcludeDeadFrameworkImplementor (string dexFile, string javaSourceDirectory, string acwMapPath, string proguardPrimaryPath)
{
const string deadManagedType = "Android.Animation.Animator+IAnimatorListenerImplementor";
const string deadJavaName = "Lmono/android/animation/Animator_AnimatorListenerImplementor;";
const string deadJavaDotName = "mono.android.animation.Animator_AnimatorListenerImplementor";

Assert.IsTrue (
Directory.EnumerateFiles (javaSourceDirectory, "MainActivity.java", SearchOption.AllDirectories).Any (),
"Post-trim Java source generation should keep the app activity JCW.");
FileAssert.DoesNotExist (
Path.Combine (javaSourceDirectory, "mono", "android", "animation", "Animator_AnimatorListenerImplementor.java"),
"Post-trim Java source generation should not copy framework listener implementors removed by ILLink.");

FileAssert.Exists (acwMapPath, "Post-trim scan should rewrite acw-map.txt for R8.");
var acwMap = File.ReadAllText (acwMapPath);
Assert.IsFalse (acwMap.Contains (deadManagedType, StringComparison.Ordinal), $"{acwMapPath} should be based on linked assemblies.");
Assert.IsFalse (acwMap.Contains (deadJavaDotName, StringComparison.Ordinal), $"{acwMapPath} should not keep removed framework listener implementors.");

FileAssert.Exists (proguardPrimaryPath, "R8 should generate a primary proguard configuration from the post-trim acw-map.");
Assert.IsFalse (
File.ReadAllText (proguardPrimaryPath).Contains (deadJavaDotName, StringComparison.Ordinal),
$"{proguardPrimaryPath} should not keep removed framework listener implementors.");

FileAssert.Exists (dexFile, "R8 should produce classes.dex.");
Assert.IsFalse (
DexUtils.ContainsClass (deadJavaName, dexFile, AndroidSdkPath),
$"{dexFile} should not contain the removed framework listener implementor.");
}

string FindOutputFile (ProjectBuilder builder, XamarinAndroidApplicationProject proj, string fileName)
{
var outputDirectory = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath);
Expand Down