Search code examples
javainstall4j

install4J, how to correctly pass `updatesUrl` to the updater via the Java preference store?


I am trying to implement multi-channels (deb/beta/stable) update for my app following recommendation made in another SO post.

I have done the following steps:

  1. create a compiler variable mediaID=${compiler:sys.mediaId}
  2. when user of my app changes it release channel preference, the ollowing function is called: mediaID = Variables.getCompilerVariable("mediaID"); Variables.saveToPreferenceStore(Map.of("updatesUrl", xmlURL), mediaID, true);
  3. when user decide to update the following function is called: ApplicationLauncher.launchApplicationInProcess(UPDATER_APPLICATION_ID, null, ....) but this throws an error (exit value = 1):

enter image description here

Based on the error message, it seems that the updater does not find the updatesUrl variable but just before the call to the function I logged the output of com.install4j.api.launcher.Variables.loadFromPreferenceStore(mediaID, true); and I got as a result {updatesUrl=https://github.com/akasolace/HO/releases/download/dev/updatesDEV.xml} which is the legit URL, so it seems updatesUrl was properly stored.

Now, I am a bit confused on how this should work. Me for example, I am running 2 version of the app in parralel and my setup is something like:

  • mediaID 1, release channel Stable
  • mediaID 2, release channel Dev

on my system I will have variable updatesUrl store in 2 differents package something like:

{(1, "updatesUrl"): "...updatesSTABLE.xml", (2, "updatesUrl"): "...updatesDEV.xml"}

Now, in install4J, I added the action "Load installer variable from the Java preference store" and I see package name default to ${compiler:sys.applicationId. This leads to the following question:

  • I believe applicationID unique for the app and mediaID different for each media. To achieve what I want I believe I need the updater to use as package name, the media ID of the media that called it. I mean if the updater is called from media ID x , I need it to look at the variable "updatesUrl" from package x. Is it doable or am I getting lost?

[Edit] I tried to set package name of "Load installer variable from the Java preference store" to ${compiler:sys.mediaId but this throws instead

enter image description here Thank you in advance for your help.

with the following stack trace

    java.lang.NullPointerException
 com.install4j.runtime.installer.Application.runApplicationInProcess(Application.java:64)
com.install4j.runtime.installer.helper.apiimpl.ApplicationLauncherImpl$1.run(ApplicationLauncherImpl.java:57)

Solution

  • Calling com.install4j.api.launcher.Variables.loadFromPreferenceStore does not set installer variables, it returns a map with the variable values. This is intended for use in your application.

    What you have to do is to add a "Load installer variables from the Java preference store" action to the "Startup" node in in the update downloader. In that way, the updatesUrl installer variable is actually set to the value from the preference store.