On android, jni/CMakeLists.txt looks for a JDK without REQUIRED since #629:
if (ANDROID)
find_package(Java 11 COMPONENTS Development)
else ()
find_package(Java 11 REQUIRED COMPONENTS Development)
find_package(JNI REQUIRED)
endif ()
...
install(TARGETS odr_jni LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT jni)
if (NOT Java_FOUND)
return()
endif ()
So a build machine with no javac on PATH and no JAVA_HOME configures, compiles
and installs happily, and produces a package with libodr_jni.so and no
odr-core-java.jar — even though the option that was asked for is with_jni=True,
and the comment right above says the android odrcore package "ships
odr-core-java.jar next to libodr_jni.so and OpenDocument.droid takes both out of
it".
It bit me bumping OpenDocument.droid to 6.1.0. The conan build succeeded, and the
failure surfaced much later and somewhere else:
FileNotFoundError: [Errno 2] No such file or directory:
'~/.conan2/p/b/odrcod31d961a414ad/p/share/java/odr-core-java.jar'
ERROR: [Errno 2] No such file or directory: ...
Execution failed for task ':app:conanInstall-armv8'
which reads like a broken deployer rather than "your build environment has no JDK,
so half the package is missing". Rebuilding with JAVA_HOME exported fixed it. On
6.0.1 the same environment failed at configure time with a clear
Could NOT find Java, which was the better outcome.
The reason to relax it doesn't seem to cover the jar. What android cannot do is
find_package(JNI) — the NDK sysroot ships jni.h and the symbols come from the
runtime — and the AAR build doesn't need the jar because android/build_native.py
asks for --target odr_jni only, so it never reaches add_jar anyway. Java itself
is as findable on an android build as on any other.
Two ways out, either is fine by me:
- keep
find_package(Java 11 REQUIRED COMPONENTS Development) unconditional and only
put find_package(JNI REQUIRED) behind if (NOT ANDROID). android/build_native.py
runs under gradle, which has a JDK by definition.
- or make it explicit with an option, e.g.
ODR_JNI_JAR defaulting to ON, REQUIRED
when it is on, and set to OFF by the AAR build. Then "no jar" is something a caller
asked for rather than something the environment decided.
Happy to send a PR for whichever you prefer.
On android,
jni/CMakeLists.txtlooks for a JDK withoutREQUIREDsince #629:So a build machine with no
javaconPATHand noJAVA_HOMEconfigures, compilesand installs happily, and produces a package with
libodr_jni.soand noodr-core-java.jar— even though the option that was asked for iswith_jni=True,and the comment right above says the android odrcore package "ships
odr-core-java.jarnext tolibodr_jni.soand OpenDocument.droid takes both out ofit".
It bit me bumping OpenDocument.droid to 6.1.0. The conan build succeeded, and the
failure surfaced much later and somewhere else:
which reads like a broken deployer rather than "your build environment has no JDK,
so half the package is missing". Rebuilding with
JAVA_HOMEexported fixed it. On6.0.1 the same environment failed at configure time with a clear
Could NOT find Java, which was the better outcome.The reason to relax it doesn't seem to cover the jar. What android cannot do is
find_package(JNI)— the NDK sysroot shipsjni.hand the symbols come from theruntime — and the AAR build doesn't need the jar because
android/build_native.pyasks for
--target odr_jnionly, so it never reachesadd_jaranyway. Java itselfis as findable on an android build as on any other.
Two ways out, either is fine by me:
find_package(Java 11 REQUIRED COMPONENTS Development)unconditional and onlyput
find_package(JNI REQUIRED)behindif (NOT ANDROID).android/build_native.pyruns under gradle, which has a JDK by definition.
ODR_JNI_JARdefaulting toON,REQUIREDwhen it is on, and set to
OFFby the AAR build. Then "no jar" is something a callerasked for rather than something the environment decided.
Happy to send a PR for whichever you prefer.