Android & Xamarin.Android Charting Documentation - SciChart Android Charts SDK v2.x
Creating your First SciChart Android App - Part 1

This tutorial was created using Android Studio v.2.1.1. If you have another version of IDE installed on your PC, the steps may differ slightly for you.

Setting up a new Android Application

If it is the first time you launch Android Studio, the “Welcome to Android Studio” window will appear:

To create a new Android application, choose the “Start a new Android Studio project” option from the list.

If you have worked in Android Studio already, go to the File->New->New Project menu options:

 

 

The “Create New Project” window will appear:

 

Using the fields, give the name and package name to your application and choose a location for it on a hard disk. After clicking the “Next” button, Android Studio will propose to choose a platform and the targeting Android SDK version. To use SciChart for Android, the Minimum SDK version must be API 19 (Android 4.4 KitKat) or higher:

 

Then you will be proposed to choose a startup project template. This step is completely optional and depends only on the complexity of an application, to reduce the amount of manually written code.

For this tutorial it actually doesn’t matter which template is choosen, so we are going to select “Empty Activity” for simplicity’s sake. This will result in a project having the only activity.

After clicking the “Next” button, Android Studio allows you to give a name to the activity and (optionally) generate an xml layout resource file for it:

In this tutorial, we will check the “Generate Layout File” box to have the xml layout resource file for the activity generated by Android Studio. Pressing the “Finish” button closes the creation wizard and we end up with a project created from the chosen template:

 

If the project’s structure doesn’t appear, you can open it clicking on the “Project” tab in the top left corner or choosing the View->Tool Windows->Project option from the menu:

In the project’s structure you should see the file with .java extension containing the class for the activity generated from the template under the “java” directory and the layout file with .xml extension under the “res” directory. The “manifest” directory contains the project’s configuration file, and under the “Gradle Scripts” directory buid configuration files can be found:

Setting up the build configuration

To be able to use SciChart classes in your application, you will need to add the SciChart libraries to the project’s dependencies. To do this, you need to go to the “app” folder under the application’s main directory and It is possible to navigate to the application’s directory from the Android Studio via the “Show in Explorer” option of the context menu on the items in the project’s structure tab:

 

We are going to add them to the “libs” folder in the “app” directory:

 

 

Now you need modify the “build.gradle” file for the project to make the build system to look for project’s dependencies in the “libs” folder. To achieve this, open the “build.gradle” file for the project and declare a new repository in the “repositories” node, located inside the “allprojects” node. To point it to the particular directory, use the “flatDir” command:

flatDir
Copy Code
allprojects {
    repositories {
        jcenter()

        // Set up a repository which looks for dependencies in the "libs" folder
        flatDir{dirs 'libs'}
    }
}

After that, you need to add every library as a dependency to the module which is intended to use SciChart. In our tutorial, the example application has the only module, so we are going to modify the “build.gradle” file for this module. Use the “compile“ command to declare a library as a module’s dependency (the order doesn’t matter):

Compile
Copy Code
dependencies {
    // Default module dependencies
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'

    // Declare SciChart libraries as module dependencies
    compile (name:'charting-release', ext:'aar')
    compile (name:'drawing-release', ext:'aar')
    compile (name:'data-release', ext:'aar')
    compile (name:'core-release', ext:'aar')
}

Now, the Android Studio proposes to “synchronize” the changes done in the build files. It will reload all the dependencies specified there, including the SciChart dependency that we have added. You can do this pressing the message at the top or the “Sync” button from the menu:

 

After the synchronization is finished, you can check the build results at the “Messages” tab at the bottom:

If you don’t see the “Messages” tab, it can be opened via the View->Tool Windows->Messages option from the menu:

If the build has failed, please try to do the steps again to ensure you haven’t missed something. If you still cannot manage it to succeed at this point, please let us know at http://support.scichart.com.