Uh oh!
There was an error while loading. Please reload this page.
[Xamarin.Android.Build.Tasks] remove TFI == MonoAndroid checks - #4225
[Xamarin.Android.Build.Tasks] remove TFI == MonoAndroid checks#4225jonathanpeppers wants to merge 1 commit into
Conversation
2f06e64 to
3a4e712Comparejonpryor
commented
Feb 6, 2020
I would like this to also rely on a reference to |
In preparation for .NET 5, we think the `$(TargetFrameworkMoniker)` *might* be: .NETCoreApp,Version=5.0,Profile=Xamarin.Android It might also be `Profile=Android`, we don't know for sure yet. The TFM currently is: MonoAndroid,Version=v10.0 I think we can (and should) remove any code during the build that looks at `$(TargetFrameworkIdentifier)`. The places we are currently doing this are for performance: * The `_ResolveLibraryProjectImports` or `_GenerateJavaStubs` targets do not need to run against .NET standard assemblies. We can rely on a reference to `Mono.Android.dll` or `Java.Interop.dll` instead. We are already using System.Reflection.Metadata to see if the assembly actually has this reference. So an example of the condition: Condition="'%(ResolvedUserAssemblies.TargetFrameworkIdentifier)' == 'MonoAndroid' Or '%(ResolvedUserAssemblies.HasMonoAndroidReference)' == 'True'" Can just be: Condition="'%(ResolvedUserAssemblies.HasMonoAndroidReference)' == 'True'" One test failure was that `Xamarin.Forms.Platform.dll` *used* to be treated as a "Xamarin.Android" assembly. * It has a `MonoAndroid` TFI * It has *no* reference to `Mono.Android.dll` or `Java.Interop.dll` * It has no `Java.Lang.Object` subclasses * It has no `__AndroidLibraryProjects__.zip` or `*.jar` `EmbeddedResource` files In the case of this assembly, I think everything will continue to work. It is OK for it to not be treated as a "Xamarin.Android" assembly. I also took the opportunity for a small perf improvement: * `<FilterAssemblies/>` only needs to look for obsolete attributes in assemblies that reference `Mono.Android.dll`. ~~ Results ~~ Testing a build with no changes for the SmartHotel360 app: Before: 60 ms FilterAssemblies 2 calls After: 49 ms FilterAssemblies 2 calls I would think there is a small ~11ms performance improvement to all builds of this app.
3a4e712 to
efdd682Comparejonathanpeppers
commented
Feb 6, 2020
I made this look for both |
jonpryor
commented
Feb 6, 2020
I have concerns, as it looks like this won't deal with "transitive dependencies". So consider this silly example: $ cat A.cs
using System;
using System.Text.RegularExpressions;
namespace Example {
public class A {
Regex r;
}
}
$ csc /t:Library /nologo A.cs
A.cs(6,15): warning CS0169: The field 'A.r' is never used
$ cat B.cs
using System;
using Example;
namespace Example {
public class B : A { }
}
$ csc /t:library /nologo B.cs /r:A.dll
$ monodis --assemblyref A.dll
AssemblyRef Table
1: Version=4.0.0.0
Name=mscorlib
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89 2: Version=4.0.0.0
Name=System
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
monodis --assemblyref B.dll
AssemblyRef Table
1: Version=4.0.0.0
Name=mscorlib
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89 2: Version=0.0.0.0
Name=A
Flags=0x00000000
Zero sized public keyNow, why do I care? Rename // Assembly: A.dllnamespaceExample{publicclassA:Java.Lang.Object{}}// Assembly: B.dllnamespaceExample{publicclassB:A{}}// ...and for local testing purposes, Mono.Android.dll:namespaceJava.Lang{publicclassObject{}}The semantics are that we must pass Which is doubly odd, because it does need to be referenced: Above we see that ...oops? Maybe this is already handled by the PR; I don't know. What I'm fairly certain about is that Use of |
jonathanpeppers
commented
Feb 6, 2020
I need to make a test as mentioned above that verifies the java stub exists after a build. Right now this PR doesn't look like it would. |
jonathanpeppers
commented
Feb 7, 2020
It definitely breaks in my test that has Foo -> Bar -> Baz: I almost have it recursively finding the reference for |
I am going to close this for now; I can come back to this if needed. I was unable to pass the TFM from leaf nodes up to the parent node -- just due to how the ordering/recursive code was working in What I think we should do instead is make the new .NET 5 TFMs work, when we know what they will be for sure. |

In preparation for .NET 5, we think the
$(TargetFrameworkMoniker)might be:
It might also be
Profile=Android, we don't know for sure yet.The TFM currently is:
I think we can (and should) remove any code during the build that
looks at
$(TargetFrameworkIdentifier).The places we are currently doing this are for performance:
_ResolveLibraryProjectImportsor_GenerateJavaStubstargetsdo not need to run against .NET standard assemblies.
We can rely on a reference to
Mono.Android.dllorJava.Interop.dllinstead. We are already using System.Reflection.Metadata to see if the
assembly actually has this reference.
So an example of the condition:
Can just be:
One test failure was that
Xamarin.Forms.Platform.dllused to betreated as a "Xamarin.Android" assembly.
MonoAndroidTFIMono.Android.dllorJava.Interop.dllJava.Lang.Objectsubclasses__AndroidLibraryProjects__.zipor*.jarEmbeddedResourcefilesIn the case of this assembly, I think everything will continue to
work. It is OK for it to not be treated as a "Xamarin.Android"
assembly.
I also took the opportunity for a small perf improvement:
<FilterAssemblies/>only needs to look for obsolete attributes inassemblies that reference
Mono.Android.dll.Results
Testing a build with no changes for the SmartHotel360 app:
I would think there is a small ~11ms performance improvement to all
builds of this app.