Developing iOS applications with Kotlin

1,090 views
Skip to first unread message

Ilya Ryzhenkov

unread,
Feb 5, 2014, 10:23:13 AM2/5/14
to rob...@googlegroups.com
Hi,

I'm trying to make use of Kotlin (http://kotlin.jetbrains.org/) with RoboVM to develop iOS applications. Since Kotlin and RoboVM are not even close to release, and I'm newbie in iOS development (this is my first time trying to write my), I'm somewhat screwed. Some basic stuff works, but I can't get autolayout constraints to work. I literally translated https://github.com/mmorey/MDMViewProgrammatically into Kotlin. Now running in simulator doesn't seem to kick in autolayout. If I set bounds manually, it works. Any ideas? 

Thanks!

Ilya Ryzhenkov

unread,
Feb 5, 2014, 10:38:39 AM2/5/14
to rob...@googlegroups.com
Here is the code in Kotlin:

package krobo

import org.robovm.cocoatouch.coregraphics.*;
import org.robovm.cocoatouch.foundation.*;
import org.robovm.cocoatouch.uikit.*;

public class MyView() : UIView(CGRect(0f,0f,0f,0f)) {
    {
        setTranslatesAutoresizingMaskIntoConstraints(false)
        setBackgroundColor(UIColor.whiteColor())

        val subView = UIView(CGRect(0f,0f,0f,0f))
        subView.setTranslatesAutoresizingMaskIntoConstraints(false)
        subView.setBackgroundColor(UIColor.greenColor())

        addSubview(subView)

        addConstraint(NSLayoutConstraint.create(subView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 0.5f, 0f) as NSLayoutConstraint)
        addConstraint(NSLayoutConstraint.create(subView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 0.5f, 0f) as NSLayoutConstraint)
        addConstraint(NSLayoutConstraint.create(subView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f) as NSLayoutConstraint)
        addConstraint(NSLayoutConstraint.create(subView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterX, 1f, 0f) as NSLayoutConstraint)
    }
}

class MyController : UIViewController() {
    override fun loadView() {
        setView(MyView())
    }
}

public class MyDemo : UIApplicationDelegate.Adapter() {

    var clickCount = 0

    fun didFinishLaunching(application: UIApplication?, launchOptions : NSDictionary<NSObject, NSObject>?) : Boolean {
        val window =  UIWindow(UIScreen.getMainScreen()!!.getBounds());
        window.setBackgroundColor(UIColor.whiteColor());
        window.setRootViewController(MyController())
        window.makeKeyAndVisible();
        return true
    }
}

public fun main(args: Array<String>) {
    val pool = NSAutoreleasePool()
    UIApplication.main<UIApplication, MyDemo>(args, null, javaClass<MyDemo>())
    pool.drain();
}

Ilya Ryzhenkov

unread,
Feb 5, 2014, 3:06:42 PM2/5/14
to rob...@googlegroups.com
So far I invented some way to "debug" RoboVM applications by attaching debugger to running process in Simulator (you will need empty Mac OS project) and setting symbolic breakpoints, like to

-[UIView(UIConstraintBasedLayout) _addConstraint:]

It actually gets called (sendmsged), so I think it's not an issue with bindings. 

Niklas Therning

unread,
Feb 6, 2014, 11:01:36 AM2/6/14
to Ilya Ryzhenkov, rob...@googlegroups.com
Hi,

I can only confirm that it doesn't work. I have tried the exact code from MDMViewProgrammatically ported to Java. The ObjC code works properly but not the Java code. I cannot say whether it's a problem with the bindings or if there's some misconfiguration (e.g. some bad value in Info.plist).


--
You received this message because you are subscribed to the Google Groups "RoboVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Ilya Ryzhenkov

unread,
Feb 7, 2014, 9:11:27 AM2/7/14
to rob...@googlegroups.com, Ilya Ryzhenkov
As for Info.plist, I copied it from the generated plist.xml from Xcode, didn't help. 

Erlend Sogge Heggen

unread,
Mar 5, 2014, 5:06:03 AM3/5/14
to rob...@googlegroups.com, Ilya Ryzhenkov
Seems you pulled it off eh?

Would love to hear more about what was required. This is becoming increasingly significant because LWJGL 3 is written largely in Kotlin:

Erlend Sogge Heggen

unread,
Mar 5, 2014, 5:29:20 AM3/5/14
to rob...@googlegroups.com
Ilya replied:

It’s on my plate :) But the plate is way too big… Right now I’m working on Kotlin stdlib to fill in the blanks and make it decent library for everyday development.
As for iOS, I still want to write programs for device in Kotlin, but I don’t have enough time to investigate why this or that doesn’t work in RoboVM, sorry. 
However, on the IntelliJ side, I discussed it with team, and here is what we have:
* AppCode has integration with iOS (sim/device) debugger, which is detachable and is actually used in plugin for Ruby Motion. We could reuse it. Need to generate adequate dsym, of course.
* Run Configurations and other bulding/deploying stuff is not that hard to do, but doesn’t make much sense without debugger. 
* All basic stuff should work in RoboVM (including layouts), otherwise it is hard for me to justify resources allocation.
So basically, generate dsym, write some application (to-do list?) in modern UI, even in Java, and we can go further with IDEA. 

Ilya Ryzhenkov

unread,
Mar 5, 2014, 7:10:14 AM3/5/14
to rob...@googlegroups.com
Yep, didn't realise it was from google-groups :)

Jon Renner

unread,
Mar 14, 2014, 10:38:47 AM3/14/14
to rob...@googlegroups.com
I am currently working on a small kotlin + libgdx game that I will try to build for iOS soon, will report back later

Jon Renner

unread,
Mar 15, 2014, 5:25:48 AM3/15/14
to rob...@googlegroups.com
So at first I was trying to build a kotlin + libgdx app on mac for iOS, but I ran into the hurdle of Kotlin only working with IntelliJ (I couldn't get the kotlin-eclipse github repo working)
and RoboVM only working with eclipse.  Without a new plugin for one or the other, seems like things would have to be done in the command line (both Kotlin and RoboVM can be run from the command line).   This is not a problem, but I don't have the time to play around with that yet.

I decided to do a very simple test of compiling a HelloWorld.kt through RoboVM for linux/x86(just for my convenience) to prove at least that RoboVM and Kotlin can work together.  Happy to report this was successful, though hardly a thorough test case.  Compile log for proof, if anyone is interested: https://gist.github.com/jrenner/9563958

Jon Renner

unread,
Mar 15, 2014, 9:08:27 AM3/15/14
to rob...@googlegroups.com
I decided to spend the time on it anways. I was able to get a working libgdx app written completely in Kotlin to run on an iPad2!

Erlend Sogge Heggen

unread,
Mar 15, 2014, 10:08:46 AM3/15/14
to rob...@googlegroups.com, Jon Renner
Wow, nice! Any special trick to it?


On 15 March 2014 14:08, Jon Renner <renn...@gmail.com> wrote:
I decided to spend the time on it anways. I was able to get a working libgdx app written completely in Kotlin to run on an iPad2!

--
You received this message because you are subscribed to a topic in the Google Groups "RoboVM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robovm/p3HJisndt-4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Renner

unread,
Mar 16, 2014, 1:07:03 AM3/16/14
to rob...@googlegroups.com, Jon Renner
I made a github Repo to share my bash script for others who need to use RoboVM from the command line

Niklas Therning

unread,
May 27, 2014, 5:14:03 AM5/27/14
to Ilya Ryzhenkov, rob...@googlegroups.com
Ilya, auto layout works as expected with the latest version of RoboVM. Attached is a Java port of your original Kotlin code which uses the new CocoaTouch bindings. The result looks like this:





On Wed, Feb 5, 2014 at 9:06 PM, Ilya Ryzhenkov <ilya.ry...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "RoboVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robovm+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

IOSHelloWorld.java
Reply all
Reply to author
Forward
0 new messages