Skip to content

Commit

Permalink
Implement changes to enable native modules auto linking (#24506)
Browse files Browse the repository at this point in the history
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] react-native-community/cli#254
- [x] react-native-community/cli#256
- [x] react-native-community/cli#258

cc grabbou thymikee orta for review

- [ ] #24517 update CLI version)

[TEMPLATE] [FEATURE] - Enable auto-initialization/linking of react native modules for new projects
Pull Request resolved: #24506

Differential Revision: D15062701

Pulled By: cpojer

fbshipit-source-id: 65296cbec2925405fe8033de71910325e0c719bc
  • Loading branch information
Salakar authored and facebook-github-bot committed Apr 24, 2019
1 parent 706f67a commit 261197d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions template/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,9 +20,11 @@ public boolean getUseDeveloperSupport() {

@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> 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
Expand Down
2 changes: 1 addition & 1 deletion template/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 3 additions & 0 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,6 +32,8 @@ target 'HelloWorld' do
inherit! :search_paths
# Pods for testing
end

use_native_modules!
end

target 'HelloWorld-tvOS' do
Expand Down

3 comments on commit 261197d

@hramos
Copy link
Contributor

@hramos hramos commented on 261197d May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've traced the test_end_to_end test's iOS e2e failures back to the Podfile changes in this commit. I've proposed these get reverted in #24788. I'd like to make sure these changes remain in the codebase, if you can find a way to fix this forward without a revert, please let us know!

@Salakar
Copy link
Contributor Author

@Salakar Salakar commented on 261197d May 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @thymikee - any idea why it's failing to find the CLI bin for this? Looks like the pod install is trying to read the config but node can't find the CLI

Failure: https://circleci.com/gh/facebook/react-native/86171?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

image

@thymikee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, haven't played with the test suite on RN repo, but @grabbou definitely knows more on the topic

Please sign in to comment.