React Native with Android

React Native — Build a development environment

React Native works with Android (part 3) — Integrate it into Android projects

React Native implementation (4) — Code integration

React Native with Android

Integrate into the Android project

Install JavaScript dependencies

Create an empty text file named package.json in the project root directory and fill in the following

{
  "name": "MyReactNativeApp"."version": "0.0.1"."private": true."scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "react": "6 16.0.0 - alpha."."react-native": "0.44.3"}}Copy the code

The Version field doesn’t make much sense (unless you’re publishing your project to the NPM repository). Scripts is the command used to start the Packager service. The React and React-native versions in Dependencies depend on your specific requirements. In general, we recommend using the latest version. You can use NPM info react for example:

npm info react-native

To view the current latest version. In addition, react-Native has strict requirements for react versions, which cannot be higher or lower than a certain range. There is another way to create package.json. Open the Terminal command line in Android Studio and type NPM init

You’ll find a /node_modules folder in the directory, which contains all the JavaScript dependencies you need.

dependencies {
     ...
     compile "com.facebook.react:react-native:+" // From node_modules.
 }
Copy the code

If you want to specify a specific React Native version, you can use the specific version number instead of +, provided you download it from NPM. Next add a Maven dependent entry to React Native in the build.gradle file of your project, which must be written in the “allProjects” code block:

allprojects {
    repositories {
        ...
        maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/.. /node_modules/react-native/android"}}... }Copy the code

Note the “$rootDir/.. /node_modules/react-native/android” /node_modules/react-native/android” Com. Facebook. React: react – native: 0. 7.0.x.x “exception. If node_modules is displayed in the project, react and React Native are installed. ###### Add. Flowconfig Download the flowconfig file

curl -o .flowconfig [https://raw.githubusercontent.com/facebook/react-native/master/.flowconfig](https://link.jianshu.com/?t=https://raw.git hubusercontent.com/facebook/react-native/master/.flowconfig)Copy the code

Add in the project root directory. Flowconfig can also manually create the browser raw.githubusercontent.com/facebook/re… Url copy content create file add

"start": "node node_modules/react-native/local-cli/cli.js 
Copy the code

Go to package.json file to modify the scripts tag before the figure