9

Here is the full error: failed to find target with hash string 'android-23' in: /Users/username/Library/Android/sdk

This is the build.gradle file in my android/app:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.mobile"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

I ran the Android SDK Manager, and I have the Android SDK Build-Tools Rev 23.0.1 installed, along with all the files for Android 6.0 (API 23).

I searched online for this problem and have tried many solutions; restarting the terminal, deleting the gradle file in the root directory, making sure ANDROID_HOME points to the correct directory (As I am following the ReactNative docs, I have copied in both ~./bashrc and ~./bash_profile the following line: # If you installed the SDK via Homebrew, otherwise ~/Library/Android/sdk export ANDROID_HOME=/usr/local/opt/android-sdk.

Nothing has worked for me so far and I keep getting the same error. I should add that everything was working fine until I installed Android Studio, after which point I started getting this error. I have since then uninstalled Android Studio naively thinking it would solve the problem.

Please help me SO, you're my only hope.

Frosty619
  • 1,381
  • 4
  • 23
  • 33

2 Answers2

9
  • Find android sdk location.(e.g /Users/username/Library/Android/sdk or /usr/local/opt/android-sdk or /Applications/ADT/sdk)

  • Open shell config file that it depends on what shell you're using. ~/.bash_profile or ~/.bashrc or ~/.zshrc.

  • Edit or add the following lines to shell config file:

$ export ANDROID_HOME=`YOUR_ANDROID_SDK_PATH` 
$ export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
  • Restart the terminal and run again.

Update

Check in official website

References

lwinkyawmyat
  • 1,221
  • 1
  • 16
  • 34
  • 1
    `export PATH = $PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools` there should be no spaces between the `=` sign – coffekid Jan 10 '17 at 21:58
1

Try opening your app up in Android Studio, instead of doing everything via the command line. This worked for me. Android Studio will show you all errors occurring in your build, and provide you with links to install the necessary missing components.

You do need the correct path set for ANDROID_HOME for this to work. I installed android sdk with brew, so my line was export ANDROID_HOME=/usr/local/opt/android-sdk.

Tori Huang
  • 527
  • 1
  • 7
  • 25