Using The Android BOX SDK With Android Studio

This is a guide on how to use Box’s Android SDK in Android Studio. Parts of this guide are derived from ReadMe files provided by Box, the rest is provided to fill in the blanks about how to actually do this.

Step 1: Install Gradle (OSX Mavericks)

We will need Gradle installed to build and install some key dependencies.

  • Download the Gradle 1.6 (NOT THE LATEST GRADLE, IT MUST BE 1.6 ONLY): http://www.gradle.org/downloads
  • Unzip the full directory
  • Move the contents of this directory to: /Users/*****(yourname)/Developer/gradle (or your desired directory)
  • Now run “vi .bashrc”
  • Add the following lines to your .bashrc:
GRADLE_HOME=/Users/*****/Development/gradle
export GRADLE_HOME
export PATH=$PATH:$GRADLE_HOME/bin

Step 2: Download & Build The Box Java SDK

Before you can use the Box Android SDK in Android Studio you must install the Box Java SDK V2.

Step 3: Install Maven

We must also install the Android Support Library for this to work. To do that, we must also install Maven.

  • Simply use Homebrew to get Maven: “brew install maven”
  • “mvn -v” to see if Maven is installed in the Terminal

Step 4: Install The Android Support Library

Next, time to install Android Support Library using Maven.

In my case, I use “~/Applications/Android Studio.app/sdk” because this is where Android Studio installs it’s SDK by default. Here is the Maven command that worked for me (note you must wrap the path in “‘s).

Additional Note: On OSX you have two application’s directories, one at the very root path and the other under your Users folder. The below command must target the appropriate directory where you have Android Studio installed.

mvn install:install-file \
-Dfile="/Applications/Android Studio.app/sdk/extras/android/support/v4/android-support-v4.jar" \
-DgroupId=com.google.android \
-DartifactId=support-v4 \
-Dversion=r13 \
-Dpackaging=jar

This should yield the following message or something like it:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /Applications/Android Studio.app/sdk/extras/android/support/v4/android-support-v4.jar to /Users/rexstjohn/.m2/repository/com/google/android/support-v4/r13/support-v4-r13.jar
[INFO] Installing /var/folders/49/6kvdjbmx2_55s6mt2vbdl12r0000gn/T/mvninstall6323110116717365831.pom to /Users/rexstjohn/.m2/repository/com/google/android/support-v4/r13/support-v4-r13.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.448s
[INFO] Finished at: Sun Dec 01 14:20:37 PST 2013
[INFO] Final Memory: 3M/81M
[INFO] ------------------------------------------------------------------------

Step 5: Build the BOX SDK

If you haven’t already, download the Box Android SDK (This is a totally separate SDK from the BOX Java SDK we installed earlier, which is also required).

Download, unzip (or use Git to fetch) the BOX Android SDK directory and navigate to the “BoxAndroidLibraryV2” folder using the terminal.

You may need to add a “local.properties” file into the project directory with the following variable: “sdk.dir=/Users/*****/android-sdks/”

Otherwise, set your ANDROID_HOME environmental variable in your .bashrc like so:

ANDROID_HOME=/Applications/Android\ Studio.app/sdk
export ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME

And then “source .bashrc” to make it official.

Now run: “gradle build” while in the BoxAndroidLibraryV2 directory, you should get the following:

...
:processReleaseJavaRes UP-TO-DATE
:packageReleaseJar UP-TO-DATE
:packageReleaseLocalJar UP-TO-DATE
:packageReleaseRenderscript UP-TO-DATE
:packageReleaseResources UP-TO-DATE
:bundleRelease UP-TO-DATE
:assembleRelease UP-TO-DATE
:assemble UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 11.583 secs

Finally, add the BoxAndroidLibraryV2 to your Gradle dependencies of your Android project:

dependencies {
	...
	compile project(':box-android-sdk-private:BoxAndroidLibraryV2')
}

Next you will need to build in the Box SDK using a multi-project setup. You can read about how to do that here: http://rexstjohn.com/exporting-android-project-eclipse-android-studio-0-4-0/