本文翻译自:React Native android build failed. SDK location not found

I have error when i start running android 开始运行android时出现错误

What went wrong:
A problem occurred evaluating project ':app'.  
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

#1楼

参考:https://stackoom.com/question/2CvgW/React-Native-Android构建失败-找不到SDK位置


#2楼

  • Go to the android/ directory of your react-native project 转到您的react-native项目的android/目录
  • Create a file called local.properties with this line: 使用以下行创建一个名为local.properties的文件:

     sdk.dir = /Users/USERNAME/Library/Android/sdk 

    Where USERNAME is your OSX username USERNAME是您的OSX用户名


#3楼

You can try adding ANDROID_PATH 您可以尝试添加ANDROID_PATH

export ANDROID_HOME=/Users/<username>/Library/Android/sdk/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

#4楼

复制系统的其他android项目local.properties并粘贴到React-native项目的android文件夹中,它将起作用。


#5楼

If you are on windows escape (add backlashes to) the backslashes and the colon in the android/local.properties file. 如果您使用的是Windows,请在android/local.properties文件中使用android/local.properties和反斜杠和冒号(在其中添加反斜杠)。 If its not there then create it 如果不存在,则创建它

sdk.dir = C\:\\Android\\sdk

#6楼

Make sure you have the proper emulator and Android version installed. 确保您已安装正确的模拟器和Android版本。 That solved the problem for me. 那为我解决了问题。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐