我可以在 Gluon Mobile 中使用最近的 Java 8 对 Android 的支持吗?

Can I use the recent Java 8 support for Android with Gluon Mobile?

Google 几个月前发布了一个 gradle 插件,用于 java 8 支持 Android API 24 级及以上。这是通过将依赖项添加到 gradle 构建文件来实现的:

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

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

Gluon Mobile 支持吗?

我已经安装了构建工具 25.0.3,并且 Gluon 插件在单视图项目上生成的 build.gradle 文件没有任何修改:

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.**.*'
        ]
    }
} 

我可以包含 Java 8 个流:

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 运行 Desktop 上的项目并将其部署并 运行 在 Android 上成功部署(至少在我的 Android 7.1.1 设备上)。显然不在 iOS.

jfxmobile 插件已经在寻找您在 $AndroidSdk/build-tools 安装的最新构建工具版本。如果你想设置一些选项,你可以设置:

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

        buildToolsVersion = '25.0.3'
        compileSdkVersion = '25'
        minSdkVersion = '25'
        targetSdkVersion = '25'
    }
}