DEV Community

Cover image for Setting up an Android Development Environment on OSX
Andrew Bt
Andrew Bt

Posted on • Originally published at scichart.com

Setting up an Android Development Environment on OSX

The following guide will help you setup a Development Environment for Android on Mac OSX. This is required if you wish to compile SciChart's Android Charts or Chart Examples / Demos from source-code. You can skip this if you already have Android Studio and the Android NDK setup!

Installing the Java Development Kit

1. Using safari, navigate to https://www.java.com/en/download/ and download Java 8 for mac.

2. You will also need to install the Java Platform JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html

NOTE: Make a note of your JDK Install path. For instance, /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home. This will be required later when setting environment variables

Installing Android Studio

Download Android Studio for MAC from the https://developer.android.com/studio/index.html#downloads. Follow the steps to install the application in OSX.

You can start the application from the Applications folder, or from Spotlight, by searching CMD+SPACE and typing ‘Android Studio’

On first start, Android Studio will try to download the Android SDK. This may take a while. Make a note of where the Android SDK was installed to, this is very useful for certain operations in Android!

Once that’s done, open Android Studio and go to Tools -> Android -> SDK Manager. Under SDK Platforms ensure you have selected the platform(s) you want to develop for. For instance, we require v4.4 – v6 for SciChart Android development.

Next, under SDK Tools ensure ‘Android SDK Build Tools’ is up to date. Also download the Android NDK v12.

Click OK to install all components.

Installing the Android NDK

Certain components in SciChart's Android Chart Library are dependent on the Android NDK (Native Development Kit). Installing this is required if you are building our examples or SciChart Android library from source-code.

The Android NDK can be downloaded via the SDK Manager within Android Studio. Go to Tools -> Android -> SDK Manager. Under Build tools ensure the Android NDK is checked and up to date.

Installing Gradle

Gradle is the command-line build tool for Java and Android applications. SciChart uses Gradle to build libraries (AARs, which contain JAR and resource files) which can be used in your own applications.

If you are compiling SciChart Android from our source code, it is recommended you install Gradle. Following the instructions from StackOverflow at http://stackoverflow.com/a/28928107/303612

  1. Install Homebrew (a package manager for OSX)
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install Gradlebrew install gradle

    brew install gradle

    Setting Mac OSX Environment Variables

    The following environment variables must be set to allow development of SciChart Android in Android Studio on OSX.

    • JAVA_HOME: The location of the Java JDK
    • ANDROID_HOME: The location of the Android SDK on disk
    • ANDROID_NDK_HOME: The location of the Android NDK on disk

    To set environment variables so that they may be read by OSX Applications, you will need to follow these steps.

  3. Press CMD+Space to open Spotlight and search for Apple Script Editor.

  4. Open Apple Script Editor

  5. Type into Apple Script the following commands to set environment variables:

    do shell script "launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home"
    do shell script "launchctl setenv ANDROID_HOME /users/$(whoami)/Library/Android/sdk"
    do shell script "launchctl setenv ANDROID_NDK_HOME /users/$(whoami)/Library/Android/sdk/ndk-bundle"
  6. Save the file with File Format Application in your Documents/ folder and name it EnvironmentVars.

 5. Next, in Spotlight, search for System Preferences -> open Users and Groups.

6. Under your username, click Login Items.

7. Add the EnvironmentVars script to the login items, so that this script is opened every time you login.


8. Finally, log out and log back in to your mac.

9. After logging in, wait a moment for the script to run (it can take 10 seconds after startup). Then, you can verify that all environment variables have been set correctly by opening a new Terminal window and typing

a. echo “$ANDROID_HOME”
b. echo “$ANDROID_NDK_HOME”
c. echo “$JAVA_HOME”

These should resolve to the correct directories where the Android SDK, NDK and JDK are installed respectively.

Top comments (0)