Tuesday Jan 21, 2014

Johan Vos blogged about Java FX and Android

If you're interested in latest development in Java FX for Android read Johan's blog entry here. I feel also that some tooling support would help in this stage of the project. So far the gradle script shipped in a binary worked well but who wants to stick with a script forever, right? Looking at the current IDEs that support Android ( Eclipse ADT, Netbeans NBAndroid and Google's Android Studio ) the natural choice would be a new gradle build system. This is a build system that Google has chosen for the future. Unfortunately it is still in a quite rough state and doesn't allow fine grained setup which is essential for us. To be more specific a dex task doesn't have capability that old good ant task had and we can't fix an issue with "too many methods" error. Positive is that there's an issue filed on Android gradle build system so there's a chance that Google will fix that. Until that happens using ant seems to be the only solution. Thanks to Radim Kubacki former NetBeans guy who's the father of NBAndroid we might have a chance to extend NBAndroid plugin for Netbeans. Add a wizard for creating Java FX projects, properly bootstrap it with FX libraries and use all great tools that NBAndroid and NetBeans and SceneBuilder have for Java FX developers. I would really glad to see that happen in near future.

Friday Dec 20, 2013

JavaFX on Android follow-up

Things moved a little bit forward with javaFX on Android and it's about the time to summarize them here. Few weeks ago in a this text "How to build OpenJFX on Android" I've put together a short tutorial for javaFX and Android enthusiasts. I hope you've enjoyed your homemade javaFX runtime for Android. But people usually appreciate when things are simpler and as smooth as possible. Thanks to Johan Vos this happened in javafxports project on bitbucket.org which contains everything required to build javaFX on Android plus publishes regularly built runtime. Javafxports repository android-graphics-rt is a direct fork of OpenJFX 8 Graphics RT synced often. It is a plan to make OpenJFX the upstream project e.q. push approved and reviewed changes back. But right now the latest and freshest features and fixes you find in javafxports.

Read carefully javafxports wiki  how to setup JFX runtime build or use prebuilt one with project creator (gradle script) to get your javaFX app deployed on Android at once. If you encounter some issues there's also newly created JavaFXAndroid forum for you to help. Don't hesitate to ask or share your results, feedback and help is welcome.

Since the first text "How to build OpenJFX on Android" there are important fixes available.

  • Fixed Multitouch support
  • Fixed issue "dex with too many method references". Thanks to patches from Stefan Fuchs and Sebastian Rheinnecker
  • Fixes in Ensemble app to make it build and run on Android.
  • Text input in TextField and TextArea from native softkeyboard.
  • Improved lifecycle behavior pause, resume, rotation.

I hope you'll enjoy more stable and capable javaFX on Android.

Friday Nov 29, 2013

JavaFX on Android multitouch and gestures support

A short entry this week. It looks that I'm on the right path to fix event processing  problems on dalvik, at last. I can't resist to publish short video . The fix hasn't been pushed to repository yet.

Thanks to Pavel Safrata for the sample application.

Friday Nov 22, 2013

Building JavaFX for Android with skia library.

I hope you've tried and succeeded to build JavFX runtime for Android following my blog post How to build OpenJavaFX for Android. Here's a short tweak how to make a freetype library significantly smaller. The result should be functionally identical just instead statically linking freetype of 1.5Mb size we will use on-device library skia. The powerfull skia graphics framework already contains freetype and harfbuzz (complex text layout). Although developers are discouraged to use skia directly since it hasn't public api we could give it a try because the change in build script is very minimal. Every kilobyte matters if you have to repeatedly deploy application to a device.

You will still need freetype headers for compilation but instead libfreetype.a you will use libskia.so. Firstly download libskia.so from your device.

adb pull /system/lib/libskia.so .

Open and edit android.gradle. Go to very bottom and look for ANDROID.fontNativeFreetype.linkFlags and change the name of library to link with. If you've done it like myself e.q. put it along with libfreetype.a to the same directory the script will look like that:

ANDROID.fontNativeFreetype.linkFlags = 
        [linkFlags, "-llog", 
         "-L$freetypeDir/lib", "$freetypeDir/lib/libskia.so"].flatten()
Now just run build and here we go.

Tuesday Nov 12, 2013

How to build Open JavaFX for Android.

Here's a short recipe for baking JavaFX for Android dalvik. We will need just a few ingredients but each one requires special care. So let's get down to the business.

 Sources

The first ingredient is an open JavaFX repository. This should be piece of cake. As always there's a catch. You probably know that dalvik is jdk6 compatible  and also that certain APIs are missing comparing to good old java vm from Oracle.  Fortunately there is a repository which is a backport of regular OpenJFX to jdk7 and going from jdk7 to jdk6 is possible. The first thing to do is to clone or download the repository from https://bitbucket.org/narya/jfx78. Main page of the project says "It works in some cases" so we will presume that it will work in most cases :)
As I've said dalvik vm misses some APIs which would lead to a build failures. To get them use another compatibility repository which is available on GitHub https://github.com/robovm/robovm-jfx78-compat. Download the zip and unzip sources into jfx78/modules/base.
We need also a javafx binary stubs. Use jfxrt.jar from jdk8.
The last thing to download are freetype sources from http://freetype.org. These will be necessary for native font rendering.

Toolchain setup

I have to point out that these instructions were tested only on linux. I suppose they will work with minimal changes also on Mac OS. I also presume that you were able to build open JavaFX. That means all tools like ant, gradle, gcc and jdk8 have been installed and are working all right. In addition to this you will need to download and install jdk7, Android SDK and Android NDK for native code compilation.  Installing all of them will take some time. Don't forget to put them in your path.

export ANDROID_SDK=/opt/android-sdk-linux
export ANDROID_NDK=/opt/android-ndk-r9b
export JAVA_HOME=/opt/jdk1.7.0
export PATH=$JAVA_HOME/bin:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK:$PATH

Freetype

Unzip freetype release sources first. We will have to cross compile them for arm. Firstly we will create a standalone toolchain for cross compiling installed in ~/work/ndk-standalone-19.
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh  --platform=android-19 --install-dir=~/work/ndk-standalone-19

After the standalone toolchain has been created cross compile freetype with following script:

export TOOLCHAIN=~/work/freetype/ndk-standalone-19
export PATH=$TOOLCHAIN/bin:$PATH
export FREETYPE=`pwd`
./configure --host=arm-linux-androideabi --prefix=$FREETYPE/install --without-png --without-zlib --enable-shared
sed -i 's/\-version\-info \$(version_info)/-avoid-version/' builds/unix/unix-cc.mk
make
make install

It will compile and install freetype library into $FREETYPE/install. We will link to this install dir later on. It would be possible also to link openjfx font support dynamically against skia library available on Android which already contains freetype. It creates smaller result but can have compatibility problems.

Patching

Download patches javafx-android-compat.patch + android-tools.patch and patch jfx78 repository. I recommend to have look at patches. First one android-compat.patch updates openjfx build script, removes dependency on SharedSecret classes and updates LensLogger to remove dependency on jdk specific PlatformLogger. Second one android-tools.patch creates helper script in android-tools. The script helps to setup javaFX Android projects.

Building

Now is time to try the build. Run following script:

JAVA_HOME=/opt/jdk1.7.0
JDK_HOME=/opt/jdk1.7.0
ANDROID_SDK=/opt/android-sdk-linux
ANDROID_NDK=/opt/android-ndk-r9b
PATH=$JAVA_HOME/bin:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK:$PATH
gradle -PDEBUG -PDALVIK_VM=true -PBINARY_STUB=~/work/binary_stub/linux/rt/lib/ext/jfxrt.jar \
-PFREETYPE_DIR=~/work/freetype/install -PCOMPILE_TARGETS=android

If everything went all right the output is in build/android-sdk :)

UPDATE: If you want to build without jfxrt.jar binary stub comment out jmx and sample apps from settings.gradle.

Create first JavaFX Android project

Use gradle script int android-tools. The script sets the project structure for you.   Following command creates Android HelloWorld project which links to a freshly built javafx runtime and to a HelloWorld application.

  • NAME is a name of Android project.
  • DIR where to create our first project.
  • PACKAGE is package name required by Android. It has nothing to do with a packaging of javafx application.
  • JFX_SDK points to our recently built runtime.
  • JFX_APP points to dist directory of javafx application. (where all application jars sit)
  • JFX_MAIN is fully qualified name of a main class.
gradle -PDEBUG -PDIR=/home/user/work -PNAME=HelloWorld -PPACKAGE=com.helloworld \
-PJFX_SDK=/home/user/work/jfx78/build/android-sdk -PJFX_APP=/home/user/NetBeansProjects/HelloWorld/dist \
-PJFX_MAIN=com.helloworld.HelloWorld createProject

Now cd to the created project and use it like any other android project. ant clean, debug, uninstall, installd will work. I haven't tried it from any IDE Eclipse nor Netbeans.

Special thanks to Stefan Fuchs and Daniel Zwolenski for the repositories used in this blog post.
About

JavaFX is a Java GUI toolkit, partially developed from Prague, Czech Republic. The Prague team uses this blog to post articles, code samples and insights about the range of topics the team members specialize in. This includes JavaFX Scenegraph (javafx.scene.*), JavaFX Core libraries & animations, iOS port & Android port.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today