Hacking the Codename One Source Code - Part V - Transcript.pdf
1. Hacking the Source - Part V
The iOS app is surprisingly easy when compared to the Android app. There are some nuances but overall the process is pretty simple.
2. cd vm/JavaAPI
ant clean jar
cd ../ByteCodeTranslator
ant jar
cd ../../Ports/iOSPort
ant jar
Compile VM & Port
First we need to compile the VM & the port. So we need to go back to the cn1 directory and execute these commands.
4. mkdir kitchenClasses
java -Dretrolambda.defaultMethods=true -Dretrolambda.inputDir=../KitchenSink/build/
classes -Dretrolambda.classpath=../cn1/vm/JavaAPI/build/classes:../cn1/CodenameOne/
build/classes -Dretrolambda.outputDir=kitchenClasses -Dretrolambda.bytecodeVersion=49 -
jar retrolambda-2.5.3.jar
Retrolambda Translate
We can run retrolambda with the following command. Once this command is complete a version of kitchen sink classes targeting JDK 5 resides under the kitchenClasses
directory. I won’t go into details about this command as I think you would be better served by the documentation in the retrolambda project.
5. package com.codename1.demos.kitchen;
import com.codename1.ui.Display;
public class KitchenSinkStub implements Runnable {
@Override
public void run() {
KitchenSink k = new KitchenSink();
k.init(this);
k.start();
}
public static void main(String[] args) {
Display.init(new KitchenSinkStub());
}
}
KitchenSinkStub (iOS)
The next step is to create and compile the stub class which we will use to launch the implementation. In the KitchenSinkIOS folder I created a stub directory. I then added
the KitchenSinkStub.java to that directory. The one interesting thing in this stub is the fact that the implementation invokes the runnable callback when its ready.
Everything else is is really trivial.
6. javac -classpath kitchenClasses:../cn1/CodenameOne/build/
classes:../cn1/Ports/iOSPort/build/classes stub/
KitchenSinkStub.java -source 1.5 -target 1.5 -d stub
Compiling the Stub
This can be compiled using this command. Notice that I used source 1.5 level when compiling. This is crucial as the VM doesn't support Java 8 directly. We use
retrolambda to add support for Java 8 language features but don’t do that on the stub.
7. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
Once we do this we can create the output folder xcodeproj and run the VM translation code. There is a lot to digest in this command so I'll break it down to one argument
at a time.
This should be pretty easy. We are running the VM translator. It's just an executable jar.
8. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
Represents the VM target OS. This is currently the only supported option. In the future we might support additional targets for the VM
9. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
Next we have the path. Bash understands this as multiple commands so we have to put the entire path in quotes. These are the individual elements within. The first
element in the path is the stubs directory where I compiled the KitchenSinkStub before
10. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
The second element is the classes of the VM. This covers the java core classes supported by Codename One
11. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
These are the actual classes of the app after they went through the retrolambda process
12. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
these are the classes of the iOS port/implementation
13. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
these are the core implementation classes of Codename One itself
14. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
these are Objective-C sources that implement the native code referenced from the iOS port
15. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
This is the target output directory we created above this will include the output project
16. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
This is the name of the stub class we created
17. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
This is the package name of the stub and the application itself
18. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
These are the title and version number of the application
19. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
This is the target type. ios indicates a universal iPad/iPhone app but you can specify iphone or ipad here
20. mkdir xcodeproj
java -jar ../cn1/vm/ByteCodeTranslator/dist/ByteCodeTranslator.jar ios
"stub;../cn1/vm/JavaAPI/build/classes;kitchenClasses;../cn1/Ports/
iOSPort/build/classes;../cn1/CodenameOne/build/classes;../cn1/Ports/
iOSPort/nativeSources" xcodeproj KitchenSinkStub
com.codename1.demos.kitchen "Kitchen Sink" "1.0" ios
"CoreImage.framework;QuartzCore.framework"
Generating the Code
And finally these are the included native libraries/frameworks. Codename One requires these two by default. Now that this is all done we have an xcode project under
xcodeproj/dist.