Fork us on GitHub

TIP: Use Android Gradle Dependencies in Native Code

Rely on automation to keep your cn1lib/native code up to date
TIP: Use Android Gradle Dependencies in Native Code

TIP: Use Android Gradle Dependencies in Native Code

Integrating a native OS library isn’t hard but it sometimes requires some juggling. Most instructions target developers working with xcode or Android Studio & you need to twist your head around them. In Android the steps for integration in most modern libraries include a gradle dependency.

E.g. we recently published a library that added support for Intercom. The native Android integration instructions for the library looked like this:

Add the following dependency to your app’s build.gradle file:

dependencies {
    compile ''

Which instantly raises the question: "How in the world do I do that in Codename One"?

Well, it’s actually pretty simple. You can add the build hint:

android.gradleDep=compile ''

This would "work" but there is a catch…​

You might need to define the specific version of the Android SDK used and specific version of Google play services version used. Intercom is pretty sensitive about those and demanded that we also add:


Once those were defined the native code for the Android implementation became trivial to write and the library was easy as there were no jars to include.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.