React Native : target with hash string 'androi

2020-05-19 04:31发布

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?

8条回答
女痞
2楼-- · 2020-05-19 04:48

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

查看更多
叛逆
3楼-- · 2020-05-19 04:50
祖国的老花朵
4楼-- · 2020-05-19 04:50

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

查看更多
太酷不给撩
5楼-- · 2020-05-19 04:54

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)

查看更多
三岁会撩人
6楼-- · 2020-05-19 04:58

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.

查看更多
我命由我不由天
7楼-- · 2020-05-19 05:06

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

查看更多
登录 后发表回答