我最初编写了一个名为backendMethodCall
的函数来使用旧的python WSGI网关。一切正常,直到我决定检查胶子为Android移动设备开发一些东西。我在桌面上测试时使用代码成功调用远程服务器,但是当我使用androidInstall任务将应用程序安装到我的Android设备(LG G4,6.0)上并拨打电话时,应用程序崩溃。
我使用adb logcat > test_log
来获取以下错误:
12-28 12:50:42.513 12394 12415 E AndroidRuntime: FATAL EXCEPTION: JavaFX Application Thread
12-28 12:50:42.513 12394 12415 E AndroidRuntime: Process: com.testgluon, PID: 12394
12-28 12:50:42.513 12394 12415 E AndroidRuntime: java.lang.Error: java.lang.SecurityException: Unsafe access denied
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at java.util.concurrent.CompletableFuture.<clinit>(CompletableFuture.java:3009)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.backendconnection.RESTClient.backendMethodCall(RESTClient.java:67)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.testgluon.views.SecondaryPresenter.lambda$initialize$0(SecondaryPresenter.java:29)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.testgluon.views.SecondaryPresenter$$Lambda$2.handle(Unknown Source)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.event.Event.fireEvent(Event.java:198)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.scene.Node.fireEvent(Node.java:8411)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.scene.control.Button.fire(Button.java:185)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.event.Event.fireEvent(Event.java:198)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.scene.Scene$MouseHandler.process(Scene.java:3761)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3489)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2498)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
12-28 12:50:42.513 12394 12415 E AndroidRuntime: at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEve
12-28 12:50:42.515 1244 3577 W ActivityManager: Force finishing activity com.testgluon/javafxports.android.FXActivity
方法调用:
public static void backendMethodCall(String method, Consumer<ArrayList>callback, Consumer<String> faliure_callback, Object... arguments) {
Consumer<String> consumer = (json) -> {
Platform.runLater(new Runnable() {
@Override public void run() {
if(json != null) {
ArrayList result = convertToArraylist(json);
callback.accept(result);
}else {
if(faliure_callback != null) {
faliure_callback.accept(json);
}
}
}
});
};
67: CompletableFuture<Void> backendCall = CompletableFuture.supplyAsync(() -> {
Message message = new Message(arguments);
Client client = null;
String result = null;
try {
client = ClientBuilder.newClient();
URI tempURI = getBaseUri();
WebTarget target = client.target(tempURI);
Gson gson = new Gson();
String send = gson.toJson(message);
System.out.println(send);
result = target.path(method).request().post(Entity.entity(send, MediaType.APPLICATION_JSON), String.class);
} catch(RuntimeException e) {
throw e;
} finally { if(client != null) client.close(); }
return result;
})
.handle( (json, ex) -> {
if(ex != null) {
System.out.println("JSON: " + json);
System.out.println("Error");
System.out.println(ex);
return null;
}
return json;
})
.thenAccept(consumer);
}
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.10'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.gluonapplication.GluonApplication'
dependencies {
compile 'com.gluonhq:charm:4.4.1'
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1'
compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.17'
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.17'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
}
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'
androidSdk = 'C:\\Users\\Steven\\AppData\\Local\\Android\\Sdk'
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
我不确定为什么会这样。我最初的想法是代码需要一些权限才能运行,但我没有看到任何可能的许可的迹象。