Friday, April 24, 2015

Kivy on Mac

I started to explore Kivy on mac.  Its a python based UI developement tool.  It looks cool.  You can develop Mobile, Desktop and cross platform UI using this tool.  For anyone struggling to install it on mac.  Instructions look simple on their site but has missed a small note.  I googled and finally found the fix.

1.  Install Kivy from DMG
2.  script file needs a soft link created under /usr/local/bin
3.  You may need use sudo with the below command based on your setup.
ln -s /Applications/Kivy.app/Contents/Resources/script /usr/local/bin/kiv
Once this is done, you will just run any examples under  /Applications/Kivy.app/Contents/Resources/examples folder 

cd to the folder and type kivy main.py (in mycase main.py was the file i was running)


Friday, March 6, 2015

Java to Objective-C journey (J2OBJC to convert apache commons math3)

There are so many opensource java libraries that we use to develop applicaitons.  Recently, I had a need to use Apache Commons Math library.  There are phenomenal things this library can do for you.  Similarly, there may be some of these functions you wish were available for iOS.  Good Luck finding them.  Atleast, I was'nt successful.  I decided to port one of the apache commons library for my iOS needs.  It turns out that it's not so simple and too much hard work.  That's when I came across J2OBJC project.

You can find out more details on www.j2objc.org 

j2objc google group - Fantastic group of people like Tom Ball and others help you succeed with your projects.  Of course, you need to know what you are doing and not expect them to do things for you.  If you understand how to setup a project and are having issues, these guys are saviors.

 https://groups.google.com/forum/#!forum/j2objc-discuss

Please note that j2objc does not convert UI code.  It is mainly meant to convert business logic or calculation that was written in Java.

I have started converting Apache Commons Math3 or Math4 library.  I will keep my progress posted if anyone is interested.  So far, I have found that there are not very good tutorials for this.  But I was able to convert all the java files to objective-c.

Update 10/28

I have to choose a few paths to use j2objc.

Path I - Eclipse Plugin - It was not very hard to find the link to the plugin on the j2objc.org website.  Install was easy, very simple documentation.

http://j2objc.org/docs/Using-J2ObjC-with-Eclipse.html

However, to convert a large project like Apache commons math.  I could not use this plugin.  I could use it for smaller projects that do not have conflicting named files within other packages.  If you have a small library in java you want to convert to iOS, this is they for you,  If you are under taking anything big like the one i have picked, go to Path II.

Path II - Gradle -  If you have not used gradle before, I would suggest you to take a look at it.  This was the first time I interacted with gradle.  I love it.  Guys at google have built a j2objc plugin for gradle.   This will not only translate code, it will pull the sources from maven repo if needed.  Build automation at its best and simple.

Gradle j2objc plugin -- https://github.com/j2objc-contrib/j2objc-gradle

If you can follow other projects fun part begins, there is a end to end test for some common libraries in place.  Here is the location.

https://github.com/j2objc-contrib/j2objc-common-libs-e2e-test

When i started to write this post, there was no apache commons math3 in the e2e repo.  Now Advay and Bruno have created one.  However, these instructions below will help you if you are working on a different library.  Enjoy

Here are some steps

1.  Clone the e2e project.  git clone https://github.com/j2objc-contrib/j2objc-common-libs-e2e-test.git

2. Run prep.sh.  This downloads the required j2objc suite.

3.  Run run-all.sh or you can run ./run-test.sh org.apache.commons-commons-math3 to build commons math3

4.  This will invoke Gradle to download the sources from maven, compile java code, translate using j2objc, compile objctive-c code and package it for you.

This is awesome.  I used the apache commons lang3 as example to setup the commons math 3.  In my case, I had apache commons math 3 had translation errors.  Still working on fixing those.

I have configured Gradle to look into my local folder for source code instead of pulling from maven as i have to remove files to get rid of dependencies that are not covered like awt.geom etc.

Note: Observe the build.grade in the sub folder "org.apache.commons-commons-math3".  It has few new interesting things.  One is the compile argument and other is to exclude several files that will not translate.  All the work has been done.

!!!!!!!!SUCCESS!!!!!!!!

Issues (mostly user based)
1.  After removing several files due to dependencies that i cannot migrate.  I did not need them either.  I was stuck at compilation with several errors mentioned in this thread

https://groups.google.com/forum/#!topic/j2objc-discuss/chyYqJr_whM

I needed to tweak gradle task to include the compiler argument

2.  Some strange reason, i needed to change the name of my library to shorten it.  Still trying to figure that one.

3.  Using the compiled static library was not hard, but I did not read all of Tom's documentation.  I made it hard on myself.  You need several dependencies listed here

http://j2objc.org/docs/Xcode-Build-Rules.html


If you are still have questions, leave me a note.  Eventually, I plan to create a github project.