36

I am trying to develop my first react-native Android app. When I run

sudo react-native run-android

I get the following error

JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> failed to find target with hash string 'android-23' in: /usr/local/Cellar/android-sdk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.981 secs
Could not install the app on the device, see the error above.

I have 24.3.3 under /usr/local/Cellar/android-sdk with all API-23 packages installed

enter image description here

My android/app/build.gradle says

compileSdkVersion 23
buildToolsVersion "23.0.0"

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

When I try $ANDROID_HOME, it says -bash: /usr/local/Cellar/android-sdk/24.3.3: is a directory.

I have also added local.properties under android/app/ and added sdk.dir=/usr/local/Cellar/android-sdk/24.3.3

Am I missing something?

Jaseem Abbas
  • 5,028
  • 6
  • 48
  • 73
  • Could you please elaborate as to how to do this? I am having the exact same problem and have tried everything without avail. Please have a look at my post [here](http://stackoverflow.com/questions/36778085/unable-to-build-react-native-app-on-android-device-failed-to-find-target-with-h) and help if you can. – Frosty619 Apr 21 '16 at 18:58

8 Answers8

12

Your $ANDROID_HOME should point to /usr/local/android-sdk and it would be the parent directory of platforms and platform-tools

Gradle will try to locate tools dir in the following location: $ANDROID_HOME/platform/android-23 so verify that you have your tools installed there if the android-23 folder is not present inside $ANDROID_HOME/platform/ , please install Android 6.0 (API23)

tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
kzzzf
  • 2,614
  • 1
  • 16
  • 7
10

You need to point ANDROID_HOME to the parent directory of platforms and platform-tools so /usr/local/Cellar/android-sdk

Matija Grcic
  • 12,963
  • 6
  • 62
  • 90
  • Could you please elaborate as to how to do this? I am having the exact same problem and have tried everything without avail. Please have a look at my post [here](http://stackoverflow.com/questions/36778085/unable-to-build-react-native-app-on-android-device-failed-to-find-target-with-h) and help if you can. – Frosty619 Apr 21 '16 at 18:58
  • @Frosty619 One of the things that threw me off was that I was working in Android Studio and I assumed that the SDK files would be saved in the same directory as the Studio files. Not so, and even though the SDK Path is listed right on top of the SDK Manager, I missed it completely. – Brendan Jul 26 '16 at 12:30
3

What I did was to change the target my application was compiled against. To do this edit the file android/app/build.gradle on your project and modify the following:

compileSdkVersion 24
buildToolsVersion "24.0.2"

This should match whatever you have installed without requiring to download another API version.

Eldelshell
  • 6,683
  • 7
  • 44
  • 63
  • This worked for me, but I also had to change the `com.android.support:appcompat-v7` dependency to the right version (which I found [here](https://developer.android.com/topic/libraries/support-library/revisions.html). – Rob Johansen Dec 15 '16 at 17:47
  • Also, take into account that you'll be doing this for any library that requires any platform build to happen. – Eldelshell Dec 15 '16 at 18:24
0

please try to install android 6.0 (Marshmallow) api level 23

i just did and works for me

android 6.0 (Marshmallow) api level 23

Lafif Astahdziq
  • 3,788
  • 29
  • 38
0

I followed the React Native Getting Started instructions and my ANDROID_HOME and PATH was right but I was still getting this error.

The solution was to install "Android 6.0 (Marshmallow)" from this screen (without clicking "Show Package Details"):

David Boyd
  • 6,501
  • 3
  • 21
  • 13
0

i solved this problem,and just replaced export ANDROID_HOME=/usr/local/Cellar/android-sdk by export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1

android sdk

Liruwei
  • 1
  • 1
0

None of the above solutions worked for me, working on a react native app generated with Ignite. Finally, I opened the project up in Android Studio, instead of doing everything via the command line, and a bunch of errors popped up. Fixing the errors one by one within Android Studio solved this problem for me.

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

Tori Huang
  • 527
  • 1
  • 7
  • 25
0

What helped me - I've just removed all installed SDK Platforms and SDK tools using Android SDK Tool

Android SDK Tool

And Run build again and Android Studio found what it should install and where. If you will follow this instruction - make sure you are running Android Studio with enough permissions to install everything.

Have fun with this issue! Hope it will help you

denieler
  • 237
  • 3
  • 8