Skip to content

Commit dcee2c8

Browse files
authored
[build] JavacSourceVersion JavacTargetVersion Harmonization (#4771)
Context: #4567 In order to support using JDK 11 to build Xamarin.Android, we need to consistently use `javac -source 1.8 -target 1.8` ~everywhere, because we also require `javac --boot-class-path`, and JDK11 doesn't support `javac --boot-class-path` unless targeting < JDK 1.9: % javac --boot-class-path ~/android-toolchain/sdk/platforms/android-29/android.jar Example.java error: option --boot-class-path not allowed with target 11 The `<Javac/>` task use `javac --boot-class-path` to compile Java code, so that Android's `android.jar` provides everything: Task "Javac" (TaskId:154) Task Parameter:JavaPlatformJarPath=/Users/runner/Library/Android/sdk/platforms/android-29/android.jar Task Parameter:ClassesOutputDirectory=obj/Release/android/bin/classes/ Task Parameter:ClassesZip=obj/Release/android/bin/classes.zip Task Parameter:StubSourceDirectory=obj/Release/android/src/ Task Parameter:ToolPath=/Users/runner/Library/Android/jdk/bin Task Parameter: Jars= /Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v10.0/mono.android.jar /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/java_runtime.jar /Users/runner/Library/Android/jdk/bin/javac -J-Dfile.encoding=UTF8 "@/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/tmp2eba46d8.tmp" JAVAC : error : option --boot-class-path not allowed with target 11 The command exited with code 2. (TaskId:154) Harmonize provisioning of `javac -source` and `javac -target` values: * Add `$(JavacSourceVersion)` and `$(JavacTargetVersion)` MSBuild properties to `Configuration.props`. * Update the `src/manifestmerger` and `src/r8` builds so that `$(JavacSourceVersion)` and `$(JavacTargetVersion)` are used to control the `.class` files that they create. * Update `build-tools/scripts/Jar.targets` to use the values from `Configuration.props`, instead of separate values. * Fix errant invocations of `javac -target $(JavacSourceVersion)`, which should be `javac -target $(JavacTargetVersion)`.
1 parent d99facb commit dcee2c8

File tree

9 files changed

+28
-9
lines changed

9 files changed

+28
-9
lines changed

Configuration.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@
117117
<MingwCommandPrefix32>i686-w64-mingw32</MingwCommandPrefix32>
118118
<MingwCommandPrefix64>x86_64-w64-mingw32</MingwCommandPrefix64>
119119
</PropertyGroup>
120+
<PropertyGroup>
121+
<JavacSourceVersion>1.8</JavacSourceVersion>
122+
<JavacTargetVersion>1.8</JavacTargetVersion>
123+
</PropertyGroup>
120124
<PropertyGroup>
121125
<AndroidMxeFullPath Condition=" '$(AndroidMxeInstallPrefix)' != '' ">$([System.IO.Path]::GetFullPath ('$(AndroidMxeInstallPrefix)'))</AndroidMxeFullPath>
122126
<AndroidNdkFullPath>$([System.IO.Path]::GetFullPath ('$(AndroidNdkDirectory)'))</AndroidNdkFullPath>

build-tools/scripts/Jar.targets

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
<Target Name="_GetJavacVersions"
44
DependsOnTargets="AndroidPrepareForBuild">
55
<PropertyGroup>
6-
<_JavacSourceVersion Condition="$(_JdkVersion.StartsWith ('9'))">1.8</_JavacSourceVersion>
7-
<_JavacSourceVersion Condition=" '$(_JavacSourceVersion)' == '' ">1.5</_JavacSourceVersion>
8-
<_JavacTargetVersion Condition="$(_JdkVersion.StartsWith ('9'))">1.8</_JavacTargetVersion>
9-
<_JavacTargetVersion Condition=" '$(_JavacTargetVersion)' == '' ">1.6</_JavacTargetVersion>
106
<JarPath Condition=" '$(JarPath)' == '' ">$(JavaSdkDirectory)\bin\jar</JarPath>
117
<JavaCPath Condition=" '$(JavaCPath)' == '' ">$(JavaSdkDirectory)\bin\javac</JavaCPath>
128
</PropertyGroup>
@@ -35,7 +31,7 @@
3531
<PropertyGroup>
3632
<_Javac>"$(JavaCPath)"</_Javac>
3733
<_Jar>"$(JarPath)"</_Jar>
38-
<_Targets>-source $(_JavacSourceVersion) -target $(_JavacTargetVersion)</_Targets>
34+
<_Targets>-source $(JavacSourceVersion) -target $(JavacTargetVersion)</_Targets>
3935
<_DestDir>$(IntermediateOutputPath)__CreateTestJarFile-bin</_DestDir>
4036
<_AndroidJar>-bootclasspath "$(AndroidSdkDirectory)\platforms\android-$(_AndroidApiLevelName)\android.jar"</_AndroidJar>
4137
<_CP>-cp "$(_JavaInteropJarPath)"</_CP>

build-tools/scripts/JavaCallableWrappers.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Overwrite="True"
3232
/>
3333
<PropertyGroup>
34-
<_Target>-source $(JavacSourceVersion) -target $(JavacSourceVersion)</_Target>
34+
<_Target>-source $(JavacSourceVersion) -target $(JavacTargetVersion)</_Target>
3535
<_D>-d "$(IntermediateOutputPath)jcw\bin"</_D>
3636
<_AndroidJar>"$(AndroidToolchainDirectory)\sdk\platforms\android-$(AndroidPlatformId)\android.jar"</_AndroidJar>
3737
<_MonoAndroidJar>$(OutputPath)mono.android.jar</_MonoAndroidJar>

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.props.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<BundleToolVersion Condition="'$(BundleToolVersion)' == ''">@BUNDLETOOL_VERSION@</BundleToolVersion>
2222
<_XamarinAndroidMSBuildDirectory>$(MSBuildThisFileDirectory)</_XamarinAndroidMSBuildDirectory>
2323

24+
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">1.8</JavacSourceVersion>
25+
<JavacTargetVersion Condition=" '$(JavacTargetVersion)' == '' ">1.8</JavacTargetVersion>
26+
2427
<!-- Enable nuget package conflict resolution -->
2528
<ResolveAssemblyConflicts>true</ResolveAssemblyConflicts>
2629
</PropertyGroup>

src/java-runtime/java-runtime.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
Overwrite="True"
3434
/>
3535
<PropertyGroup>
36-
<_Target Condition="'$(JavacSourceVersion)' != ''">-source $(JavacSourceVersion) -target $(JavacSourceVersion)</_Target>
36+
<_Target Condition="'$(JavacSourceVersion)' != ''">-source $(JavacSourceVersion) -target $(JavacTargetVersion)</_Target>
3737
<_AndroidJar>"$(AndroidToolchainDirectory)\sdk\platforms\android-$(AndroidFirstPlatformId)\android.jar"</_AndroidJar>
3838
</PropertyGroup>
3939
<Exec

src/manifestmerger/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ plugins {
22
id 'java-library'
33
}
44

5+
java {
6+
ext.javaSourceVer = project.hasProperty('javaSourceVer') ? JavaVersion.toVersion(project.getProperty('javaSourceVer')) : JavaVersion.VERSION_1_8
7+
ext.javaTargetVer = project.hasProperty('javaTargetVer') ? JavaVersion.toVersion(project.getProperty('javaTargetVer')) : JavaVersion.VERSION_1_8
8+
9+
sourceCompatibility = ext.javaSourceVer
10+
targetCompatibility = ext.javaTargetVer
11+
}
12+
513
repositories {
614
maven { url 'https://maven.google.com' }
715
mavenCentral()

src/manifestmerger/manifestmerger.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Inputs="$(MSBuildThisFile);build.gradle"
1818
Outputs="$(_Destination)">
1919
<Exec
20-
Command="&quot;$(GradleWPath)&quot; build $(GradleArgs)"
20+
Command="&quot;$(GradleWPath)&quot; build $(GradleArgs) -PjavaSourceVer=$(JavacSourceVersion) -PjavaTargetVer=$(JavacTargetVersion)"
2121
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)"
2222
WorkingDirectory="$(MSBuildThisFileDirectory)"
2323
/>

src/r8/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
apply plugin: 'java'
22
apply plugin: 'idea'
33

4+
java {
5+
ext.javaSourceVer = project.hasProperty('javaSourceVer') ? JavaVersion.toVersion(project.getProperty('javaSourceVer')) : JavaVersion.VERSION_1_8
6+
ext.javaTargetVer = project.hasProperty('javaTargetVer') ? JavaVersion.toVersion(project.getProperty('javaTargetVer')) : JavaVersion.VERSION_1_8
7+
8+
sourceCompatibility = ext.javaSourceVer
9+
targetCompatibility = ext.javaTargetVer
10+
}
11+
412
// See: https://r8.googlesource.com/r8/+/refs/tags/1.6.82/build.gradle#55
513
repositories {
614
maven {

src/r8/r8.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Inputs="$(MSBuildThisFile);build.gradle"
1919
Outputs="$(_Destination)">
2020
<Exec
21-
Command="&quot;$(GradleWPath)&quot; jar $(GradleArgs)"
21+
Command="&quot;$(GradleWPath)&quot; jar $(GradleArgs) -PjavaSourceVer=$(JavacSourceVersion) -PjavaTargetVer=$(JavacTargetVersion)"
2222
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)"
2323
WorkingDirectory="$(MSBuildThisFileDirectory)"
2424
/>

0 commit comments

Comments
 (0)