From e24e62b3e976bef9fc48585415602dba6f286256 Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Tue, 23 May 2017 10:07:29 -0700 Subject: [PATCH 1/4] Update PATH instructions. --- docs/GettingStarted.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 7fb22ab92863fc..0f8a2d63a74984 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -382,37 +382,37 @@ Finally, click "Apply" to download and install the Android SDK and related build -#### 3. Set up the ANDROID_HOME environment variable +#### 3. Configure the ANDROID_HOME environment variable The React Native tools require some environment variables to be set up in order to build apps with native code. - + -Add the following lines to your `~/.profile` (or equivalent) config file: +Add the following lines to your `$HOME/.bash_profile` config file: + + ``` -export ANDROID_HOME=${HOME}/Library/Android/sdk -export PATH=${PATH}:${ANDROID_HOME}/tools -export PATH=${PATH}:${ANDROID_HOME}/platform-tools +export ANDROID_HOME=$HOME/Library/Android/sdk +export PATH=$PATH:$ANDROID_HOME/tools +export PATH=$PATH:$ANDROID_HOME/platform-tools ``` -Type `source ~/.profile` to load the config into your current shell. - -> Please make sure you export the correct path for `ANDROID_HOME`. If you installed the Android SDK using Homebrew, it would be located at `/usr/local/opt/android-sdk`. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. - -Add the following lines to your `~/.profile` (or equivalent) config file: - ``` -export ANDROID_HOME=${HOME}/Android/Sdk -export PATH=${PATH}:${ANDROID_HOME}/tools -export PATH=${PATH}:${ANDROID_HOME}/platform-tools +export ANDROID_HOME=$HOME/Android/Sdk +export PATH=$PATH:$ANDROID_HOME/tools +export PATH=$PATH:$ANDROID_HOME/platform-tools ``` -Type `. ~/.profile` to load the config into your current shell. + + +> `.bash_profile` is specific to `bash`. If you're using another shell, you will need to edit the appropriate shell-specific config file. + +Type `source $HOME/.bash_profile` to load the config into your current shell. Verify that ANDROID_HOME has been added to your path by running `echo $PATH`. -> Please make sure you export the correct path for `ANDROID_HOME` if you did not install the Android SDK using Android Studio. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. +> Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio "Preferences" dialog, under **Appearance & Behavior** → **System Settings** → **Android SDK**. From ff010b864f1a39b372febed4fa64c608da16af17 Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Tue, 23 May 2017 10:37:00 -0700 Subject: [PATCH 2/4] Add running on device notes. --- docs/GettingStarted.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 0f8a2d63a74984..304ab4b977a222 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -140,6 +140,12 @@ to the [Tutorial](docs/tutorial.html). - If you can't get this to work, see the [Troubleshooting](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md#troubleshooting) section in the README for Create React Native App. +### Running your app on a simulator or virtual device + +Create React Native App makes it really easy to run your React Native app on a physical device without setting up a development environment. If you want to run your app on the iOS Simulator or an Android Virtual Device, please refer to the instructions for building projects with native code to learn how to install Xcode and set up your Android development environment. + +Once you've set these up, you can launch your app on on an Android Virtual Device by running `npm run android`, or on the iOS Simulator by running `npm run ios` (macOS only). + ### Caveats Because you don't build any native code when using Create React Native App to create a project, it's not possible to include custom native modules beyond the React Native APIs and components that are available in the Expo client app. @@ -473,7 +479,7 @@ Either way, you will need to prepare the device to run Android apps for developm ### Using a physical device -If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and [enabling USB debugging](https://developer.android.com/training/basics/firstapp/running-app.html). You can then proceed to the next step. +If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions [here](docs/running-on-device.html). ### Using a virtual device @@ -536,6 +542,10 @@ You should see your new app running in the iOS Simulator shortly. `react-native run-ios` is just one way to run your app. You can also run it directly from within Xcode or [Nuclide](https://nuclide.io/). +### Running on a device + +The above command will automatically run your app on the iOS Simulator by default. If you want to run the app on an actual physical iOS device, please follow the instructions [here](docs/running-on-device.html). + ## Running your React Native application From 483d3b3da97f18dd415c08621967263edbbe5001 Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Tue, 23 May 2017 14:57:04 -0700 Subject: [PATCH 3/4] Expand Debugging, Running on Device guides --- docs/Debugging.md | 24 +++--- docs/GettingStarted.md | 37 +++++----- docs/RunningOnDevice.md | 69 ++++++++++++------ .../img/ConfigureReleaseScheme.png | Bin 0 -> 69365 bytes .../img/RunningOnDeviceCodeSigning.png | Bin 0 -> 109944 bytes .../react-native/img/RunningOnDeviceReady.png | Bin 0 -> 15390 bytes 6 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 website/src/react-native/img/ConfigureReleaseScheme.png create mode 100644 website/src/react-native/img/RunningOnDeviceCodeSigning.png create mode 100644 website/src/react-native/img/RunningOnDeviceReady.png diff --git a/docs/Debugging.md b/docs/Debugging.md index 3c9dfb84871f3c..a2298188018b50 100644 --- a/docs/Debugging.md +++ b/docs/Debugging.md @@ -14,7 +14,7 @@ React Native supports a few keyboard shortcuts in the iOS Simulator. They are de ## Accessing the In-App Developer Menu -You can access the developer menu by shaking your device or by selecting "Shake Gesture" inside the Hardware menu in the iOS Simulator. You can also use the **`Command`**`⌘` + **`D`** keyboard shortcut when your app is running in the iPhone Simulator, or **`Command`**`⌘` + **`M`** when running in an Android emulator. +You can access the developer menu by shaking your device or by selecting "Shake Gesture" inside the Hardware menu in the iOS Simulator. You can also use the `⌘D` keyboard shortcut when your app is running in the iOS Simulator, or `⌘M` when running in an Android emulator. ![](img/DeveloperMenu.png) @@ -22,7 +22,7 @@ You can access the developer menu by shaking your device or by selecting "Shake ## Reloading JavaScript -Instead of recompiling your app every time you make a change, you can reload your app's JavaScript code instantly. To do so, select "Reload" from the Developer Menu. You can also press **`Command`**`⌘` + **`R`** in the iOS Simulator, or press **`R`** twice on Android emulators. +Instead of recompiling your app every time you make a change, you can reload your app's JavaScript code instantly. To do so, select "Reload" from the Developer Menu. You can also press `⌘R` in the iOS Simulator, or tap `R` twice on Android emulators. ### Automatic reloading @@ -61,7 +61,7 @@ In CI/Xcode, YellowBoxes can also be disabled by setting the `IS_TESTING` enviro To debug the JavaScript code in Chrome, select "Debug JS Remotely" from the Developer Menu. This will open a new tab at [http://localhost:8081/debugger-ui](http://localhost:8081/debugger-ui). -Select `Tools → Developer Tools` from the Chrome Menu to open the [Developer Tools](https://developer.chrome.com/devtools). You may also access the DevTools using keyboard shortcuts (**`Command`**`⌘` + **`Option`**`⌥` + **`I`** on Mac, **`Ctrl`** + **`Shift`** + **`I`** on Windows). You may also want to enable [Pause On Caught Exceptions](http://stackoverflow.com/questions/2233339/javascript-is-there-a-way-to-get-chrome-to-break-on-all-errors/17324511#17324511) for a better debugging experience. +Select `Tools → Developer Tools` from the Chrome Menu to open the [Developer Tools](https://developer.chrome.com/devtools). You may also access the DevTools using keyboard shortcuts (`⌘⌥I` on macOS, `Ctrl` `Shift` `I` on Windows). You may also want to enable [Pause On Caught Exceptions](http://stackoverflow.com/questions/2233339/javascript-is-there-a-way-to-get-chrome-to-break-on-all-errors/17324511#17324511) for a better debugging experience. > Note: the React Developer Tools Chrome extension does not work with React Native, but you can use its standalone version instead. Read [this section](docs/debugging.html#react-developer-tools) to learn how. @@ -75,7 +75,7 @@ The debugger will receive a list of all project roots, separated by a space. For ## React Developer Tools -With React Native 0.43 or higher, you can use [the standalone version of React Developer Tools](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) to debug the React component hierarchy. To use it, install the `react-devtools` package globally: +You can use [the standalone version of React Developer Tools](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) to debug the React component hierarchy. To use it, install the `react-devtools` package globally: ``` npm install -g react-devtools @@ -91,11 +91,11 @@ react-devtools It should connect to your simulator within a few seconds. -> Note: if you prefer to avoid global installations, you can add `react-devtools` as a project dependency. With Yarn, you can run `yarn add --dev react-devtools`, and then run `yarn react-devtools` from your project folder to open the DevTools. With npm, you can run `npm install --save-dev react-devtools`, add `"react-devtools": "react-devtools"` to the `scripts` section in your `package.json`, and then run `npm run react-devtools` from your project folder to open the DevTools. +> Note: if you prefer to avoid global installations, you can add `react-devtools` as a project dependency. Add the `react-devtools` package to your project using `npm install --save-dev react-devtools`, then add `"react-devtools": "react-devtools"` to the `scripts` section in your `package.json`, and then run `npm run react-devtools` from your project folder to open the DevTools. ### Integration with React Native Inspector -You can open the [in-app developer menu](#accessing-the-in-app-developer-menu) and choose "Show Inspector". It will bring up an overlay that lets you tap on any UI element and see information about it: +Open the in-app developer menu and choose "Show Inspector". It will bring up an overlay that lets you tap on any UI element and see information about it: ![React Native Inspector](img/Inspector.gif) @@ -109,7 +109,7 @@ You can choose "Hide Inspector" in the same menu to exit this mode. When debugging JavaScript in Chrome, you can inspect the props and state of the React components in the browser console. -First, follow the [instructions for debugging in Chrome](docs/debugging.html#chrome-developer-tools) to open the Chrome console. +First, follow the instructions for debugging in Chrome to open the Chrome console. Make sure that the dropdown in the top left corner of the Chrome console says `debuggerWorker.js`. **This step is essential.** @@ -138,8 +138,6 @@ You can enable a performance overlay to help you debug performance problems by s ## Accessing console logs -Note: if you're using Create React Native App, these already appear in the same terminal output as the packager. - You can display the console logs for an iOS or Android app by using the following commands in a terminal while the app is running: ``` @@ -149,9 +147,11 @@ $ react-native log-android You may also access these through `Debug → Open System Log...` in the iOS Simulator or by running `adb logcat *:S ReactNative:V ReactNativeJS:V` in a terminal while an Android app is running on a device or emulator. +> If you're using Create React Native App, console logs already appear in the same terminal output as the packager. + ## Debugging on a device with Chrome Developer Tools -Note: if you're using Create React Native App, this is configured for you already. +> If you're using Create React Native App, this is configured for you already. On iOS devices, open the file [`RCTWebSocketExecutor.m`](https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTWebSocketExecutor.m) and change "localhost" to the IP address of your computer, then select "Debug JS Remotely" from the Developer Menu. @@ -201,8 +201,8 @@ Alternatively, select "Dev Settings" from the Developer Menu, then update the "D 4. Run ```react-native run-android ``` -5. In a new chrome tab, open : ```chrome://inspect```, click on 'Inspect device' (the one followed by "Powered by Stetho") +5. In a new Chrome tab, open: ```chrome://inspect```, then click on 'Inspect device' (the one followed by "Powered by Stetho"). ## Debugging native code -When working with native code (e.g. when writing native modules) you can launch the app from Android Studio or Xcode and take advantage of the debugging features (setup breakpoints, etc.) as you would in case of building a standard native app. +When working with native code, such as when writing native modules, you can launch the app from Android Studio or Xcode and take advantage of the native debugging features (setting up breakpoints, etc.) as you would in case of building a standard native app. diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 304ab4b977a222..51c40f6ba1d15d 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -133,13 +133,13 @@ Congratulations! You've successfully run and modified your first React Native ap ## Now what? -- If you're curious to learn more about React Native, continue on -to the [Tutorial](docs/tutorial.html). - - Create React Native App also has a [user guide](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md) you can reference if you have questions specific to the tool. - If you can't get this to work, see the [Troubleshooting](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md#troubleshooting) section in the README for Create React Native App. +If you're curious to learn more about React Native, continue on +to the [Tutorial](docs/tutorial.html). + ### Running your app on a simulator or virtual device Create React Native App makes it really easy to run your React Native app on a physical device without setting up a development environment. If you want to run your app on the iOS Simulator or an Android Virtual Device, please refer to the instructions for building projects with native code to learn how to install Xcode and set up your Android development environment. @@ -542,6 +542,8 @@ You should see your new app running in the iOS Simulator shortly. `react-native run-ios` is just one way to run your app. You can also run it directly from within Xcode or [Nuclide](https://nuclide.io/). +> If you can't get this to work, see the [Troubleshooting](docs/troubleshooting.html#content) page. + ### Running on a device The above command will automatically run your app on the iOS Simulator by default. If you want to run the app on an actual physical iOS device, please follow the instructions [here](docs/running-on-device.html). @@ -571,6 +573,8 @@ If everything is set up correctly, you should see your new app running in your A `react-native run-android` is just one way to run your app - you can also run it directly from within Android Studio or [Nuclide](https://nuclide.io/). +> If you can't get this to work, see the [Troubleshooting](docs/troubleshooting.html#content) page. + ### Modifying your app @@ -580,12 +584,12 @@ Now that you have successfully run the app, let's modify it. - Open `index.ios.js` in your text editor of choice and edit some lines. -- Hit `Command⌘ + R` in your iOS Simulator to reload the app and see your changes! +- Hit `⌘R` in your iOS Simulator to reload the app and see your changes! - Open `index.android.js` in your text editor of choice and edit some lines. -- Press the `R` key twice or select `Reload` from the Developer Menu to see your changes! +- Press the `R` key twice or select `Reload` from the Developer Menu (`⌘M`) to see your changes! @@ -594,7 +598,7 @@ Now that you have successfully run the app, let's modify it. Now that you have successfully run the app, let's modify it. - Open `index.android.js` in your text editor of choice and edit some lines. -- Press the `R` key twice or select `Reload` from the Developer Menu to see your changes! +- Press the `R` key twice or select `Reload` from the Developer Menu (`⌘M`) to see your changes! @@ -608,32 +612,31 @@ Congratulations! You've successfully run and modified your first React Native ap ### That's it! -Congratulations! You've successfully run and modified a React Native app. +Congratulations! You've successfully run and modified your first React Native app.
-## Now What? - -- If you're curious to learn more about React Native, continue on -to the [Tutorial](docs/tutorial.html). +## Now what? -- If you can't get this to work, see the [Troubleshooting](docs/troubleshooting.html#content) page. +- Turn on [Live Reload](docs/debugging.html#reloading-javascript) in the Developer Menu. Your app will now reload automatically whenever you save any changes! - If you want to add this new React Native code to an existing application, check out the [Integration guide](docs/integration-with-existing-apps.html). - +If you're curious to learn more about React Native, continue on +to the [Tutorial](docs/tutorial.html). -## Now What? + -- If you're curious to learn more about React Native, continue on -to the [Tutorial](docs/tutorial.html). +## Now what? -- If you can't get this to work, see the [Troubleshooting](docs/troubleshooting.html#content) page. +- Turn on [Live Reload](docs/debugging.html#reloading-javascript) in the Developer Menu. Your app will now reload automatically whenever you save any changes! - If you want to add this new React Native code to an existing application, check out the [Integration guide](docs/integration-with-existing-apps.html). +If you're curious to learn more about React Native, continue on +to the [Tutorial](docs/tutorial.html). - - - -## Creating a release build in Android Studio - -You can use Android Studio to create your release builds too! It’s as easy as creating release builds of your previously-existing native Android app. There’s just one additional step, which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which’ll be included with your native Android app: - - $ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/ - -Don’t forget to replace the paths with correct ones and create the assets folder if it doesn’t exist! - -Now just create a release build of your native app from within Android Studio as usual and you should be good to go!