ShinobiAndroidStudioThumbnail

Back to Blog

Using ShinobiCharts with Android Studio: Update 0.5.5

Posted on 24 Apr 2014 Written by Sam Davies

Introduction

Back in November I wrote a blog post explaining how to use ShinobiCharts for Android with Android Studio. It was a bit of a hack – involving manually bundling the NDK libraries up, but now many releases of Android Studio later, there is a better way.

In this brief post I’m going to explain how you can use the ShinobiCharts for Android library with Android Studio by importing it as a module. The standard disclaimer applies for pre-release software:

Please note: Android Studio is changing on a very regular basis. These instructions are not expected to work indefinitely. ShinobiControls offers no support for Android Studio at this time. Once Android Studio is officially released then ShinobiCharts for Android will be updated so that it works seamlessly.

Importing the library as a module

This post isn’t a tutorial, so I’m assuming that you have downloaded ShinobiCharts for Android and have Android Studio installed. You’re going to add ShinobiCharts as a new module. Since 0.8.0 of the gradle build plugin, there has been support for prebuilt NDK libs in android library projects, and 0.5.5 of Android Studio has added GUI support to make this easy to do.

File > Import Module will kick off the importer.

Import Module

Navigate to the shinobi-charts-android-library directory, which was part of the donwloaded zip file.

Browse To Location

There are some options on the following page – you want all of them to be ticked.

Select Options

The importer copies the content of the library into the project directory, and restructures it to match the convention used by Android Gradle projects. This involves moving the binary libs to a directory called jniLibs, and pushing most content into a src directory. It has also created the appropriate build.gradle file, and added your module to the project.

Import Report

One thing you do need to change is the plugin used. By default it will import as an android module, but you want it to be a android-library. Open up build.gradle inside the shinoibchartsandroidlibrary module, and replace the appropriate line with the following:

apply plugin: 'android-library'

That completes the library module setup – simple!

Using the ShinobiCharts module

In order to use ShinobiCharts in your other modules, you need to do a couple of things – add it as a dependency, and update the manifest. Adding a dependency is easy in Android Studio: right click on your app module and select “Open Module Settings“.

Module Settings

Choose the dependencies tab, and use the + in the bottom left-hand corner to add a module dependency.

Add Dependency

Select :shinobichartsandroidlibrary and you’re done. This actually adds the following to the build.gradle file:

dependencies {
    ...
    compile project(':shinobichartsandroidlibrary')
}

Shinobi Charts Module

If you try and build it now, you’ll run into the same problem as before – where the manifest files cannot be merged. This is because you need to specify the version of OpenGLES required in your app module. Add the following line to the manifest section of AndroidManifest.xml:

<uses-feature android:glEsVersion="0x00020000" android:required="true"/>

and the add the following attribute to the application tag:

android:hardwareAccelerated="true"

If you build again, this time you won’t get any errors.

Conclusion

I like Android Studio a lot, and it’s really exciting to see it moving this quickly. It’s now as easy to use the ShinobiCharts library in Android Studio as it is in Eclipse ADT (some would argue easier…). We can’t wait for full NDK support so we can start trialling AS for development of ShinobiCharts.

sam

Back to Blog