git clone https://github.com/facebook/react-native.git
@H_301_0@
三、构建源代码
@H_301_0@
1.添加Node_Modules模块
@H_301_0@
npm install
提示1:
@H_301_0@
pengcx@pengcx-Ubuntu:~/ReactNativeWorkspace/react-native$ npm install
@H_301_0@
npm ERR! Linux 3.13.0-85-generic
@H_301_0@
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
@H_301_0@
npm ERR! node v4.4.2
@H_301_0@
npm ERR! npm v2.15.0
@H_301_0@
npm ERR! file /home/pengcx/.npm/tr46/0.0.3/package/package.json
@H_301_0@
npm ERR! code EJSONPARSE
@H_301_0@
npm ERR! Failed to parse json
@H_301_0@
npm ERR! No data,empty input at 1:1cd
@H_301_0@
npm ERR!
@H_301_0@
npm ERR! ^
@H_301_0@
npm ERR! File: /home/pengcx/.npm/tr46/0.0.3/package/package.json
@H_301_0@
npm ERR! Failed to parse package.json data.
@H_301_0@
npm ERR! package.json must be actual JSON,not just JavaScript.
@H_301_0@
npm ERR! This is not a bug in npm.
@H_301_0@
npm ERR! Tell the package author to fix their package.json file. JSON.parse
@H_301_0@
npm ERR! Please include the following file with any support request:
@H_301_0@
npm ERR! /home/pengcx/ReactNativeWorkspace/react-native/npm-debug.log
@H_301_0@
@H_301_0@
处理:npm cache clean
@H_301_0@
2.运行相应的Demo
@H_301_0@
./gradlew :Example:UIExplorer:android:app:installDebug
提示2:Installing APK 'app-debug.apk' on 'm1 Metal - 5.1' for app:debug
@H_301_0@
03:39:32 E/1194330994: Error while uploading app-debug.apk : Unknown failure ([CDS]close[0])
@H_301_0@
Unable to install /home/pengcx/ReactNativeWorkspace/react-native/Examples/UIExplorer/android/app/build/outputs/apk/app-debug.apk
@H_301_0@
com.android.ddmlib.InstallException: Unable to upload some APKs
@H_301_0@
at com.android.ddmlib.Device.installPackages(Device.java:956)
@H_301_0@
@H_301_0@
... ....
@H_301_0@
:Examples:UIExplorer:android:app:installDebug Failed
@H_301_0@
FAILURE: Build Failed with an exception.
@H_301_0@
* What went wrong:
@H_301_0@
Execution Failed for task ':Examples:UIExplorer:android:app:installDebug'.
@H_301_0@
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unable to upload some APKs
@H_301_0@
* Try:
@H_301_0@
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
@H_301_0@
BUILD Failed
@H_301_0@
Total time: 3 mins 29.331 secs
@H_301_0@
处理:修改项目根目录下的build.gradle文件
@H_301_0@
@H_301_0@
classpath 'com.android.tools.build:gradle:1.2.3'
@H_301_0@
提示3:
@H_301_0@
pengcx@pengcx-Ubuntu:~/ReactNativeWorkspace/react-native$ sudo ./gradlew :Example:UIExplorer:android:app:installDebug
@H_301_0@
FAILURE: Build Failed with an exception.
@H_301_0@
* Where:
@H_301_0@
Build file '/home/pengcx/ReactNativeWorkspace/react-native/ReactAndroid/build.gradle' line: 3、
@H_301_0@
* What went wrong:
@H_301_0@
A problem occurred evaluating project ':ReactAndroid'.
@H_301_0@
> Failed to apply plugin [id 'com.android.library']
@H_301_0@
> Gradle version 2.2 is required. Current version is 2.11. If using the gradle wrapper,try editing the distributionUrl in /home/pengcx/ReactNativeWorkspace/react-native/gradle/wrapper/gradle-wrapper.properties to gradle-2.2-all.zip
@H_301_0@
* Try:
@H_301_0@
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
@H_301_0@
BUILD Failed
@H_301_0@
Total time: 49.768 secs
@H_301_0@
处理:/react-native/gradle/wrapper/gradle-wrapper.properties
@H_301_0@
@H_301_0@
distributionUrl=https://services.gradle.org/distributions/gradle-2.2-all.zip
@H_301_0@
3.启动服务器
@H_301_0@
./packager/packager.sh
提示4:
@H_301_0@
[Hot Module Replacement] Server listening on /hot
@H_301_0@
React packager ready.
@H_301_0@
ERROR EACCES: permission denied,scandir '/home/pengcx/ReactNativeWorkspace/react-native/ReactAndroid/build/third-party-ndk/boost/boost_1_57_0'
@H_301_0@
{"errno":-13,"code":"EACCES","syscall":"scandir","path":"/home/pengcx/ReactNativeWorkspace/react-native/ReactAndroid/build/third-party-ndk/boost/boost_1_57_0"}
@H_301_0@
Error: EACCES: permission denied,121);"> at Error (native)
@H_301_0@
Seehttp://facebook.github.io/react-native/docs/troubleshooting.html
@H_301_0@
for common problems and solutions.
@H_301_0@
处理: sudo ./packager/packager.sh
@H_301_0@
提示5:
@H_301_0@
ERROR A non-recoverable condition has triggered. Watchman needs your help!
@H_301_0@
The triggering condition was at timestamp=1462014845: inotify-add-watch(/home/pengcx/ReactNativeWorkspace/react-native/ReactAndroid/build/tmp/expandedArchives/boost_1_57_0.zip_an0bykhqkyzSEOwihr2ej31lv/boost_1_57_0/boost/geometry/strategies/concepts) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl\
@H_301_0@
All requests will continue to fail with this message until you resolve
@H_301_0@
the underlying problem. You will find more information on fixing this at
@H_301_0@
https://facebook.github.io/watchman/docs/troubleshooting.html#poison-inotify-add-watch
@H_301_0@
{"watchmanResponse":{"version":"4.5.0","error":"A non-recoverable condition has triggered. Watchman needs your help!\nThe triggering condition was at timestamp=1462014845: inotify-add-watch(/home/pengcx/ReactNativeWorkspace/react-native/ReactAndroid/build/tmp/expandedArchives/boost_1_57_0.zip_an0bykhqkyzSEOwihr2ej31lv/boost_1_57_0/boost/geometry/strategies/concepts) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl\nAll requests will continue to fail with this message until you resolve\nthe underlying problem. You will find more information on fixing this at\nhttps://facebook.github.io/watchman/docs/troubleshooting.html#poison-inotify-add-watch\n"}}
@H_301_0@
Error: A non-recoverable condition has triggered. Watchman needs your help!
@H_301_0@
1462014845: inotify-add-watch(/home/pengcx/ReactNativeWorkspace/react-native/ReactAndroid/build/tmp/expandedArchives/boost_1_57_0.zip_an0bykhqkyzSEOwihr2ej31lv/boost_1_57_0/boost/geometry/strategies/concepts) -> The user limit on the total number of inotify watches was reached; increase the fs.inotify.max_user_watches sysctl
@H_301_0@
https://facebook.github.io/watchman/docs/troubleshooting.html#poison-inotify-add-watch
@H_301_0@
at BunserBuf.<anonymous> (/home/pengcx/ReactNativeWorkspace/react-native/node_modules/sane/node_modules/fb-watchman/index.js:95:23)
@H_301_0@
at emitOne (events.js:77:13)
@H_301_0@
at BunserBuf.emit (events.js:169:7)
@H_301_0@
at BunserBuf.process (/home/pengcx/ReactNativeWorkspace/react-native/node_modules/bser/index.js:289:10)
@H_301_0@
at /home/pengcx/ReactNativeWorkspace/react-native/node_modules/bser/index.js:244:12
@H_301_0@
at nextTickCallbackWith0Args (node.js:420:9)
@H_301_0@
at process._tickCallback (node.js:349:13)
@H_301_0@
Seehttp://facebook.github.io/react-native/docs/troubleshooting.html
@H_301_0@
@H_301_0@
for common problems and solutions.
@H_301_0@
处理:
@H_301_0@
echo 256 | sudo tee -a /proc/sys/fs/inotify/max_user_instances
@H_301_0@
echo 32768 | sudo tee -a /proc/sys/fs/inotify/max_queued_events
@H_301_0@
echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches
@H_301_0@
watchman shutdown-server
@H_301_0@
4.手机端Reload JS,运行如下:
@H_301_0@
@H_301_0@