Skip to content

Commit 4742d50

Browse files
authored
[java-runtime, build] Use r8.jar instead of dx (dotnet#4777)
`dx` doesn't like OpenJDK 11 on Windows: "C:\Users\dlab14\android-toolchain\sdk\build-tools\29.0.2\dx" --dex --no-strict --output="C:\A\vs2019xam00000H-1\_work\2\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\java_runtime.dex" "C:\A\vs2019xam00000H-1\_work\2\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\java_runtime.jar" ##[debug]Processed: ##vso[task.logdetail id=dffb25d4-cb0b-4e58-94d2-4b9a4f215bed;parentid=;name=EXEC;type=Build;starttime=2020-04-19T01:21:10.0332656Z;state=InProgress;] ##[error]EXEC(0,0): Error : No suitable Java found. In order to properly use the Android Developer ##[debug]Processed: ##vso[task.logissue type=Error;sourcepath=EXEC;linenumber=0;columnnumber=0;code=;]No suitable Java found. In order to properly use the Android Developer ##[debug]Processed: ##vso[task.logdetail id=dffb25d4-cb0b-4e58-94d2-4b9a4f215bed;parentid=;type=Build;result=Failed;finishtime=2020-04-19T01:21:10.0488457Z;progress=100;state=Completed;parentid=;name=;] EXEC : error : No suitable Java found. In order to properly use the Android Developer [C:\A\vs2019xam00000H-1\_work\2\s\src\java-runtime\java-runtime.csproj] Tools, you need a suitable version of Java JDK installed on your system. We recommend that you install the JDK version of JavaSE, available here: http://www.oracle.com/technetwork/java/javase/downloads If you already have Java installed, you can define the JAVA_HOME environment variable in Control Panel / System / Avanced System Settings to point to the JDK folder. You can find the complete Android SDK requirements here: http://developer.android.com/sdk/requirements.html ##[error]src\java-runtime\java-runtime.targets(59,3): Error MSB3073: The command ""C:\Users\dlab14\android-toolchain\sdk\build-tools\29.0.2\dx" --dex --no-strict --output="C:\A\vs2019xam00000H-1\_work\2\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\java_runtime.dex" "C:\A\vs2019xam00000H-1\_work\2\s\bin\Release\lib\xamarin.android\xbuild\Xamarin\Android\java_runtime.jar"" exited with code -1. Use `r8.jar` instead of `dx` *everywhere*, to avoid the problem.
1 parent c8ab455 commit 4742d50

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

build-tools/scripts/JavaCallableWrappers.targets

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@
5353
AfterTargets="GenerateJavaCallableWrappers"
5454
Inputs="$(OutputPath)mono.android.jar"
5555
Outputs="$(OutputPath)mono.android.dex">
56+
<PropertyGroup>
57+
<R8JarPath>$(XAInstallPrefix)xbuild\Xamarin\Android\r8.jar</R8JarPath>
58+
</PropertyGroup>
5659
<Exec
57-
Command="&quot;$(AndroidSdkDirectory)\build-tools\$(XABuildToolsFolder)\dx&quot; --dex --no-strict --output=&quot;$(OutputPath)mono.android.dex&quot; &quot;$(OutputPath)mono.android.jar&quot;"
60+
Command="&quot;$(JavaPath)&quot; -classpath &quot;$(R8JarPath)&quot; com.android.tools.r8.D8 --release --no-desugaring --output &quot;$(IntermediateOutputPath.TrimEnd('\'))&quot; &quot;$(OutputPath)mono.android.jar&quot;"
5861
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory)"
5962
/>
63+
<Move
64+
SourceFiles="$(IntermediateOutputPath)\classes.dex"
65+
DestinationFiles="$(OutputPath)mono.android.dex"
66+
/>
6067
</Target>
6168
</Project>

src/Mono.Android/Mono.Android.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
<ProjectReference Include="..\..\external\Java.Interop\tools\generator\generator.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472"/>
353353
<ProjectReference Include="..\..\external\Java.Interop\tools\jcw-gen\jcw-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472" />
354354
<ProjectReference Include="..\..\src\java-runtime\java-runtime.csproj" ReferenceOutputAssembly="false" />
355+
<ProjectReference Include="..\r8\r8.csproj" ReferenceOutputAssembly="False" />
355356
</ItemGroup>
356357

357358
<!--NOTE: a workaround for the test runner in VS Windows-->

src/OpenTK-1.0/OpenTK.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,5 +614,6 @@
614614
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
615615
<Private>False</Private>
616616
</ProjectReference>
617+
<ProjectReference Include="..\r8\r8.csproj" ReferenceOutputAssembly="False" />
617618
</ItemGroup>
618619
</Project>

src/java-runtime/java-runtime.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
1515
<OutputPath>$(XAInstallPrefix)xbuild\Xamarin\Android</OutputPath>
1616
</PropertyGroup>
17+
<ItemGroup>
18+
<ProjectReference Include="..\r8\r8.csproj" ReferenceOutputAssembly="False" />
19+
</ItemGroup>
1720
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets" />
1821
<ItemGroup>
1922
<AllRuntimeSource Include="java/mono/**/*.java" />

src/java-runtime/java-runtime.targets

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

4+
<PropertyGroup>
5+
<BuildDependsOn>
6+
ResolveReferences;
7+
_BuildJavaRuntimeJar;
8+
</BuildDependsOn>
9+
<CleanDependsOn>
10+
_CleanJavaRuntimeJar;
11+
</CleanDependsOn>
12+
</PropertyGroup>
13+
414
<ItemGroup>
515
<_RuntimeOutput Include="$(OutputPath)java_runtime.jar">
616
<OutputJar>$(OutputPath)java_runtime.jar</OutputJar>
@@ -17,7 +27,11 @@
1727
<RemoveItems>java\mono\android\release\MultiDexLoader.java;java\mono\android\release\BuildConfig.java</RemoveItems>
1828
</_RuntimeOutput>
1929
</ItemGroup>
20-
<Target Name="Build"
30+
31+
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" />
32+
<Target Name="Clean" DependsOnTargets="$(CleanDependsOn)" />
33+
34+
<Target Name="_BuildJavaRuntimeJar"
2135
Inputs="@(AllRuntimeSource)"
2236
Outputs="%(_RuntimeOutput.OutputJar)"
2337
>
@@ -57,8 +71,17 @@
5771
Inputs="@(_RuntimeOutput->'%(Identity)')"
5872
Outputs="@(_RuntimeOutput->'%(OutputDex)')">
5973
<Exec
60-
Command="&quot;$(AndroidSdkDirectory)\build-tools\$(XABuildToolsFolder)\dx&quot; --dex --no-strict --output=&quot;%(_RuntimeOutput.OutputDex)&quot; &quot;%(_RuntimeOutput.OutputJar)&quot;"
74+
Command="&quot;$(JavaPath)&quot; -classpath &quot;$(OutputPath)\r8.jar&quot; com.android.tools.r8.D8 --release --no-desugaring --output &quot;%(_RuntimeOutput.IntermediateRuntimeOutputPath)&quot; &quot;%(_RuntimeOutput.OutputJar)&quot;"
6175
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory)"
6276
/>
77+
<Move
78+
SourceFiles="@(_RuntimeOutput->'%(IntermediateRuntimeOutputPath)\classes.dex')"
79+
DestinationFiles="%(_RuntimeOutput.OutputDex)"
80+
/>
6381
</Target>
82+
83+
<Target Name="_CleanJavaRuntimeJar">
84+
<Delete Files="%(_RuntimeOutput.OutputJar)" />
85+
</Target>
86+
6487
</Project>

src/manifestmerger/manifestmerger.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<PropertyGroup Condition="'$(Configuration)'=='Debug'" />
1010
<PropertyGroup Condition="'$(Configuration)'=='Release'" />
1111
<Import Project="..\..\Configuration.props" />
12+
<ItemGroup>
13+
<ProjectReference Include="..\r8\r8.csproj">
14+
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
15+
</ProjectReference>
16+
</ItemGroup>
1217
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets" />
1318
<Import Project="manifestmerger.targets" />
1419
</Project>

0 commit comments

Comments
 (0)