Skip to content

Commit 3470539

Browse files
jonpryorradekdoulik
authored andcommitted
[build] Generate $(JdkBinPath)` property
We're trying to build xamarin-android on a VSTS macOS instance which has multiple Java JDKs installed, including JDK 9. The problem is that the Android SDK and JDK 9 don't get along. The `xamarin-android/tests/CodeGen-Binding/Xamarin.Android.LibraryProjectZip-LibBinding` build invokes `gradlew`, `gradlew` uses whatever `java` is in `$PATH`, and when using JDK 9 `gradlew` fails: Executing: ./gradlew assembleDebug --stacktrace ... org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':library'. ... Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener. ... Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema ... Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema (Rephrased: JDK 9 removed the type `javax.xml.bind.annotation.XmlSchema`, which broke some dependency.) 55c56f7 was an attempt to support this environment, by *allowing* JDK 9 to be filtered out when computing `$(JdkJvmPath)`, `$(JavaCPath)`, and `$(JarPath)`. Unfortunately this was inadequate: we need to override `$PATH` so that the "right" JDK is used, not whatever happens to be first in `$PATH`. In manual testing, this fails: ANDROID_HOME=... ./gradlew assembleDebug --stacktrace while this works: ANDROID_HOME=... PATH=/path/to/jdk8/bin:$PATH ./gradlew assembleDebug --stacktrace --no-daemon (The `--no-daemon` is needed so that we don't use some previously launched gradle daemon under the wrong JDK.) Thus, we want a way to easily insert the appropriate JDK path into `$PATH` for the `gradlew` command. Export a new `$(JdkBinPath)` MSBuild property which contains the JDK `bin` directory. This will allow us to fix the `Xamarin.Android.LibraryProjectZip-LibBinding` project: <Exec EnvironmentVariables="ANDROID_HOME=$(AndroidSdkDirectory)" Command="PATH=$(JdkBinPath):%24PATH .\gradlew assembleDebug --stacktrace --no-daemon" WorkingDirectory="$(MSBuildThisFileDirectory)java\JavaLib" /> and (hopefully) allow us to build on our VSTS bot which contains both JDK 8 and 9.
1 parent 449e5de commit 3470539

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

build-tools/scripts/jdk.mk

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
# It DOES NOT contain the -I itself; use $(JI_JDK_INCLUDE_PATHS:%=-I%) for that.
2323
# $(JI_JVM_PATH):
2424
# Location of the Java native library that contains e.g. JNI_CreateJavaVM().
25+
# $(JI_JDK_BIN_PATH):
26+
# Location of the JDK `/bin` directory, which contains `java/`javac`/etc.
2527

2628
OS ?= $(shell uname)
2729
JI_JAVAC_PATH = javac
2830
JI_JAR_PATH = jar
2931

32+
JI_JDK_BIN_PATH = $(dir $(shell which java))
33+
3034

3135
# Filter on <= JI_MAX_JDK
3236
ifneq ($(JI_MAX_JDK),)
@@ -75,14 +79,15 @@ _APPLE_JDK6_URL = http://adcdownload.apple.com/Developer_Tools
7579

7680
ifneq ($(_DARWIN_JDK_FALLBACK_DIRS),)
7781
_DARWIN_JDK_ROOT := $(shell ls -dtr $(_DARWIN_JDK_FALLBACK_DIRS) | $(_VERSION_SORT))
82+
JI_JDK_BIN_PATH = $(_DARWIN_JDK_ROOT)/Contents/Home/bin
7883
JI_JAVAC_PATH = $(_DARWIN_JDK_ROOT)/Contents/Home/bin/javac
7984
JI_JAR_PATH = $(_DARWIN_JDK_ROOT)/Contents/Home/bin/jar
8085
JI_JDK_INCLUDE_PATHS = \
8186
$(_DARWIN_JDK_ROOT)/$(_DARWIN_JDK_JNI_INCLUDE_DIR) \
8287
$(_DARWIN_JDK_ROOT)/$(_DARWIN_JDK_JNI_OS_INCLUDE_DIR)
8388

8489
ifeq ($(_MONO_BITNESS),64-bit)
85-
JI_JVM_PATH = $(_DARWIN_JDK_ROOT)/Contents/Home/jre/lib/jli/libjli.dylib
90+
JI_JVM_PATH = $(shell find $(_DARWIN_JDK_ROOT)/Contents/Home -name libjli.dylib)
8691
endif # 64-bit
8792

8893
else # (1) failed; try Xcode.app's copy?
@@ -143,6 +148,7 @@ JI_JVM_PATH = $(_LINUX_JAVA_ROOT)/jre/lib/$(_LINUX_JAVA_ARCH_32)
143148
endif # (2)
144149
endif # (1)
145150

151+
JI_JDK_BIN_PATH = $(_LINUX_JAVA_ROOT)/bin
146152
JI_JAVAC_PATH = $(_LINUX_JAVA_ROOT)/bin/javac
147153
JI_JAR_PATH = $(_LINUX_JAVA_ROOT)/bin/jar
148154

@@ -169,6 +175,7 @@ bin/Build$(CONFIGURATION)/JdkInfo.props: $(JI_JDK_INCLUDE_PATHS) $(JI_JVM_PATH)
169175
echo ' </When>' >> "$@"
170176
echo ' </Choose>' >> "$@"
171177
echo ' <PropertyGroup>' >> "$@"
178+
echo " <JdkBinPath Condition=\" '\$$(JdkBinPath)' == '' \">$(JI_JDK_BIN_PATH)</JdkBinPath>" >> "$@"
172179
echo " <JavaCPath Condition=\" '\$$(JavaCPath)' == '' \">$(JI_JAVAC_PATH)</JavaCPath>" >> "$@"
173180
echo " <JarPath Condition=\" '\$$(JarPath)' == '' \">$(JI_JAR_PATH)</JarPath>" >> "$@"
174181
echo ' </PropertyGroup>' >> "$@"

0 commit comments

Comments
 (0)