Explain how to set the Java version correctly
This is the sort of issue that could be resolved by documentation, but could also be addressed by tooling.
I've been trying to package up an app that requires JDK 17, following the instructions at https://f-droid.org/en/docs/Submitting_to_F-Droid_Quick_Start_Guide/, and have run in to the following problems.
First, there's no documentation I can find best practices for F-Droid and JDK 17. I ended up checking out other apps' .yml files, and
sudo:
- apt-get update
- apt-get install -y openjdk-17-jdk-headless
- update-java-alternatives -a --jre-headless
in the build:
portion appears to be the way to do it at the moment.
Second, if you run fdroid build
locally per the instructions this does not work, because (and it emits a warning about this), fdroid
skips the sudo
steps if it is not running on a build server.
You have to run those commands by hand, and you have to remember to do this every time you enter the docker container to check the build.
Third, there's some additional weirdness -- my local invocation of sudo update-java-alternatives
in the docker container requires the --jre-headless
flag, otherwise it fails with a jconsole
error. But other yml files in the F-Droid metadata don't have that flag. That makes me concerned that the build in the docker container is not a perfect match for what will happen when F-Droid tries to build this, and I lose confidence in the validity of the testing I'm doing.
Fourth, after running those commands by hand things still do not work. This is because the instructions (https://f-droid.org/en/docs/Submitting_to_F-Droid_Quick_Start_Guide/) tell you to:
. /etc/profile
export PATH="$fdroidserver:$PATH" PYTHONPATH="$fdroidserver"
export JAVA_HOME=$(java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | awk -F'=' '{print $2}' | tr -d ' ')
cd /build
fdroid readmeta
fdroid rewritemeta com.example
fdroid checkupdates --allow-dirty com.example
fdroid lint com.example
fdroid build com.example
after launching the container.
You either need to run the sudo
commands before the export JAVA_HOME
line, or you need to re-run that export after running the sudo commands.
I spent some time looking to see if there was an env:
block or similar I could add to the build recipe, but there isn't.
Also, the documentation about the different steps does not explain what, if anything, of the environment is preserved between the different steps. I experimented with prebuild
step that exported JAVA_HOME
, thinking that the environment might be preserved between steps, but it doesn't appear to be (or that didn't work for some other reason).
Suggestions:
- Ideally, setting the JDK version should be a first-class operation supported in the build language. For example, with GitHub actions I can specify a JDK version and distribution like so:
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
The action takes care of setting the Java symlinks, updating JAVA_HOME
for the rest of the build, and so on.
If that's not feasible then please update the docs to include a canonical "How to set the JDK version and distribution".
- Consider adding a flag to
fdroid
so it will run the commands in thesudo
block. - Please document the appropriate way to set environment variables in a build
I hope those are helpful.