Setting up an Android Development Environment on OSX
Published: 2024-05-02 08:14:35

<div class="i-box i-box-note">
<blockquote><em>The following guide will help you setup a <strong>Development Environment for Android on Mac OSX.</strong> This is required if you wish to compile SciChart's <a href="https://www.scichart.com/android-chart-features/">Android Charts</a> or <a href="https://github.com/abtsoftware/scichart.android.examples">Chart Examples / Demos</a> from source-code. You can skip this if you already have Android Studio and the Android NDK setup!</em></blockquote>
<h2>Installing the Java Development Kit</h2>
1. Using safari, navigate to <a href="https://www.java.com/en/download/">https://www.java.com/en/download/</a> and download Java 8 for mac.

2. You will also need to install the Java Platform JDK from <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a>
<div class="i-box i-box-note">
<blockquote><b><i>NOTE</i></b><i>: 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</i></blockquote>
<h2>Installing Android Studio</h2>
Download Android Studio for MAC from the <a href="https://developer.android.com/studio/index.html#downloads">https://developer.android.com/studio/index.html#downloads</a>. Follow the steps to install the application in OSX.

<img class="alignnone size-full wp-image-8308" src="http://www.scichart.com/wp-content/uploads/2020/01/android-studio-install.jpg" alt="" width="602" height="340" />

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

<img class="alignnone size-full wp-image-8309" src="http://www.scichart.com/wp-content/uploads/2020/01/android-studio-start.jpg" alt="" width="601" height="353" />

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!

<img class="alignnone size-full wp-image-8310" src="http://www.scichart.com/wp-content/uploads/2020/01/android-sdk-location.jpg" alt="" width="602" height="457" />

Once that’s done, open Android Studio and go to Tools -&gt; Android -&gt; 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.

<img class="alignnone size-full wp-image-8311" src="http://www.scichart.com/wp-content/uploads/2020/01/android-sdk-versions.jpg" alt="" width="602" height="406" />

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

<img class="alignnone size-full wp-image-8312" src="http://www.scichart.com/wp-content/uploads/2020/01/android-ndk-versions.jpg" alt="" width="602" height="407" />

Click OK to install all components.
<h2>Installing the Android NDK</h2>
Certain components in SciChart's <a href="https://www.scichart.com/android-chart-features/">Android Chart Library</a> are dependent on the Android NDK (Native Development Kit). Installing this is <b>required if you are building our examples or SciChart Android library from source-code</b>.

The Android NDK can be downloaded via the SDK Manager within Android Studio. Go to Tools -&gt; Android -&gt; SDK Manager. Under Build tools ensure the Android NDK is checked and up to date.
<h2>Installing Gradle</h2>
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 <a href="http://stackoverflow.com/a/28928107/303612">http://stackoverflow.com/a/28928107/303612</a>

1. Install Homebrew (a package manager for OSX)
<pre><code class="language-bash">/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
</code></pre>
2. Install Gradlebrew install gradle
<pre><code class="language-bash">brew install gradle</code></pre>
<h2>Setting Mac OSX Environment Variables</h2>
The following environment variables must be set to allow development of SciChart Android in Android Studio on OSX.
<ul>
 	<li>JAVA_HOME: The location of the Java JDK</li>
 	<li>ANDROID_HOME: The location of the Android SDK on disk</li>
 	<li>ANDROID_NDK_HOME: The location of the Android NDK on disk</li>
</ul>
To set environment variables so that they may be read by OSX Applications, you will need to follow these steps.

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

2. Open Apple Script Editor

3. Type into Apple Script the following commands to set environment variables:
<pre><code class="language-bash">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"</code></pre>
4. Save the file with <b>File</b> <b>Format</b> <b>Application</b> in your Documents/ folder and name it EnvironmentVars.

<img class="alignnone size-full wp-image-8313" src="http://www.scichart.com/wp-content/uploads/2020/01/osx-envrionment-vars.jpg" alt="" width="601" height="446" />
<p dir="ltr"> 5. Next, in Spotlight, search for System Preferences -&gt; open Users and Groups.</p>

</div>
<p dir="ltr"><img class="alignnone size-full wp-image-8314" src="http://www.scichart.com/wp-content/uploads/2020/01/osx-users-groups.jpg" alt="" width="602" height="531" /></p>
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.

</div>
<img class="alignnone size-full wp-image-8315" src="http://www.scichart.com/wp-content/uploads/2020/01/osx-login-script.jpg" alt="" width="602" height="444" />

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
<pre><code class="language-bash">a. echo “$ANDROID_HOME”
b. echo “$ANDROID_NDK_HOME”
c. echo “$JAVA_HOME”</code></pre>
These should resolve to the correct directories where the Android SDK, NDK and JDK are installed respectively.

<img class="alignnone size-full wp-image-8316" src="http://www.scichart.com/wp-content/uploads/2020/01/osx-android-environment-vars-set-correctly.png" alt="" width="612" height="391" />