React Native : target with hash string 'androi

2020-05-19 04:19发布

问题:

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

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?

回答1:

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



回答2:

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)



回答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.



回答4:

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

i just did and works for me



回答5:

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"):



回答6: