react_native环境搭建

2017-03-21  本文已影响1472人  我不是死胖子

0 环境搭建

根据http://reactnative.cn/docs/0.41/getting-started.html#content

1. 安装Chocolatey, cmd输入

    @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

2. 安装Python2(不支持3), 使用Chocolatey安装, cmd输入

    choco install python2

3. 安装Node(避开Node7.0以上版本,手动下载), 使用Chocolatey安装, cmd输入,

choco install nodejs.install

建议手动下载安装低版本node

4. 安装yarn(facebook替代npm的工具, 加速node模块下载), 以及ReactNative的命令行工具react-native-cli

npm install -g yarn react-native-cli

5. 安装git,Android Studio和JDK

choco install jdk8
choco install git

6. 配置sdk路径为ANDROID_HOME的环境变量

7. 测试安装

react-native init AwesomeProject
cd AwesomeProject
react-native run-android

问题1 报错"Command yarn add react-native --exact failed."

问题2 adb devices找不到genymotion

问题3 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

问题4 小米关闭"通过usb验证应用程序"

问题4 Failed to establish session

问题5 安装后白屏

问题6 安装后红屏

问题7 模拟器

问题8 未解决红米note2的安装问题

:app:packageDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE
:app:installDebug
Installing APK 'app-debug.apk' on 'Redmi Note 2 - 5.0.2' for app:debug
Unable to install D:\rn\AwesomeProject\android\app\build\outputs\apk\app-debug.a
pk
com.android.ddmlib.InstallException: Failed to install all
        at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:8
9)
        at com.android.ddmlib.Device.installPackages(Device.java:904)
        at com.android.builder.testing.ConnectedDevice.installPackages(Connected
Device.java:137)
        at com.android.build.gradle.internal.tasks.InstallVariantTask.install(In
stallVariantTask.java:134)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:228)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:621)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:604)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:66)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
e(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
ter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
e(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTa
skWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.processTask(AbstractTaskPlanExecutor.java:66)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.
onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableE
xecutorImpl.java:40)
04:01:06 E/1102664595: Error while uploading app-debug.apk : Unknown failure ([C
DS]close[0])
:app:installDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallExc
eption: Failed to install all

* 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: 9.999 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

D:\rn\AwesomeProject>
上一篇下一篇

猜你喜欢

热点阅读