Browse Source

Adapt installation guide to v5

Guy Carmeli 4 years ago
parent
commit
af27d89999
1 changed files with 124 additions and 177 deletions
  1. 124
    177
      docs/docs/Installing.md

+ 124
- 177
docs/docs/Installing.md View File

@@ -7,11 +7,19 @@
7 7
 ## npm
8 8
 * `npm install --save react-native-navigation`
9 9
 
10
-## iOS
10
+## Installing with react-native link
11
+If you're using RN 0.60 or higher, you can link RNN automatically with react-native link. Otherwise, follow the manual installation steps. Unlike most other libraries, react-native-navigation requires you to make a few changes to native files. To make all the necessary changes, run `react-native link react-native-navigation` in your project's root folder. Make sure to commit the changes introduced by the link script.
12
+
13
+If the link script completed successfully, you're good to go! If one of the steps failed, you'll need to complete the relevant step in the manual installation steps bellow.
14
+
15
+## Manual Installation
16
+If installation with react-native link did not work, follow the manual installation steps.
17
+
18
+### iOS
11 19
 
12 20
 > Make sure your Xcode is updated. We recommend editing `.h` and `.m` files in Xcode as the IDE will usually point out common errors.
13 21
 
14
-### Native Installation
22
+#### Native Installation
15 23
 
16 24
 1. In Xcode, in Project Navigator (left pane), right-click on the `Libraries` > `Add files to [project name]`. Add `node_modules/react-native-navigation/lib/ios/ReactNativeNavigation.xcodeproj` ([screenshots](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking)).
17 25
 
@@ -73,12 +81,13 @@
73 81
   		...
74 82
   	```
75 83
 
76
-### Installation with CocoaPods
84
+#### Installation with CocoaPods
77 85
 
78 86
 Projects generated using newer versions of react-native use CocoaPods by default. In that case it's easier to install react-native-navigation using CocoaPods.
79 87
 
80 88
 1. Update your `Podfile`:
81
-If you're upgrading to v5 from a previous RNN version, make sure to remove manual linking of RNN
89
+**If you're upgrading to v5 from a previous RNN version**, make sure to remove manual linking of RNN
90
+
82 91
 ```diff
83 92
 platform :ios, '9.0'
84 93
 require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
@@ -118,46 +127,31 @@ end
118 127
 
119 128
 2. `cd ios && pod install`
120 129
 
121
-3. Follow 3 and 3b in the Native Installation section.
122
-
123
-## Android
130
+### Android
124 131
 
125 132
 > Make sure your Android Studio installation is updated. We recommend editing `gradle` and `java` files in Android Studio as the IDE will suggest fixes and point out errors, this way you avoid most common pitfalls.
126 133
 
127
-### 1. Add the following in `android/settings.gradle`:
128
-
129
-```groovy
130
-include ':react-native-navigation'
131
-project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/lib/android/app/')
132
-```
133
-
134
-### 2. Make sure you're using the new gradle plugin, edit `android/gradle/wrapper/gradle-wrapper.properties`
135
-
136
-```diff
137
-distributionBase=GRADLE_USER_HOME
138
-distributionPath=wrapper/dists
139
-zipStoreBase=GRADLE_USER_HOME
140
-zipStorePath=wrapper/dists
141
-+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
142
--distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
143
-```
144
-
145
-### 3 Update `android/build.gradle`:
134
+#### 1 Update `android/build.gradle`:
146 135
 
147 136
 ```diff
148 137
 buildscript {
138
+  ext {
139
+-   minSdkVersion = 16
140
++   minSdkVersion = 19 // Or higher
141
+    compileSdkVersion = 26
142
+    targetSdkVersion = 26
143
+    supportLibVersion = "26.1.0"
144
++   RNNKotlinVersion = "1.3.61" // Or any version above 1.3.x
145
++   RNNKotlinStdlib = "kotlin-stdlib-jdk8"
146
+  }
149 147
 	repositories {
150
-+        google()
148
+        google()
149
+        jcenter()
151 150
 +        mavenLocal()
152 151
 +        mavenCentral()
153
-+        jcenter()
154
--        maven {
155
--            url 'https://maven.google.com/'
156
--            name 'Google'
157
--        }
158 152
 	}
159 153
 	dependencies {
160
-+        classpath 'com.android.tools.build:gradle:3.0.1'
154
++        classpath 'com.android.tools.build:gradle:3.5.3' // Or higher
161 155
 -        classpath 'com.android.tools.build:gradle:2.2.3'
162 156
 	}
163 157
 }
@@ -178,91 +172,8 @@ allprojects {
178 172
 +		maven { url 'https://jitpack.io' }
179 173
 	}
180 174
 }
181
-
182
-ext {
183
--    minSdkVersion = 16
184
-+    minSdkVersion = 19
185
-    compileSdkVersion = 26
186
-    targetSdkVersion = 26
187
-    supportLibVersion = "26.1.0"
188
-}
189
-
190
-
191
-```
192
-
193
-### 4 Update project dependencies in `android/app/build.gradle`.
194
-
195
-```diff
196
-android {
197
-    compileSdkVersion rootProject.ext.compileSdkVersion
198
-    buildToolsVersion rootProject.ext.buildToolsVersion
199
-
200
-    defaultConfig {
201
-        applicationId "com.yourproject"
202
-        minSdkVersion rootProject.ext.minSdkVersion
203
-        targetSdkVersion rootProject.ext.targetSdkVersion
204
-        versionCode 1
205
-        versionName "1.0"
206
-        ndk {
207
-            abiFilters "armeabi-v7a", "x86"
208
-        }
209
-    }
210
-+	compileOptions {
211
-+		sourceCompatibility JavaVersion.VERSION_1_8
212
-+		targetCompatibility JavaVersion.VERSION_1_8
213
-+	}
214
-	...
215
-}
216
-
217
-dependencies {
218
--    compile fileTree(dir: "libs", include: ["*.jar"])
219
--    compile "com.facebook.react:react-native:+"  // From node_modules
220
-+    implementation fileTree(dir: "libs", include: ["*.jar"])
221
-+    implementation "com.facebook.react:react-native:+"  // From node_modules
222
-+    implementation project(':react-native-navigation')
223
-}
224
-```
225
-
226
-#### 5.0 Build app with gradle command
227
-
228
-**prefered solution** The RNN flavor you would like to build is specified in `app/build.gradle`. Therefore in order to compile only that flavor, instead of building your entire project using `./gradlew assembleDebug`, you should instruct gradle to build the app module: `./gradlew app:assembleDebug`. The easiest way is to add a package.json command to build and install your debug Android APK .
229
-
230
-```
231
-"scripts": {
232
-  ...
233
-  "android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug"
234
-}
235 175
 ```
236
-
237
-Now run `npm run android` to build your application
238
-
239
-#### 5.1 Ignore other RNN flavors
240
-
241
-If you don't want to run `npm run android` and want to keep the default `react-native run-android` command, you need to specify to graddle to ignore the other flavors RNN provides.
242
-
243
-To do so edit `android/build.gradle` and add:
244
-
245
-```diff
246
-+subprojects { subproject ->
247
-+    afterEvaluate {
248
-+        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
249
-+            android {
250
-+                variantFilter { variant ->
251
-+                    def names = variant.flavors*.name
252
-+                    if (names.contains("reactNative51") || names.contains("reactNative55")) {
253
-+                        setIgnore(true)
254
-+                    }
255
-+                }
256
-+            }
257
-+        }
258
-+    }
259
-+}
260
-```
261
-
262
-**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative51") || names.contains("reactNative55")`). This is why we recommend the first solution.
263
-
264
-
265
-### 6. Update `MainActivity.java`
176
+#### 2 Update `MainActivity.java`
266 177
 
267 178
 `MainActivity.java` should extend `com.reactnativenavigation.NavigationActivity` instead of `ReactActivity`.
268 179
 
@@ -283,7 +194,7 @@ This file is located in `android/app/src/main/java/com/<yourproject>/MainActivit
283 194
 
284 195
 If you have any **react-native** related methods, you can safely delete them.
285 196
 
286
-### 7. Update `MainApplication.java`
197
+#### 3 Update `MainApplication.java`
287 198
 
288 199
 This file is located in `android/app/src/main/java/com/<yourproject>/MainApplication.java`.
289 200
 
@@ -299,49 +210,110 @@ import com.facebook.soloader.SoLoader;
299 210
 
300 211
 +import com.reactnativenavigation.NavigationApplication;
301 212
 +import com.reactnativenavigation.react.NavigationReactNativeHost;
302
-+import com.reactnativenavigation.react.ReactGateway;
303
-
304
-import java.util.Arrays;
305
-import java.util.List;
306 213
 
307 214
 -public class MainApplication extends Application implements ReactApplication {
308 215
 +public class MainApplication extends NavigationApplication {
309
-+
310
-+    @Override
311
-+    protected ReactGateway createReactGateway() {
312
-+        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
313
-+            @Override
314
-+            protected String getJSMainModuleName() {
315
-+                return "index";
316
-+            }
317
-+        };
318
-+        return new ReactGateway(this, isDebug(), host);
319
-+    }
320
-+
321
-+    @Override
322
-+    public boolean isDebug() {
323
-+        return BuildConfig.DEBUG;
324
-+    }
325
-+
326
-+    protected List<ReactPackage> getPackages() {
327
-+        // Add additional packages you require here
328
-+        // No need to add RnnPackage and MainReactPackage
329
-+        return Arrays.<ReactPackage>asList(
330
-+            // eg. new VectorIconsPackage()
331
-+        );
216
+
217
+private final ReactNativeHost mReactNativeHost =
218
+-      new ReactNativeHost(this) {
219
++      new NavigationReactNativeHost(this) {
220
+        @Override
221
+        public boolean getUseDeveloperSupport() {
222
+          return BuildConfig.DEBUG;
223
+        }
224
+
225
+        @Override
226
+        protected List<ReactPackage> getPackages() {
227
+          @SuppressWarnings("UnnecessaryLocalVariable")
228
+          List<ReactPackage> packages = new PackageList(this).getPackages();
229
+          // Packages that cannot be autolinked yet can be added manually here, for example:
230
+          // packages.add(new MyReactNativePackage());
231
+          return packages;
232
+        }
233
+
234
+        @Override
235
+        protected String getJSMainModuleName() {
236
+          return "index";
237
+        }
238
+      };
239
+
240
+  @Override
241
+  public ReactNativeHost getReactNativeHost() {
242
+    return mReactNativeHost;
243
+  }
244
+
245
+  @Override
246
+  public void onCreate() {
247
+    super.onCreate();
248
+-    SoLoader.init(this, /* native exopackage */ false);
249
+    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
250
+  }
251
+}
252
+```
253
+
254
+## You can use react-native-navigation \o/
255
+
256
+Update `index.js` file
257
+```diff
258
++import { Navigation } from "react-native-navigation";
259
+-import {AppRegistry} from 'react-native';
260
+import App from "./App";
261
+-import {name as appName} from './app.json';
262
+
263
+-AppRegistry.registerComponent(appName, () => App);
264
++Navigation.registerComponent(`navigation.playground.WelcomeScreen`, () => App);
265
+
266
++Navigation.events().registerAppLaunchedListener(() => {
267
++  Navigation.setRoot({
268
++    root: {
269
++      component: {
270
++        name: "navigation.playground.WelcomeScreen"
271
++      }
332 272
 +    }
333
-+
334
-+    @Override
335
-+    public List<ReactPackage> createAdditionalReactPackages() {
336
-+        return getPackages();
273
++  });
274
++});
275
+```
276
+
277
+⚠️ we use the layout type `component` here, which renders a React component but does not allow you to navigate to others. See [Usage](docs/Usage.md) and [LayoutTypes](docs/layout-types.md) for more options.
278
+
279
+## Troubleshooting
280
+### Build app with gradle command
281
+**prefered solution** - The RNN flavor you would like to build is specified in `app/build.gradle`. Therefore in order to compile only that flavor, instead of building your entire project using `./gradlew assembleDebug`, you should instruct gradle to build the app module: `./gradlew app:assembleDebug`. The easiest way is to add a package.json command to build and install your debug Android APK .
282
+
283
+```
284
+"scripts": {
285
+  ...
286
+  "android": "cd ./android && ./gradlew app:assembleDebug && ./gradlew installDebug"
287
+}
288
+```
289
+
290
+Now run `npm run android` to build your application
291
+
292
+### Ignore other RNN flavors
293
+If you don't want to run `npm run android` and want to keep the default `react-native run-android` command, you need to instruct gradle to ignore the other flavors RNN provides.
294
+
295
+To do so edit `android/build.gradle` and add:
296
+
297
+```diff
298
++subprojects { subproject ->
299
++    afterEvaluate {
300
++        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
301
++            android {
302
++                variantFilter { variant ->
303
++                    def names = variant.flavors*.name
304
++                    if (names.contains("reactNative51") || names.contains("reactNative55")) {
305
++                        setIgnore(true)
306
++                    }
307
++                }
308
++            }
309
++        }
337 310
 +    }
338
-- ...
339 311
 +}
340
-
341 312
 ```
342 313
 
343
-### 8. Force the same support library version across all dependencies (optional)
314
+**Note**: As more build variants come available in the future, you will need to adjust the list (`names.contains("reactNative51") || names.contains("reactNative55")`). This is why we recommend the first solution.
344 315
 
316
+### Force the same support library version across all dependencies
345 317
 Some of your dependencies might require a different version of one of Google's support library packages. This results in compilation errors similar to this:
346 318
 
347 319
 ```
@@ -375,28 +347,3 @@ dependencies {
375 347
 }
376 348
 
377 349
 ```
378
-
379
-## You can use react-native-navigation \o/
380
-
381
-Update `index.js` file
382
-```diff
383
-+import { Navigation } from "react-native-navigation";
384
--import {AppRegistry} from 'react-native';
385
-import App from "./App";
386
--import {name as appName} from './app.json';
387
-
388
--AppRegistry.registerComponent(appName, () => App);
389
-+Navigation.registerComponent(`navigation.playground.WelcomeScreen`, () => App);
390
-
391
-+Navigation.events().registerAppLaunchedListener(() => {
392
-+  Navigation.setRoot({
393
-+    root: {
394
-+      component: {
395
-+        name: "navigation.playground.WelcomeScreen"
396
-+      }
397
-+    }
398
-+  });
399
-+});
400
-```
401
-
402
-⚠️ we use the layout type `component` here, which renders a React component but does not allow you to navigate to others. See [Usage](docs/Usage.md) and [LayoutTypes](docs/layout-types.md) for more options.