确保您正在运行Android模拟器或已连接设备

MUH*_* PC 24 android react-native

我试图react-native run-android通过我的React项目运行.之后,我收到如下错误.

  Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.android.support:appcompat-v7:23.0.1.
     Searched in the following locations:
         file:/C:/Users/DELL/.m2/repository/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
         file:/C:/Users/DELL/.m2/repository/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
         https://jcenter.bintray.com/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
         https://jcenter.bintray.com/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
         file:/F:/Android/react/AwesomeProject/node_modules/react-native/android/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.pom
         file:/F:/Android/react/AwesomeProject/node_modules/react-native/android/com/android/support/appcompat-v7/23.0.1/appcompat-v7-23.0.1.jar
     Required by:
         AwesomeProject:app:unspecified
         AwesomeProject:app:unspecified > com.facebook.react:react-native:0.27.2
   > Could not find com.android.support:recyclerview-v7:23.0.1.
     Searched in the following locations:
         file:/C:/Users/DELL/.m2/repository/com/android/support/recyclerview-v7/23.0.1/recyclerview-v7-23.0.1.pom
         file:/C:/Users/DELL/.m2/repository/com/android/support/recyclerview-v7/23.0.1/recyclerview-v7-23.0.1.jar
         https://jcenter.bintray.com/com/android/support/recyclerview-v7/23.0.1/recyclerview-v7-23.0.1.pom
         https://jcenter.bintray.com/com/android/support/recyclerview-v7/23.0.1/recyclerview-v7-23.0.1.jar
         file:/F:/Android/react/AwesomeProject/node_modules/react-native/android/com/android/support/recyclerview-v7/23.0.1/recyclerview-v7-23.0.1.pom
         file:/F:/Android/react/AwesomeProject/node_modules/react-native/android/com/android/support/recyclerview-v7/23.0.1/recyclerview-v7-23.0.1.jar
     Required by:
         AwesomeProject:app:unspecified > com.facebook.react:react-native:0.27.2
   > Could not find com.android.support:support-v4:23.1.1.
     Searched in the following locations:
         file:/C:/Users/DELL/.m2/repository/com/android/support/support-v4/23.1.1/support-v4-23.1.1.pom
         file:/C:/Users/DELL/.m2/repository/com/android/support/support-v4/23.1.1/support-v4-23.1.1.jar
         https://jcenter.bintray.com/com/android/support/support-v4/23.1.1/support-v4-23.1.1.pom
         https://jcenter.bintray.com/com/android/support/support-v4/23.1.1/support-v4-23.1.1.jar
         file:/F:/Android/react/AwesomeProject/node_modules/react-native/android/com/android/support/support-v4/23.1.1/support-v4-23.1.1.pom
         file:/F:/Android/react/AwesomeProject/node_modules/react-native/android/com/android/support/support-v4/23.1.1/support-v4-23.1.1.jar
     Required by:
         AwesomeProject:app:unspecified > com.facebook.react:react-native:0.27.2 > com.facebook.fresco:fresco:0.10.0 > com.facebook.fresco:drawee:0.10.0
         AwesomeProject:app:unspecified > com.facebook.react:react-native:0.27.2 > com.facebook.fresco:fresco:0.10.0 > com.facebook.fresco:imagepipeline:0.10.0
         AwesomeProject:app:unspecified > com.facebook.react:react-native:0.27.2 > com.facebook.fresco:fresco:0.10.0 > com.facebook.fresco:imagepipeline:0.10.0 > com.facebook.fresco:imagepipeline-base:0.10.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: 17.502 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
Run Code Online (Sandbox Code Playgroud)

我安装了Android SDK并成功设置了Android Home和Path Environmental Variable.但我仍然得到同样的错误.

我还在我的电脑上安装了Gennymotion来创建虚拟安卓设备.

Roy*_*l.O 22

您可以检查Android/Gradlew上的权限它们应该是755而不是644.

chmod 755 android/gradlew在app根文件夹中运行.

然后跑react-native run-android.

它应该再次工作.


STE*_*EEL 6

  1. 打开安卓工作室
  2. 打开任何项目或创建一个空项目
  3. Find Action (CMD + SHIFT + A) 类型:AVD Manager
  4. 按回车键打开 AVD 管理器
  5. 单击小铅笔图标(编辑此 AVD)
  6. 点击更改(我们需要 Android 6 (23) 那边) 在此处输入图片说明

  7. 然后选择 Android 6 (23) 并单击确定 在此处输入图片说明

  8. 现在单击编辑(铅笔)旁边的播放按钮,并保持模拟器运行

  9. 现在打开终端,cd TO_YOUR_PROJECT 然后输入:react-native run-android

参考:https : //facebook.github.io/react-native/docs/getting-started.html


cur*_*isp 1

在本React Native AwesomeProject 教程中,作者指出,项目的 Android Studio 构建版本可能需要在项目build.gradle文件中进行更新。

如果您使用的是最新版本的 Android Studio,如果您的教程有点旧,您可能也必须这样做。

找到您的项目build.gradle文件,该文件应位于 \AwesomeProject\android\app\文件夹中。

build.gradle文件中查找buildToolsVersion "23.0.1"并更改为buildToolsVersion "23.0.3"

请注意,您的文件中可能还有另一个"23.0.1"字符串,但该字符串适用于 Android 支持版本,应保持不变。