1

Google released a few months ago a gradle plugin for java 8 support on Android API level 24 and up. This is achieved by adding the dependency to the gradle build file:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:2.4.0-alpha7'
    }
}

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Is this supported with Gluon Mobile?

Mark
  • 2,167
  • 4
  • 32
  • 64

1 Answers1

1

I have installed builds tools 25.0.3, and without any modification at all of the build.gradle file that the Gluon plugin generates on a Single View project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.8'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.gluonandroid24.GluonAndroid24'

dependencies {
    compile 'com.gluonhq:charm:4.3.7'
}

jfxmobile {
    downConfig {
        version = '3.6.0'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        plugins 'display', 'lifecycle', 'statusbar', 'storage'
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
} 

I can include Java 8 streams:

public BasicView(String name) {
    super(name);

    Label label = new Label("Hello JavaFX World!");

    Button button = new Button("Change the World!");
    button.setGraphic(new Icon(MaterialDesignIcon.LANGUAGE));
    button.setOnAction(e -> label.setText("Sum: " + Stream.of("1", "2", "5")
            .mapToInt(Integer::parseInt)
            .sum()));

    VBox controls = new VBox(15.0, label, button);
    controls.setAlignment(Pos.CENTER);

    controls.getChildren().stream()
            .filter(Label.class::isInstance)
            .forEach(System.out::println);

    setCenter(controls);
}

and run the project on Desktop and deploy it and run it successfully on Android (at least on my device with Android 7.1.1). Obviously not on iOS.

The jfxmobile plugin already looks for the latest build-tools version you have installed at $AndroidSdk/build-tools. In case you want to set some options, you could set:

jfxmobile {
    ...
    android {
        manifest = 'src/android/AndroidManifest.xml'

        buildToolsVersion = '25.0.3'
        compileSdkVersion = '25'
        minSdkVersion = '25'
        targetSdkVersion = '25'
    }
}
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • I see, thanks. BTW, there is a problem with the gluon plugin and eclipse (with Buildship) that won't let you Finish the new project wizard. Someone posted it [here](https://stackoverflow.com/questions/42953287/eclipse-gluon-new-project-does-not-finish) so if the problem is on gluon side maybe you should report it. – Mark Aug 31 '17 at 19:53
  • 1
    Thanks, it's a known issue: the new Buildship 2+ breaks the compatibility with Buildship 1.0.+, which is the one bundled with the plugin. It has already been reported. The solution for now is going back to Buildship 1. – José Pereda Aug 31 '17 at 19:55