我有错误,当我开始运行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”的文件夹,其中有一个本地。属性文件。 删除该文件,构建应该会成功运行

其他回答

如果你在windows上转义(添加反斜杠到)反斜杠和冒号在android/local。属性文件。如果没有,就创建一个

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

我在Windows上,我必须修改sdk路径,不管它在path环境中。变量

sdk.dir=C:/Users/MY_USERNAME/AppData/Local/Android/Sdk

更改此文件:

MyProject\android\local.properties

如果你使用mac,你需要导出你的sdk路径。只需将Macbook替换为您的系统名称,然后粘贴到终端。“临时使用”

出口ANDROID_HOME = /用户/笔记本/图书馆/ Android sdk

我能找到的最佳解决方案如下:

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。因此,您不需要担心人工干预。

有两个gradle文件,在你的C:\myapp\android\build中更改一个。Gradle而不是在父目录myapp中。

将23.0.1替换为安装在我的案例中25.0.0的Android构建工具版本

运行react-native Run -android在模拟器中查看你的应用。