我一直在尝试从gluon mobile连接到REST端点,但是当应用程序部署在移动本身上时,我面临挑战。每次我尝试按按钮进行连接时,它就会崩溃(应用程序停止工作)。但是,在台式机上进行测试时,一切工作正常。这是代码
button.setOnAction(e -> {
JSONObject reqJson = new JSONObject();
reqJson.put("username", username.getText());
reqJson.put("password", password.getText());
Future<HttpResponse<JsonNode>> future = Unirest.post("http://xxx.xxx.xx:8087/business/login")
.header("accept", "application/json")
.body(reqJson.toJSONString())
.asJsonAsync(new Callback<JsonNode>() {
public void failed(UnirestException e) {
System.out.println("The request has failed");
}
public void completed(HttpResponse<JsonNode> response) {
System.out.println("successfull");
System.out.println("...");
MobileApplication.getInstance().switchView("DASHBOARD_VIEW");
}
public void cancelled() {
System.out.println("The request has been cancelled");
}
});
});
我的build.gradle看起来像这样
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'
}
dependencies {
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
}
}
mainClassName = 'com.mysacco.MySACCO'
dependencies {
compile 'com.gluonhq:charm:5.0.2'
}
jfxmobile {
downConfig {
version = '3.8.6'
// 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 = '/Users/aiden/Library/Android/sdk'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
exclude 'DEPENDENCIES.txt'
exclude 'NOTICE.txt'
exclude '**/*.txt'
}
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
我的androidmanifest看起来像这样
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mysacco" android:versionCode="1" android:versionName="1.0">
<supports-screens android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="21"/>
<application android:label="MySACCO" android:name="android.support.multidex.MultiDexApplication" android:icon="@mipmap/ic_launcher">
<activity android:name="javafxports.android.FXActivity" android:label="MySACCO" android:configChanges="orientation|screenSize">
<meta-data android:name="main.class" android:value="com.mysacco.MySACCO"/>
<meta-data android:name="debug.port" android:value="0"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.gluonhq.impl.charm.down.plugins.android.PermissionRequestActivity" />
</application>
</manifest>