diff --git a/autolink/postlink/applicationLinker.js b/autolink/postlink/applicationLinker.js index 5cd253f7f6..5d65b320e0 100644 --- a/autolink/postlink/applicationLinker.js +++ b/autolink/postlink/applicationLinker.js @@ -98,6 +98,11 @@ class ApplicationLinker { } _extendNavigationHost(applicationContent) { + if (this._hasAlreadyLinkedNavigationHost(applicationContent)) { + warnn(' NavigationReactNativeHost is already used, skipping.'); + return applicationContent; + } + if (this._doesExtendReactNativeHost(applicationContent)) { debugn(' Changing host implementation to NavigationReactNativeHost'); return applicationContent @@ -106,11 +111,14 @@ class ApplicationLinker { 'import com.facebook.react.ReactNativeHost;', 'import com.facebook.react.ReactNativeHost;\nimport com.reactnativenavigation.react.NavigationReactNativeHost;' ); - } - - if (this._hasAlreadyLinkedNavigationHost(applicationContent)) { - warnn(' NavigationReactNativeHost is already used, skipping.'); - return applicationContent; + } else if (this._doesExtendDefaultReactNativeHost(applicationContent)) { + debugn(' Changing host implementation to NavigationReactNativeHost'); + return applicationContent + .replace('new DefaultReactNativeHost(this)', 'new NavigationReactNativeHost(this)') + .replace( + 'import com.facebook.react.defaults.DefaultReactNativeHost;', + 'import com.facebook.react.defaults.DefaultReactNativeHost;\nimport com.reactnativenavigation.react.NavigationReactNativeHost;' + ); } throw new Error('There was a problem extending NavigationReactNativeHost().'); @@ -120,6 +128,10 @@ class ApplicationLinker { return /\s*new ReactNativeHost\(this\)\s*/.test(applicationContent); } + _doesExtendDefaultReactNativeHost(applicationContent) { + return /\s*new DefaultReactNativeHost\(this\)\s*/.test(applicationContent); + } + _hasAlreadyLinkedNavigationHost(applicationContent) { return /\s*new NavigationReactNativeHost\(this\)\s*/.test(applicationContent); } diff --git a/autolink/postlink/gradleLinker.js b/autolink/postlink/gradleLinker.js index 86139e9dc6..520539591b 100644 --- a/autolink/postlink/gradleLinker.js +++ b/autolink/postlink/gradleLinker.js @@ -3,7 +3,7 @@ var path = require('./path'); var fs = require('fs'); var { warnn, errorn, logn, infon, debugn } = require('./log'); var { insertString } = require('./stringUtils'); -var DEFAULT_KOTLIN_VERSION = '1.5.31'; +var DEFAULT_KOTLIN_VERSION = '1.7.10'; // This should be the minSdkVersion required for RNN. var DEFAULT_MIN_SDK_VERSION = 21; @@ -74,7 +74,7 @@ class GradleLinker { return contents; } - var match = /classpath\s*\(*["']com\.android\.tools\.build:gradle:/.exec(contents); + var match = /classpath\s*\(*["']com\.android\.tools\.build:gradle.*/.exec(contents); if (match) { debugn(' Adding Kotlin plugin'); return insertString(