Skip to content

Commit

Permalink
[WIP] Support for NET6 builds of the Java runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Feb 26, 2021
1 parent 1802827 commit 1270c68
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xamarin/monodroid:main@2e93b630e47701dae56f426fe5934846d571832b
xamarin/monodroid:net6-native@9f5d2e031c207a0174f2f6d126835311ba58754d
mono/mono:2020-02@c66141a8c7ba2566c578c2dd012b2b723e006213
2 changes: 2 additions & 0 deletions build-tools/create-pkg/create-pkg.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<MSBuildFrameworksDir>$(XAFrameworkDir)\lib\xamarin.android\xbuild-frameworks\MonoAndroid</MSBuildFrameworksDir>
</PropertyGroup>
<RemoveDir Directories="$(PayloadDir)" />
<!-- Remove items with '%(ExcludeFromLegacy)' == 'true' metadata -->
<MSBuildItemsUnix Remove="@(MSBuildItemsUnix)" Condition=" '%(MSBuildItemsUnix.ExcludeFromLegacy)' == 'true' " />
<Copy
SourceFiles="@(FrameworkItemsUnix)"
DestinationFiles="@(FrameworkItemsUnix->'$(MSBuildFrameworksDir)\%(RelativePath)')"
Expand Down
2 changes: 2 additions & 0 deletions build-tools/create-vsix/create-vsix.targets
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<ReferenceAssemblies Include="@(FrameworkItemsWin)" >
<VSIXSubPath>Microsoft/Framework/MonoAndroid/$([System.IO.Path]::GetDirectoryName(%(RelativePath)))</VSIXSubPath>
</ReferenceAssemblies>
<!-- Remove items with '%(ExcludeFromLegacy)' == 'true' metadata -->
<MSBuildItemsWin Remove="@(MSBuildItemsWin)" Condition=" '%(MSBuildItemsWin.ExcludeFromLegacy)' == 'true' " />
<MSBuild Include="@(MSBuildItemsWin)" >
<VSIXSubPath>Xamarin/Android/$([System.IO.Path]::GetDirectoryName(%(RelativePath)))</VSIXSubPath>
</MSBuild>
Expand Down
12 changes: 8 additions & 4 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@
<_MSBuildFiles Include="$(MSBuildSrcDir)\startup-xf.aotprofile" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\r8.jar" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\bundletool.jar" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.jar" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.jar" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.dex" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.dex" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.jar" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.jar" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.dex" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.dex" ExcludeFromAndroidNETSdk="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_net6.jar" ExcludeFromLegacy="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev_net6.jar" ExcludeFromLegacy="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_net6.dex" ExcludeFromLegacy="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev_net6.dex" ExcludeFromLegacy="true" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\manifestmerger.jar" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\protobuf-net.dll" />
<_MSBuildFiles Include="$(MSBuildSrcDir)\SgmlReaderDll.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,8 +1259,11 @@ because xbuild doesn't support framework reference assemblies.

<Target Name="_CollectRuntimeJarFilenames">
<PropertyGroup>
<_RuntimeJar>$(MSBuildThisFileDirectory)\java_runtime.jar</_RuntimeJar>
<_RuntimeDex>$(MSBuildThisFileDirectory)\java_runtime.dex</_RuntimeDex>
<_RuntimeJar Condition=" '$(UsingAndroidNETSdk)' != 'True' ">$(MSBuildThisFileDirectory)\java_runtime.jar</_RuntimeJar>
<_RuntimeDex Condition=" '$(UsingAndroidNETSdk)' != 'True' ">$(MSBuildThisFileDirectory)\java_runtime.dex</_RuntimeDex>

<_RuntimeJar Condition=" '$(UsingAndroidNETSdk)' == 'True' ">$(MSBuildThisFileDirectory)\java_runtime_net6.jar</_RuntimeJar>
<_RuntimeDex Condition=" '$(UsingAndroidNETSdk)' == 'True' ">$(MSBuildThisFileDirectory)\java_runtime_net6.dex</_RuntimeDex>
</PropertyGroup>
</Target>

Expand Down
19 changes: 17 additions & 2 deletions src/java-runtime/java-runtime.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@
<OutputDex>$(OutputPath)java_runtime.dex</OutputDex>
<IntermediateRuntimeOutputPath>$(IntermediateOutputPath)release</IntermediateRuntimeOutputPath>
<IntermediateRuntimeClassesTxt>$(IntermediateOutputPath)release.txt</IntermediateRuntimeClassesTxt>
<RemoveItems>..\..\src-ThirdParty\bazel\java\mono\android\debug\MultiDexLoader.java;java\mono\android\debug\BuildConfig.java</RemoveItems>
<RemoveItems>..\..\src-ThirdParty\bazel\java\mono\android\debug\MultiDexLoader.java;java\mono\android\debug\BuildConfig.java;java\mono\android\debug-net6\BuildConfig.java;java\mono\android\release-net6\BuildConfig.java</RemoveItems>
</_RuntimeOutput>
<_RuntimeOutput Include="$(OutputPath)java_runtime_fastdev.jar">
<OutputJar>$(OutputPath)java_runtime_fastdev.jar</OutputJar>
<OutputDex>$(OutputPath)java_runtime_fastdev.dex</OutputDex>
<IntermediateRuntimeOutputPath>$(IntermediateOutputPath)fastdev</IntermediateRuntimeOutputPath>
<IntermediateRuntimeClassesTxt>$(IntermediateOutputPath)fastdev.txt</IntermediateRuntimeClassesTxt>
<RemoveItems>..\..\src-ThirdParty\bazel\java\mono\android\release\MultiDexLoader.java;java\mono\android\release\BuildConfig.java</RemoveItems>
<RemoveItems>..\..\src-ThirdParty\bazel\java\mono\android\release\MultiDexLoader.java;java\mono\android\release\BuildConfig.java;java\mono\android\release-net6\BuildConfig.java;java\mono\android\debug-net6\BuildConfig.java</RemoveItems>
</_RuntimeOutput>

<_RuntimeOutput Include="$(OutputPath)java_runtime_net6.jar">
<OutputJar>$(OutputPath)java_runtime_net6.jar</OutputJar>
<OutputDex>$(OutputPath)java_runtime_net6.dex</OutputDex>
<IntermediateRuntimeOutputPath>$(IntermediateOutputPath)release-net6</IntermediateRuntimeOutputPath>
<IntermediateRuntimeClassesTxt>$(IntermediateOutputPath)release-net6.txt</IntermediateRuntimeClassesTxt>
<RemoveItems>..\..\src-ThirdParty\bazel\java\mono\android\debug\MultiDexLoader.java;java\mono\android\debug-net6\BuildConfig.java;java\mono\android\debug\BuildConfig.java;java\mono\android\release\BuildConfig.java</RemoveItems>
</_RuntimeOutput>
<_RuntimeOutput Include="$(OutputPath)java_runtime_fastdev_net6.jar">
<OutputJar>$(OutputPath)java_runtime_fastdev_net6.jar</OutputJar>
<OutputDex>$(OutputPath)java_runtime_fastdev_net6.dex</OutputDex>
<IntermediateRuntimeOutputPath>$(IntermediateOutputPath)fastdev-net6</IntermediateRuntimeOutputPath>
<IntermediateRuntimeClassesTxt>$(IntermediateOutputPath)fastdev-net6.txt</IntermediateRuntimeClassesTxt>
<RemoveItems>..\..\src-ThirdParty\bazel\java\mono\android\release\MultiDexLoader.java;java\mono\android\release-net6\BuildConfig.java;java\mono\android\release\BuildConfig.java;java\mono\android\debug\BuildConfig.java</RemoveItems>
</_RuntimeOutput>
</ItemGroup>

Expand Down
16 changes: 9 additions & 7 deletions src/java-runtime/java/mono/android/MonoPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ public static void LoadApplication (Context context, ApplicationInfo runtimePack
}
System.loadLibrary("xamarin-app");

// .net5+ APKs don't contain `libmono-native.so` but we can't just perform a file existence check
// because we might be running with embedded DSOs enabled in which case the check would fail and we
// would have to catch the exception anyway in this case.
try {
System.loadLibrary("mono-native");
} catch (java.lang.UnsatisfiedLinkError ex) {
Log.i ("monodroid", "Failed to preload libmono-native.so (may not exist), ignoring", ex);
if (!BuildConfig.DotNetRuntime) {
// .net5+ APKs don't contain `libmono-native.so` but we can't just perform a file existence check
// because we might be running with embedded DSOs enabled in which case the check would fail and we
// would have to catch the exception anyway in this case.
try {
System.loadLibrary("mono-native");
} catch (java.lang.UnsatisfiedLinkError ex) {
Log.i ("monodroid", "Failed to preload libmono-native.so (may not exist), ignoring", ex);
}
}

System.loadLibrary("monodroid");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mono.android;

public class BuildConfig {
public static boolean Debug = true;
public static boolean DotNetRuntime = true;
}
1 change: 1 addition & 0 deletions src/java-runtime/java/mono/android/debug/BuildConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class BuildConfig {
public static boolean Debug = true;
public static boolean DotNetRuntime = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mono.android;

public class BuildConfig {
public static boolean Debug = false;
public static boolean DotNetRuntime = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class BuildConfig {
public static boolean Debug = false;
public static boolean DotNetRuntime = false;
}

0 comments on commit 1270c68

Please sign in to comment.