You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX项目Gradle构建成功但无APK输出,求解决方案

JavaFX构建APK成功但无输出,Gradle配置问题排查

问题背景

用IntelliJ开发JavaFX应用,尝试通过Gradle构建APK部署到Android虚拟机。执行./gradlew build显示构建成功,但未生成输出目录及APK文件,命令输出如下:

Configure project : Project : => no module-info.java found
BUILD SUCCESSFUL in 906ms 6 actionable tasks: 6 up-to-date

尝试过的命令及错误:

  • 执行./gradlew client:built失败:

    根项目中未找到'client'项目。

  • 执行./gradlew assembleDebug失败:

    根项目中未找到'assembleDebug'任务。

当前build.gradle配置代码:

buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://nexus.gluonhq.com/nexus/content/repositories/releases'
        }
    }
    dependencies {
        classpath 'com.gluonhq:client-gradle-plugin:0.1.36'
        classpath "com.android.tools.build:gradle:0.12.2"
    }
}

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.25.0'
}

apply plugin: 'com.gluonhq.client-gradle-plugin'

group 'com.example'
version '1.0-SNAPSHOT'

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

ext {
    javafxVersion = '11'
    gluonMobileVersion = '6.0.6'
    gluonAttachVersion = '4.0.12'
    junitVersion = '5.8.2'
}

sourceCompatibility = '11'
targetCompatibility = '11'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'com.example.cocktailmakergradle'
    mainClass = 'com.example.cocktailmakergradle.CocktailAppRun'
}

javafx {
    version = javafxVersion
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.media']
}

dependencies {
    implementation "org.openjfx:javafx-controls:${javafxVersion}"
    implementation "org.openjfx:javafx-fxml:${javafxVersion}"
    implementation "org.openjfx:javafx-media:${javafxVersion}"
    implementation "com.gluonhq:charm-glisten:${gluonMobileVersion}"
    implementation "com.gluonhq.attach:util:${gluonAttachVersion}"
    implementation "com.gluonhq.attach:storage:${gluonAttachVersion}"
    // Ajoutez d'autres dépendances Attach si nécessaire
    // Ajout des dépendances Gluon Mobile
    implementation "com.gluonhq.attach:display:${gluonAttachVersion}"
    implementation "com.gluonhq.attach:lifecycle:${gluonAttachVersion}"
    implementation "com.gluonhq.attach:statusbar:${gluonAttachVersion}"
    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

test {
    useJUnitPlatform()
}

jlink {
    imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
    launcher {
        name = 'app'
    }
}

jlinkZip {
    group = 'distribution'
}

gluonClient {
    target = 'android'
}

解决方案

1. 修正构建命令

Gluon Client Gradle插件在单项目结构下的核心构建任务是clientBuild,而非client:built(该命名适用于多项目结构)。执行正确的构建命令:

./gradlew clientBuild

构建成功后,APK文件会生成在build/client/android/x86_64/release(或对应架构的目录)下。

2. 升级Gluon Client插件版本

当前使用的0.1.36版本过旧,存在任务命名、兼容性等问题,建议升级到较新的稳定版本(例如0.1.56),修改buildscript中的依赖配置:

classpath 'com.gluonhq:client-gradle-plugin:0.1.56'

3. 修复模块配置冲突

命令输出提示no module-info.java found,但application块中设置了mainModule,需根据项目类型调整:

  • 模块化项目:在src/main/java下添加module-info.java,声明模块依赖:
    module com.example.cocktailmakergradle {
        requires javafx.controls;
        requires javafx.fxml;
        requires javafx.media;
        requires com.gluonhq.charm.glisten;
        requires com.gluonhq.attach.util;
        requires com.gluonhq.attach.storage;
        requires com.gluonhq.attach.display;
        requires com.gluonhq.attach.lifecycle;
        requires com.gluonhq.attach.statusbar;
        exports com.example.cocktailmakergradle;
    }
    
  • 非模块化项目:移除application块中的mainModule配置,仅保留mainClass:
    application {
        mainClass = 'com.example.cocktailmakergradle.CocktailAppRun'
    }
    

4. 清理不必要的插件与依赖

Gluon Client插件已内置JavaFX支持,无需同时使用org.openjfx.javafxplugin,可移除该插件及对应的javafx块配置,避免依赖冲突。

5. 确保Android SDK配置正确

如果构建时提示Android SDK未找到,可在gluonClient块中手动指定SDK路径:

gluonClient {
    target = 'android'
    androidSdk = file('/path/to/your/android/sdk') // 替换为实际路径,或使用环境变量
}

也可确保系统环境变量ANDROID_HOME已正确设置。

内容的提问来源于stack exchange,提问作者Terry Vitanza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 05:29:53