Use robovm to run javafx on iOS devices

Source: Internet
Author: User

Disclaimer: the original articles of this blog are all personal originals and are copyrighted. For more information, see http://blog.csdn.net/ml3947. for more information, visit http://www.wjfxgame.com.


At present, I got an exciting message that someone has asked javafx to run on the iOS device !!!!

Robovm is used here.

The so-called robovm is a VM that can translate Java bytecode into the native code of the arm or X86 platform. Because robovm comes with a bridge from Java to object-C, we can use robovm to develop iOS programs using Java.

Let's take a look at how to run the javafx program on iOS devices.

1. Obtain xcode 4.6.2 from app store.

2. Download and install jdk8: https://jdk8.java.net/download.html.

3. Installing llvm 3.2 to/opt/llvm

$ curl -O 'http://llvm.org/releases/3.2/clang+llvm-3.2-x86_64-apple-darwin11.tar.gz'$ sudo tar xvfz clang+llvm-3.2-x86_64-apple-darwin11.tar.gz -C /opt$ sudo ln -s /opt/clang+llvm-3.2-x86_64-apple-darwin11 /opt/llvm$ rm -f clang+llvm-3.2-x86_64-apple-darwin11.tar.gz

4. Install the latest robovm to/opt/robovm

$ curl -O 'http://download.robovm.org/nightlies/robovm-0.0.2-SNAPSHOT-20130520_0201.tar.gz'$ sudo tar xvfz robovm-0.0.2-SNAPSHOT-20130520_0201.tar.gz -C /opt/$ sudo ln -s /opt/robovm-0.0.2-SNAPSHOT /opt/robovm$ rm -f robovm-0.0.2-SNAPSHOT-20130520_0201.tar.gz

Now you can run the official javafx brick hitting example.

1. Download the source code of Brickbreaker.

$ curl -O 'http://download.robovm.org/BrickBreaker.zip'$ unzip BrickBreaker.zip

2. Compile the Java source code and copy images.

$ cd BrickBreaker$ mkdir bin$ find src -name '*.java' -print | xargs javac -d bin -bootclasspath /opt/robovm/lib/robovm-rt.jar -cp /opt/robovm/lib/robovm-objc.jar:/opt/robovm/lib/robovm-cocoatouch.jar:lib/openjfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/ext/jfxrt.jar$ rsync -r --include '*.png' src/ bin/

3. Use robovm to compile javafx code into local code, and then run the app on the IOS simulator.

$ /opt/robovm/bin/robovm -verbose -properties robovm.properties -config robovm.xml -arch x86 -run -ios-sim-family ipad

You will see that the javafx program is running on your iOS simulator.


I have read the brickbreak source code. In fact, there are only two more java files.

import javafx.application.Application;import org.robovm.cocoatouch.foundation.NSAutoreleasePool;import org.robovm.cocoatouch.foundation.NSDictionary;import org.robovm.cocoatouch.uikit.UIApplication;import org.robovm.cocoatouch.uikit.UIApplicationDelegate; public class BrickBreaker extends UIApplicationDelegate.Adapter {    @Override    public boolean didFinishLaunching(UIApplication application,            NSDictionary launchOptions) {        Thread launchThread = new Thread() {            @Override            public void run() {                Application.launch(brickbreaker.Main.class);            }        };        launchThread.setDaemon(true);        launchThread.start();        return true;    }        public static void main(String[] args) throws Exception {        System.setProperty("glass.platform", "ios");        DummyFontLoader.install();        NSAutoreleasePool pool = new NSAutoreleasePool();        UIApplication.main(args, null, BrickBreaker.class);        pool.drain();    }}

This is a file using the robovm library. Specifies the main class of the started javafx.


import java.io.InputStream;import java.lang.reflect.Field;import java.util.Collections;import java.util.List;import javafx.scene.text.Font;import javafx.scene.text.FontPosture;import javafx.scene.text.FontWeight;import com.sun.javafx.font.PrismFontLoader;import com.sun.javafx.tk.FontLoader;import com.sun.javafx.tk.FontMetrics;public class DummyFontLoader extends PrismFontLoader {    public static void install() {        try {            Field field = PrismFontLoader.class.getDeclaredField("theInstance");            field.setAccessible(true);            field.set(null, new DummyFontLoader());        } catch (Exception e) {            throw new RuntimeException(e);        }    }        public void loadFont(Font paramFont) {    }    public List<String> getFamilies() {        return Collections.emptyList();    }    public List<String> getFontNames() {        return Collections.emptyList();    }    public List<String> getFontNames(String s) {        return Collections.emptyList();    }    public Font font(String family, FontWeight weight, FontPosture posture, double size) {        return new Font(null, size);    }    public Font loadFont(InputStream paramInputStream, double size) {        return new Font(null, size);    }    public Font loadFont(String name, double size) {        return new Font(null, size);    }    public FontMetrics getFontMetrics(Font font) {        return new FontMetrics(0, 0, 0, 0, 0, 0, font);    }    public float computeStringWidth(String s, Font font) {        return 0.0f;    }    public float getSystemFontSize() {        return 13.0f;    }}

This file is not very familiar. It seems that the class in javafx is obtained through reflection, and some settings of font loading are changed during runtime. The specific use is unknown.


Other files are the source code of the official brickbreak of javafx, which is exactly the same.


This only demonstrates that running javafx on iOS is feasible. But it is not yet supported by the official oracle. However, this is also an improvement, hoping to see more development in the future.


Reprinted please indicate the source: http://blog.csdn.net/ml3947

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.