我有错误,当我开始运行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.
我有错误,当我开始运行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.
当前回答
我能找到的最佳解决方案如下:
Download Android Studio and SDK of your choice (Even if you think you don't need it trust me that you would need it to release the apk file and some manual changes to the android code). File > New > Import , point to the location where your react native android project is. If it ask you to download any specific SDK then please download the same. It can ask you to update gradle etc... Please keep on updating where required. If you have an existing Android SDK and you know the version then all you have to do is match that version under build.gradle of your android project.
这是gradle文件看起来的样子:
如果你的机器设置一切顺利,你可以使用Android Studio编译项目,那么没有什么会阻止你通过react-native cli build Android命令构建你的应用程序。
使用这种方法,您不仅可以解决SDK的问题,还可以解决与Android开发的机器设置相关的许多问题。导入将自动找到SDK位置并创建local.properties。因此,您不需要担心人工干预。
其他回答
确保你安装了合适的模拟器和Android版本。这为我解决了问题。
将系统中的其他android项目复制到本地。属性和粘贴在React-native项目的android文件夹中,它将工作。
这对我很管用。
我在Udemy上使用Stephen Grider的React Native,其中一个学生在第50课上发布了这个。在命令行中逐字粘贴(当然是w/o '$')。
$ export "ANDROID_HOME=/usr/local/opt/android-sdk" >~/.bash_profile
去你的React-native项目-> Android 创建文件local.properties 打开文件 粘贴你的Android SDK路径如下 在Windows sdk中。dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk 在macOS sdk中。dir = /Users/USERNAME/Library/Android/sdk 在Linux sdk中。dir = /home/USERNAME/Android/Sdk
将USERNAME替换为用户名
现在,在终端上运行react-native Run -android。
~ /开放。Bash_profile和add:
export ANDROID_HOME=~/Library/Android/sdk/
export PATH=$PATH:~/android-sdks/platform-tools/
export PATH=$PATH:~/android-sdks/tools/
源~ / . bash_profile