Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] remove the android\assets\shrunk directory
Browse files Browse the repository at this point in the history
Context: #3753
Context: xamarin/monodroid#1053

There appears to be an issue with mono:2019-10 when the Xamarin.Forms
integration project is built with AOT in `Release` mode.

The issue somehow stems from two `Mono.Android.dll` existing:

* `obj\Debug\android\assets\Mono.Android.dll`
* `obj\Debug\android\assets\shrunk\Mono.Android.dll`

Looking at how AOT is invoked, it seems like either `Mono.Android.dll`
could be picked up by the parameters being passed in. We might be
AOT'ing a user's `Foo.dll`, and both directories are in `$MONO_PATH`
or passed via other arguments. How would we know which is picked up?

The `shrunk` directory is used by the `<RemoveRegisterAttribute/>`
MSBuild task that:
* Runs after the linker & `<GenerateJavaStubs/>`
* Removes all the `[RegisterAttribute]` from types, to further shrink
  `Mono.Android.dll`.

It looks like we copy all `@(_ResolvedFrameworkAssemblies)` to the
`shrunk` directory and fix up item groups. Why don't we just get rid
of this `shrunk` directory and not copy anything? We can edit
`Mono.Android.dll` in place, and incremental builds should be fine due
to the use of stamp files.

I also moved the flag file to:

    $(_AndroidStampDirectory)_RemoveRegisterAttribute.stamp

To match our new MSBuild conventions.

There is also usage of `@(_ShrunkFrameworkAssemblies)` that needs to
be updated in monodroid.
  • Loading branch information
jonathanpeppers committed Nov 20, 2019
1 parent 748dec3 commit 20f192f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xamarin/monodroid:master@1b907d680cc6561dcfaddc6f997d2f6ff5456644
xamarin/monodroid:shrunkframeworkassemblies@326b7fc28ebfc0e630e3383ea5061a3337efe986
mono/mono:2019-08@8946e49a974ea8b75fe5b8b7e93ffd4571521a85
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class RemoveRegisterAttribute : AndroidTask
const string RegisterAttribute = "Android.Runtime.RegisterAttribute";

[Required]
public ITaskItem[] ShrunkFrameworkAssemblies { get; set; }
public ITaskItem[] FrameworkAssemblies { get; set; }

public bool Deterministic { get; set; }

public override bool RunTask ()
{
// Find Mono.Android.dll
var mono_android = ShrunkFrameworkAssemblies.First (f => Path.GetFileNameWithoutExtension (f.ItemSpec) == "Mono.Android").ItemSpec;
var mono_android = FrameworkAssemblies.First (f => Path.GetFileNameWithoutExtension (f.ItemSpec) == "Mono.Android").ItemSpec;
var writerParameters = new WriterParameters {
DeterministicMvid = Deterministic,
};
Expand Down
41 changes: 8 additions & 33 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,6 @@ because xbuild doesn't support framework reference assemblies.
<_AndroidLinkFlag>$(IntermediateOutputPath)link.flag</_AndroidLinkFlag>
<_AndroidApkPerAbiFlagFile>$(IntermediateOutputPath)android\bin\apk_per_abi.flag</_AndroidApkPerAbiFlagFile>
<_AndroidDebugKeyStoreFlag>$(IntermediateOutputPath)android_debug_keystore.flag</_AndroidDebugKeyStoreFlag>
<_RemoveRegisterFlag>$(MonoAndroidIntermediateAssemblyDir)shrunk\shrunk.flag</_RemoveRegisterFlag>
<_AcwMapFile>$(IntermediateOutputPath)acw-map.txt</_AcwMapFile>
<_CustomViewMapFile>$(IntermediateOutputPath)customview-map.txt</_CustomViewMapFile>
<_AndroidTypeMappingJavaToManaged>$(IntermediateOutputPath)android\typemap.jm</_AndroidTypeMappingJavaToManaged>
Expand Down Expand Up @@ -2038,18 +2037,6 @@ because xbuild doesn't support framework reference assemblies.
<Output TaskParameter="Include" ItemName="_ResolvedFrameworkAssemblies" />
</CreateItem>

<CreateItem
Include="@(_ResolvedFrameworkAssemblies)"
Condition="'$(AndroidLinkMode)' == 'None' OR '$(AndroidUseSharedRuntime)' == 'true'">
<Output TaskParameter="Include" ItemName="_ShrunkFrameworkAssemblies" />
</CreateItem>

<CreateItem
Include="@(_ResolvedFrameworkAssemblies->'$(MonoAndroidIntermediateAssemblyDir)shrunk\%(Filename)%(Extension)')"
Condition="'$(AndroidLinkMode)' != 'None' AND '$(AndroidUseSharedRuntime)' != 'true'">
<Output TaskParameter="Include" ItemName="_ShrunkFrameworkAssemblies" />
</CreateItem>

<CreateItem
Include="@(_ResolvedUserAssemblies)"
Condition="'%(_ResolvedUserAssemblies.TargetFrameworkIdentifier)' == 'MonoAndroid' Or '%(_ResolvedUserAssemblies.HasMonoAndroidReference)' == 'True'">
Expand Down Expand Up @@ -2512,27 +2499,16 @@ because xbuild doesn't support framework reference assemblies.
<Target Name="_RemoveRegisterAttribute"
DependsOnTargets="_PrepareAssemblies"
Inputs="$(_AndroidLinkFlag)"
Outputs="$(_RemoveRegisterFlag)"
Outputs="$(_AndroidStampDirectory)_RemoveRegisterAttribute.stamp"
Condition="'$(AndroidLinkMode)' != 'None' AND '$(AndroidUseSharedRuntime)' != 'true'">

<!-- Make a copy of every assembly into assets\shrunk -->
<Copy
SourceFiles="@(_ResolvedFrameworkAssemblies)"
DestinationFiles="@(_ShrunkFrameworkAssemblies)"
SkipUnchangedFiles="true" />

<CopyIfChanged
SourceFiles="@(_ResolvedFrameworkAssemblies->'%(Identity).config')"
DestinationFiles="@(_ShrunkFrameworkAssemblies->'%(Identity).config')" />

<!-- Shrink Mono.Android.dll by removing attribute only needed for GenerateJavaStubs -->
<RemoveRegisterAttribute
Condition="'$(AndroidLinkMode)' != 'None' AND '$(AndroidUseSharedRuntime)' != 'true'"
Deterministic="$(Deterministic)"
ShrunkFrameworkAssemblies="@(_ShrunkFrameworkAssemblies)" />
FrameworkAssemblies="@(_ResolvedFrameworkAssemblies)" />

<MakeDir Directories="$(MonoAndroidIntermediateAssemblyDir)shrunk" />
<Touch Files="$(_RemoveRegisterFlag)" AlwaysCreate="true" />
<Touch Files="$(_AndroidStampDirectory)_RemoveRegisterAttribute.stamp" AlwaysCreate="true" />
</Target>

<Target Name="_ResolveSatellitePaths"
Expand Down Expand Up @@ -2674,8 +2650,7 @@ because xbuild doesn't support framework reference assemblies.
<_BuildApkEmbedInputs>
$(MSBuildAllProjects)
;$(_PackagedResources)
;@(_ResolvedUserAssemblies)
;@(_ShrunkFrameworkAssemblies)
;@(_ResolvedAssemblies)
;@(AndroidNativeLibrary)
;@(_DexFile)
;$(_AndroidBuildPropertiesCache)
Expand Down Expand Up @@ -2712,7 +2687,7 @@ because xbuild doesn't support framework reference assemblies.
SupportedAbis="@(_BuildTargetAbis)"
AndroidSequencePointsMode="$(_SequencePointsMode)"
AotAdditionalArguments="$(AndroidAotAdditionalArguments)"
ResolvedAssemblies="@(_ResolvedUserAssemblies);@(_ShrunkFrameworkAssemblies)"
ResolvedAssemblies="@(_ResolvedAssemblies)"
AotOutputDirectory="$(_AndroidAotBinDirectory)"
IntermediateAssemblyDir="$(MonoAndroidIntermediateAssemblyDir)"
LinkMode="$(AndroidLinkMode)"
Expand All @@ -2737,7 +2712,7 @@ because xbuild doesn't support framework reference assemblies.
Condition="'$(BundleAssemblies)' == 'True'"
KeepTemp="$(AndroidMakeBundleKeepTemporaryFiles)"
AndroidNdkDirectory="$(_AndroidNdkDirectory)"
Assemblies="@(_ResolvedUserAssemblies);@(_AndroidResolvedSatellitePaths);@(_ShrunkFrameworkAssemblies)"
Assemblies="@(_ResolvedAssemblies);@(_AndroidResolvedSatellitePaths)"
IncludePath="$(MonoAndroidIncludeDirectory)"
SupportedAbis="@(_BuildTargetAbis)"
TempOutputPath="$(IntermediateOutputPath)"
Expand All @@ -2755,7 +2730,7 @@ because xbuild doesn't support framework reference assemblies.
BundleNativeLibraries="$(_BundleResultNativeLibraries)"
EmbedAssemblies="$(EmbedAssembliesIntoApk)"
ResolvedUserAssemblies="@(_ResolvedUserAssemblies);@(_AndroidResolvedSatellitePaths)"
ResolvedFrameworkAssemblies="@(_ShrunkFrameworkAssemblies)"
ResolvedFrameworkAssemblies="@(_ResolvedFrameworkAssemblies)"
NativeLibraries="@(AndroidNativeLibrary)"
ApplicationSharedLibraries="@(_ApplicationSharedLibrary)"
AdditionalNativeLibraryReferences="@(_AdditionalNativeLibraryReferences)"
Expand Down Expand Up @@ -2784,7 +2759,7 @@ because xbuild doesn't support framework reference assemblies.
BundleNativeLibraries="$(_BundleResultNativeLibraries)"
EmbedAssemblies="$(EmbedAssembliesIntoApk)"
ResolvedUserAssemblies="@(_ResolvedUserAssemblies);@(_AndroidResolvedSatellitePaths)"
ResolvedFrameworkAssemblies="@(_ShrunkFrameworkAssemblies)"
ResolvedFrameworkAssemblies="@(_ResolvedFrameworkAssemblies)"
NativeLibraries="@(AndroidNativeLibrary)"
ApplicationSharedLibraries="@(_ApplicationSharedLibrary)"
AdditionalNativeLibraryReferences="@(_AdditionalNativeLibraryReferences)"
Expand Down

0 comments on commit 20f192f

Please sign in to comment.