Debugging Codename One apps on iOS devices has been documented well with a video for years, we didn’t spend too much time outlining the Android counterpart mostly because we didn’t really use it as much and it was far simpler.
As Android Studio launched this actually became really easy as it was possible to actually open the gradle project in Android Studio and just run it. But due to the fragile nature of the gradle project this stopped working for our recent builds, this works for some cases but is a bit of a flaky touch & go.
| || If these instructions work for you then you can ignore the video/instructions below. However, if they don’t then keep reading |
Google has the tendency to change things frequently which makes documenting a process to work with Android much harder than the iOS equivalent. The method outlined in the "how do i" video that we just launched should work regardless of future changes. It might not be the best way to do this but it’s simple and it works.
Here are the steps highlighted in the video:
Check the include source flag in the IDE and send a build
Download the sources.zip result from the build server
Launch Android Studio and create a new project
Make sure to use the same package and app name as you did in the Codename One project, select to not create an activity
Unzip the sources.zip file and copy the
main directory from its
src directory to the Android Studio projects
src directory make sure to overwrite files/directories.
libs directory on top of the existing libs
Copy the source gradle files dependencies content to the destination gradle file
Connect your device and press the Debug button for the IDE
| || You might need to copy additional gradle file meta-data such as multi-dexing etc. |
You might not need to repeat the whole thing with every build. E.g. it might be practical to only copy the
userSources.jar from the libs directory to get the latest version of your code.and you can copy the
src/main directory to get our up to date port.
There are many edge cases and hints that probably don’t fit into this process, let us know in the comments below about the difficulties and success you’ve had with this process and also provide tips about simpler hacks to build the code for device.
There is a portion we didn’t get into with the video, copying updated sources directly without sending a build. This is possible if you turn on the new Android Java 8 support. At this point you should be able to remove the libs jar file which contains your compiled data and place your source code directly into the native project for debugging on the device.