Skip to content

Commit

Permalink
Merge branch 'main' into dev/grendel/native-tracing
Browse files Browse the repository at this point in the history
* main:
  [trimming] fix custom applications for `TrimMode=full` (#8936)
  • Loading branch information
grendello committed May 14, 2024
2 parents 23fde10 + 98c1063 commit 4086a74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Microsoft.Android.Sdk.ILLink/PreserveApplications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ void PreserveTypeProperty (CustomAttribute attribute, string property)
if (!attribute.HasProperties)
return;

var type_ref = (TypeReference) attribute.Properties.First (p => p.Name == property).Argument.Value;
// NOTE: CustomAttributeNamedArgument is a struct
var named_arg = attribute.Properties.FirstOrDefault (p => p.Name == property);
if (named_arg.Name == null)
return;

var type_ref = named_arg.Argument.Value as TypeReference;
if (type_ref == null)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,11 @@ public void BuildAfterMultiDexIsNotRequired ()
}

[Test]
public void CustomApplicationClassAndMultiDex ()
public void CustomApplicationClassAndMultiDex ([Values (true, false)] bool isRelease)
{
var proj = CreateMultiDexRequiredApplication ();
proj.IsRelease = isRelease;
proj.TrimModeRelease = TrimMode.Full;
proj.SetProperty ("AndroidEnableMultiDex", "True");
proj.Sources.Add (new BuildItem ("Compile", "CustomApp.cs") { TextContent = () => @"
using System;
Expand All @@ -1108,7 +1110,7 @@ public override void OnCreate()
}
}
}" });
using (var b = CreateApkBuilder ("temp/CustomApplicationClassAndMultiDex")) {
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Assert.IsFalse (b.LastBuildOutput.ContainsText ("Duplicate zip entry"), "Should not get warning about [META-INF/MANIFEST.MF]");
var customAppContent = File.ReadAllText (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "src", "com", "foxsports", "test", "CustomApp.java"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public static string ToString (TypeDefinition typeDef, TypeDefinitionCache cache

public static TypeDefinition ResolveType (string type, ICustomAttributeProvider provider, IAssemblyResolver resolver)
{
if (type == null)
throw new ArgumentException ("Type resolution support requires a non-null Type.", nameof (type));
if (provider == null)
throw new ArgumentException ("Type resolution support requires an AssemblyDefinition or TypeDefinition.", "provider");
throw new ArgumentException ("Type resolution support requires an AssemblyDefinition or TypeDefinition.", nameof (provider));
if (resolver == null)
throw new ArgumentException ("Type resolution support requires a IAssemblyResolver.", "resolver");
throw new ArgumentException ("Type resolution support requires a IAssemblyResolver.", nameof (resolver));

// `type` is either a "bare" type "Foo.Bar", or an
// assembly-qualified type "Foo.Bar, AssemblyName [Version=...]?".
Expand Down

0 comments on commit 4086a74

Please sign in to comment.