我计划获取手机的IMEI,以便在我的应用程序中生成二维码或条形码。我在提问前已经检查过问题了。此外,我还查看了gluon移动文档以获取更多详细信息。但这似乎并没有解决我的问题。ispresent()中的代码块永远不会被执行。以下是我的代码
Services.get(DeviceService.class).ifPresent(deviceService -> {
label.setText("Modeld: "+"Test" );
label.setText("Model: "+ deviceService.getModel()+"\nSerial: "+ deviceService.getSerial());
});Build.gradles
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.16'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url
'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'fr.cashmag.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
jfxmobile {
downConfig {
version = '3.8.5'
// 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 = [
'fr.cashmag.**.*',
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}当我在真实设备上部署应用程序时,它似乎没有在logcat中显示任何错误
发布于 2019-01-30 19:25:34
如果你检查你的构建文件中的downConfig块,你会注意到你的应用程序正在使用的插件列表,或Charm Down服务:
jfxmobile {
downConfig {
version = '3.8.5'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
...
}jfxmobile正在为每个插件添加核心工件及其平台实现:
dependencies {
compile 'com.gluonhq:charm:5.0.2'
compile 'com.gluonhq:charm-down-plugin-display:3.8.5'
desktopCompile 'com.gluonhq:charm-down-plugin-display-desktop:3.8.5'
androidCompile 'com.gluonhq:charm-down-plugin-display-android:3.8.5'
iosCompile 'com.gluonhq:charm-down-plugin-display-ios:3.8.5'
...
}因为您也有charm,所以它在其他一些服务(如device )中具有传递依赖关系,但仅在核心构件中,因此您将添加:
dependencies {
compile 'com.gluonhq:charm:5.0.2'
compile 'com.gluonhq:charm-down-plugin-device:3.8.5'
...
compile 'com.gluonhq:charm-down-plugin-display:3.8.5'
desktopCompile 'com.gluonhq:charm-down-plugin-display-desktop:3.8.5'
androidCompile 'com.gluonhq:charm-down-plugin-display-android:3.8.5'
iosCompile 'com.gluonhq:charm-down-plugin-display-ios:3.8.5'
...
}这就是为什么你的项目可以使用DeviceService。
但是您没有添加该服务的平台实现。因此,当您在任何平台上运行时,Services.get(DeviceService.class).get()将为空。
在这种情况下,您需要做的就是将device插件添加到列表中:

您的构建将具有:
jfxmobile {
downConfig {
version = '3.8.6'
plugins 'device', 'display', 'lifecycle', 'statusbar', 'storage'
}
...
}请注意,您现在可以使用Charm Down 3.8.6。
https://stackoverflow.com/questions/54439106
复制相似问题