From 261197d85705dad1a362cc4637aa308c0382dcbe Mon Sep 17 00:00:00 2001 From: Salakar Date: Wed, 24 Apr 2019 06:13:20 -0700 Subject: [PATCH] Implement changes to enable native modules auto linking (#24506) Summary: Replaces #24099 (original PR became detached for some reason) Implements the template changes required to enable native modules auto-linking for both Android & iOS. Requires the following to be merged first and an updated CLI to be published: - [x] https://github.com/react-native-community/react-native-cli/pull/254 - [x] https://github.com/react-native-community/react-native-cli/pull/256 - [x] https://github.com/react-native-community/react-native-cli/pull/258 cc grabbou thymikee orta for review - [ ] https://github.com/facebook/react-native/pull/24517 update CLI version) [TEMPLATE] [FEATURE] - Enable auto-initialization/linking of react native modules for new projects Pull Request resolved: https://github.com/facebook/react-native/pull/24506 Differential Revision: D15062701 Pulled By: cpojer fbshipit-source-id: 65296cbec2925405fe8033de71910325e0c719bc --- template/android/app/build.gradle | 2 ++ .../src/main/java/com/helloworld/MainApplication.java | 11 ++++++----- template/android/settings.gradle | 2 +- template/ios/Podfile | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 208c97217ebc08..0f3c05cbf6491c 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -190,3 +190,5 @@ task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } + +apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) diff --git a/template/android/app/src/main/java/com/helloworld/MainApplication.java b/template/android/app/src/main/java/com/helloworld/MainApplication.java index 8b5a7f97bea556..c35b27063797cf 100644 --- a/template/android/app/src/main/java/com/helloworld/MainApplication.java +++ b/template/android/app/src/main/java/com/helloworld/MainApplication.java @@ -2,13 +2,12 @@ import android.app.Application; +import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; -import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; -import java.util.Arrays; import java.util.List; public class MainApplication extends Application implements ReactApplication { @@ -21,9 +20,11 @@ public boolean getUseDeveloperSupport() { @Override protected List getPackages() { - return Arrays.asList( - new MainReactPackage() - ); + @SuppressWarnings("UnnecessaryLocalVariable") + List packages = new PackageList(this).getPackages(); + // Packages that cannot be autolinked yet can be added manually here, for example: + // packages.add(new MyReactNativePackage()); + return packages; } @Override diff --git a/template/android/settings.gradle b/template/android/settings.gradle index 32e6f44c4b2df5..e50c29d6298864 100644 --- a/template/android/settings.gradle +++ b/template/android/settings.gradle @@ -1,3 +1,3 @@ rootProject.name = 'HelloWorld' - +apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' diff --git a/template/ios/Podfile b/template/ios/Podfile index 5114274b54178e..a25e513a914b07 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -1,4 +1,5 @@ platform :ios, '9.0' +require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'HelloWorld' do # Pods for HelloWorld @@ -31,6 +32,8 @@ target 'HelloWorld' do inherit! :search_paths # Pods for testing end + + use_native_modules! end target 'HelloWorld-tvOS' do