要安装的信息源: - https://facebook.github.io/react-native/docs/getting-started.html
此外,我还添加了环境变量。
然后使用了这些命令,它完美运行:
npm 启动 npm 运行安卓
然后当我运行以下命令时:
React-native run-android
它显示了这个error
:显示错误堆栈的图像
D:ProjectsReact-NativeAwesomeProject>react-native run-android
Scanning 768 folders for symlinks in D:ProjectsReact-NativeAwesomeProjectnod
e_modules (31ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat install
Debug)...
FAILURE: Build failed with an exception.
* Where:
Build file 'D:ProjectsReact-NativeAwesomeProjectandroidappbuild.gradle' li
ne: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : U
nsupported major.minor version 52.0
* 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: 3.124 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
events.js:182
throw er; // Unhandled 'error' event
^
Error: spawn cmd.exe ENOENT
at _errnoException (util.js:1019:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
构建分级
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
显然你的build.gradle文件中有一个错误。
在不查看文件的情况下,我想它可能与最低 android 版本或类似的东西有关。
此 gradle 文件包含构建您的 android 应用程序的所有信息,因此如果它包含错误,您会收到"失败:构建失败,出现异常"。
我已经通过添加适当的环境变量路径解决了这个问题。 请参阅随附的屏幕截图。
C:\Windows\System32*WindowsPowerShell\v1.0*;
C:\Users\gyrix**AppData\Roamingpm**;
C:\Users\gyrix**AppData\Local\Yarn\bin**;
D:\Android\sdk1**platform-tools**;
E:\android-sdk**build-tools\25.0.2**;
D:\Android**sdk1**;
D:\Android\sdk1**tools**;
C:\Program Files**Java\jdk1.8.0_144\bin**;
注意:请以粗体指定文件夹的路径,它可能因系统而异。 enter code here