Skip to content

android: with_jni silently ships no odr-core-java.jar when no JDK is on the build machine #637

Description

@andiwand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions