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.
问题:
回答1:
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.