Mastering Android NDK
上QQ阅读APP看书,第一时间看更新

Using Android command-line tools on OS X

Installation of Android development tools on OS X is straightforward. First of all, you will need to download the required official SDK and NDK packages from http://developer.android.com/sdk/index.html. As we are going for command-line tools, we can use the SDK Tools Only package available at http://dl.google.com/android/android-sdk_r24.0.2-macosx.zip. As for the NDK, OS X Yosemite works with the 64-bit Android NDK, which can be downloaded from http://developer.android.com/tools/sdk/ndk/index.html.

We will install all these tools into the user's home folder; in our case, it is /Users/sk.

To get Apache Ant and Gradle, the best way would be to install the package manager Homebrew from http://brew.sh and bring in the required tools using the following commands:

$ brew install ant
$ brew install gradle

This way you will not be bothered with installation paths and other low-level configuration stuff. The following are the steps to install packages and set path for them:

Note

Since the notion of this book is doing stuff from the command line, we will indeed do so the hard way. However, you are encouraged to actually visit the download page, http://developer.android.com/sdk/index.html, in your browser and check for updated versions of the Android SDK and NDK.

  1. Download the Android SDK for OS X from the official page and put it into your home directory:
    >curl -o android-sdk-macosx.zip http://dl.google.com/android/android-sdk_r24.0.2-macosx.zip
    
  2. Unpack it:
    >unzip android-sdk-macosx.zip
    
  3. Then, download the Android NDK. It comes as a self-extracting binary:
    >curl -o android-ndk-r10e.bin http://dl.google.com/android/ndk/android-ndk-r10e-darwin-x86_64.bin
    
  4. So, just make it executable and run it:
    >chmod +x android-ndk-r10e.bin
    >./android-ndk-r10e.bin
    
  5. The packages are in place. Now, add paths to your tools and all the necessary environment variables to the .profile file in your home directory:
    export PATH=/Users/sk/android-ndk-r10e:/Users/sk/android-ndk-r10e/prebuilt/darwin-x86_64/bin:/Users/sk/android-sdk-macosx/platform-tools:$PATH
    
  6. Use these variables within Android scripts and tools:
    export NDK_ROOT="/Users/sk/android-ndk-r10e"
    export ANDROID_SDK_ROOT="/Users/sk/android-sdk-macosx"
    
  7. Edit the local.properties file to set up the paths on a per-project basis.