Skip to content

Commit

Permalink
[build] option for Java.Interop to be built as non-PCL (#360)
Browse files Browse the repository at this point in the history
* [build] option for Java.Interop to be built as non-PCL

Fixes: http://work.devdiv.io/667174

When building a "Hello World" Xamarin.Android app, I noticed the
following in the build log:

    Adding assembly reference for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065, recursively...
        Adding assembly reference for System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.ComponentModel.Composition, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, recursively...
        Adding assembly reference for System.Diagnostics.Debug, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Threading, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Collections, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Collections.Concurrent, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Reflection, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Linq.Expressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Reflection.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Dynamic.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.ObjectModel, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Linq, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Runtime.InteropServices, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Runtime.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
        Adding assembly reference for System.Reflection.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, recursively...
    Adding assembly reference for Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065, recursively...

It appears that Java.Interop is a PCL, and we end up having to work
with lots of facade assemblies during our build!

My thought is that we should build `Java.Interop.dll` the same as
`Mono.Android.dll`:

    <PropertyGroup>
        <NoStdLib>true</NoStdLib>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="mscorlib">
            <HintPath>$(XAInstallPrefix)xbuild-frameworks\MonoAndroid\v1.0\mscorlib.dll</HintPath>
            <Private>False</Private>
        </Reference>
        <Reference Include="System">
            <HintPath>$(XAInstallPrefix)xbuild-frameworks\MonoAndroid\v1.0\System.dll</HintPath>
            <Private>False</Private>
        </Reference>
        <Reference Include="System.Core">
            <HintPath>$(XAInstallPrefix)xbuild-frameworks\MonoAndroid\v1.0\System.Core.dll</HintPath>
            <Private>False</Private>
        </Reference>
    </ItemGroup>

I added a new property, `$(JavaInteropProfile)` we can set downstream
in Xamarin.Android. We can set this with a
`Configuration.Override.props` file that is already used in
Xamarin.Android's build process.

After doing this, the log now reads:

   Adding assembly reference for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065, recursively...
   Adding assembly reference for Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065, recursively...

And the savings in build times for "Hello World", this is the
`Rebuild` target:
- `Debug` + PCL - 8.424s
- `Release` + PCL - 13.651s
- `Debug` + *not* PCL - 4.258s
- `Release` + *not PCL - 9.487s

That does bring up a big question, however...

Why are facade assemblies adding so much build time???

This change is good: making `Java.Interop` have fewer dependencies.
But I suspect there is more work to be done downstream in
Xamarin.Android. I have a feeling referencing `netstandard` libraries
cause the same problem to occur.

* [build] $(JavaInteropProfile) now outputs to $(Configuration)Net45 folder

This allows us to have two sets of outputs:
- bin/Debug/Java.Interop.dll - referenced by MSBuild tasks
- bin/DebugNet45/Java.Interop.dll - referenced by Mono.Android.dll and apps

Other changes:
- Fixed warning where file was getting imported twice
- Updated `.gitignore` for `*.binlog` files

* Whoops doc XML file was missing
  • Loading branch information
jonathanpeppers authored and dellis1972 committed Aug 25, 2018
1 parent 80b4f4e commit 893562c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ packages
.nuget/
*.userprefs
*.user
Resource.designer.cs
Resource.designer.cs
*.binlog
27 changes: 27 additions & 0 deletions src/Java.Interop/Java.Interop.Net45.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project>
<PropertyGroup>
<NoStdLib Condition=" '$(XAInstallPrefix)' != '' ">true</NoStdLib>
<OutputPath>..\..\bin\$(Configuration)Net45</OutputPath>
<DocumentationFile>$(OutputPath)\Java.Interop.xml</DocumentationFile>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup Condition=" '$(XAInstallPrefix)' != '' ">
<Reference Include="mscorlib">
<HintPath>$(XAInstallPrefix)xbuild-frameworks\MonoAndroid\v1.0\mscorlib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System">
<HintPath>$(XAInstallPrefix)xbuild-frameworks\MonoAndroid\v1.0\System.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Core">
<HintPath>$(XAInstallPrefix)xbuild-frameworks\MonoAndroid\v1.0\System.Core.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(XAInstallPrefix)' == '' ">
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/Java.Interop/Java.Interop.PCL.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>
5 changes: 3 additions & 2 deletions src/Java.Interop/Java.Interop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop</RootNamespace>
<AssemblyName>Java.Interop</AssemblyName>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<NoWarn>1591</NoWarn>
<SignAssembly>true</SignAssembly>
Expand Down Expand Up @@ -129,7 +128,9 @@
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\GCUserPeerable.java" />
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\ManagedPeer.java" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\Configuration.props" />
<Import Project="Java.Interop.PCL.props" Condition=" '$(JavaInteropProfile)' != 'net45' " />
<Import Project="Java.Interop.Net45.props" Condition=" '$(JavaInteropProfile)' == 'net45' " />
<Import Project="Java.Interop.targets" />
<PropertyGroup>
<BuildDependsOn>
Expand Down
1 change: 0 additions & 1 deletion src/Java.Interop/Java.Interop.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
</PropertyGroup>
<Import Project="$(JNIEnvGenPath)\JdkInfo.props" />
<Target Name="BuildJnienvGen"
Inputs="..\..\build-tools\jnienv-gen\jnienv-gen.csproj"
Outputs="$(JNIEnvGenPath)\jnienv-gen.exe">
Expand Down

0 comments on commit 893562c

Please sign in to comment.