I am trying to set up my Gluon project by putting platform/os specific code in their respective folder (The automatically created project set up in a newly created Gluon project). However no matter what task I do with Gradle it end up taking what is the Main
folder.
Lets say I want to have a com.gluonhq.charm.glisten.mvc.View
with a javafx.scene.control.Button
in it - and have it labeled differently by stating from which folder it came from (main, android, desktop or iOS). How would that be possible?
As a rule of thumb, you shouldn't require specific platform code in your project.
If what you want is custom styling based on the platform, you can use Platform.getCurrent().name()
and then react based on it.
For instance, the MyDevoxx
app loads different css files based on platform and type of device.
A good way to understand how the platform specific folders work is by having a look at the Charm Down library, and the implementation for the different services.
As you'll notice those folders contain both java and specific platform code.
A sample on how you can create a new service can be found here. For instance, the AndroidLogService
implementation makes use of android.util.Log
, while the IOSLogService
makes use of native Objective-C (see Log.m
). This native code has to be compiled as a native library (see installNativeLib
task in the build file).
In any case, the service is called from the main
package:
Services.get(LogService.class).ifPresent(service -> service.log(message));
When you deploy your application to a specific platform, only the implementation for that platform is called.
So if you need a new service you can create it following the design of those in Charm Down.