Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to build react-native app on Android device :failed to find target with hash string 'android-23'

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.

like image 954
Frosty619 Avatar asked Apr 21 '16 18:04

Frosty619


1 Answers

  • 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

  • Setting ANDROID_HOME enviromental variable on Mac OS X

  • React Native : target with hash string 'android-X' not found

like image 149
lwinkyawmyat Avatar answered Oct 26 '22 19:10

lwinkyawmyat