将JavaFX项目导出到android [英] Export JavaFX project to android

查看:764
本文介绍了将JavaFX项目导出到android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JavaFX 中创建了一个项目,并希望在Android中运行它。我使用了 JavaFXports 并生成了所需的apk。我还设法在模拟器上安装apk。但我需要源(源代码)。换句话说,我希望能够在模拟器上运行时调试项目。

解决方案

调试JavaFXPorts /您使用适用于IDE(NetBeans,IntelliJ或Eclipse)的Gluon插件创建的Gluon Mobile,以及已部署到Android模拟器(使用Android Studio)的Gluon Mobile,请按照以下步骤操作:



1。从IDE创建JavaFX移动应用程序



为此您可以使用Gluon



虽然这个图像非常非常慢,但x86-64图像无法部署apk(参见INSTALL_FAILED_NO_MATCHING_ABIS



7。在IDE上附加调试器



最后,返回IDE,在Debug选项下,附加一个调试器,localhost和8700.这适用于NetBeans:





然后点击确定。调试过程将开始。



8。开始调试



在代码中添加断点,例如在按钮事件处理程序中,然后单击模拟器上运行的应用程序中的按钮。您将看到它在断点处停止。





这个是吧。


I have a project made in JavaFX and want to run it in Android. I have used JavaFXports and have generated the needed apk. Also I managed to install the apk on an emulator. But I need the sources(the source code). In other words I want to be able to debug the project while it is running on the emulator.

解决方案

To debug a JavaFXPorts/Gluon Mobile that you have created using the Gluon plugin for your IDE (NetBeans, IntelliJ or Eclipse), and that you have deployed to the Android emulator (using Android Studio), follow these steps:

1. Create the JavaFX mobile app from your IDE

For that you can use the Gluon plugin for your IDE. Use one of the built-in templates to create your project or go and use one of the many samples available here.

Let's say you use the Single View project. Provide a name and run the app

2. Create the apk

Run the task Tasks->Android->Android to create the apk (or on command line run ./gradlew android).

3. Run the emulator

For this, open Android Studio, create a new empty app from a template, and click on run. It will ask you to select a device. Then create a new virtual device and use an ARMEABI image.

While this image is really, really slow, the x86-64 image won't work to deploy the apk (see INSTALL_FAILED_NO_MATCHING_ABIS error). So if you can't get a real device to test it, this is the only solution as far as I know.

If needed, download the armeabi image. Once you have it, it will take quite a while to launch the app. But just need the emulator, so there is no need to wait, and we can close the emulator, and before closing Android Studio, get the image name, let's say Nexus_5_API_23.

On command line, go to <android sdk>/tools and run:

./emulator -avd Nexus_5_API_23

It will show up, and you will see something like:

$ ./emulator -avd Nexus_5_API_23
emulator: Listening for console connections on port: 5554
emulator: Serial number of this emulator (for ADB): emulator-5554

4. Deploy the apk

On command line, go to <android sdk>/platform-tools and run

adb -s emulator-5554 install <path.to>/<your.app>.apk

You can find the apk in your project under /builds/javafxports/android/<your.app>.apk.

$adb -s emulator-5554 install GluonDebugEmulator.apk                                         
[100%] /data/local/tmp/GluonDebugEmulator.apk                                                                                       
    pkg: /data/local/tmp/GluonDebugEmulator.apk
Success

5. Run the apk on the emulator

6. Open Android Device Monitor

Go to <android sdk>/tools and run monitor. On the left, on top you should see the emulator device, and a list of processes. Find your app package name there, select it and see the port it is using for the app (8700).

7. Attach the debugger on your IDE

Finally, go back to your IDE, and under Debug options, attach a debugger, with localhost and 8700. This is for NetBeans:

and click ok. A debugging process will start.

8. Start debugging

Add a breakpoint in your code, for instance in the button event handler, and click on the button in the app running on the emulator. You will see that it stops in the breakpoint.

And this is it.

这篇关于将JavaFX项目导出到android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆