Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 948
feat: autolinking for Android with Gradle#258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f5f62719734a8f3ab1c46703098f4f1767532da7cf942db96dcb036293090f84afecc28f947ce4af1cfe830e929505e4d064f3f5a933512a9815ff2e50001a2b3e016bfc9ed72180a5a7abcaeb225d739623b6433c7f36bb3cbf3bdb90f504b67b8b34224eb717687b50674d7752104b8a491a81f1da28089669bc2c30e7d71658b5c13c1aa575d6c7b67f2e60053905941d8f8d08a00b6e97cdb5869f66a9ecd25ad00b3a7fb13b5c3c7c97a7115f108b873File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,250 @@ | ||||||
| import groovy.json.JsonSlurper | ||||||
| import org.gradle.initialization.DefaultSettings | ||||||
| def generatedFileName = "PackageList.java" | ||||||
| def generatedFileContentsTemplate = """ | ||||||
| package com.facebook.react; | ||||||
| import android.app.Application; | ||||||
| import android.content.Context; | ||||||
| import android.content.res.Resources; | ||||||
| import com.facebook.react.ReactPackage; | ||||||
| import com.facebook.react.shell.MainReactPackage; | ||||||
| import java.util.Arrays; | ||||||
| import java.util.List; | ||||||
| {{ packageImports }} | ||||||
| public class PackageList { | ||||||
| private ReactNativeHost reactNativeHost; | ||||||
| public PackageList(ReactNativeHost reactNativeHost) { | ||||||
| this.reactNativeHost = reactNativeHost; | ||||||
| } | ||||||
| private ReactNativeHost getReactNativeHost() { | ||||||
| return this.reactNativeHost; | ||||||
| } | ||||||
| private Resources getResources() { | ||||||
| return this.getApplication().getResources(); | ||||||
| } | ||||||
| private Application getApplication() { | ||||||
| return this.reactNativeHost.getApplication(); | ||||||
| } | ||||||
| private Context getApplicationContext() { | ||||||
| return this.getApplication().getApplicationContext(); | ||||||
| } | ||||||
| public List<ReactPackage> getPackages() { | ||||||
| return Arrays.<ReactPackage>asList( | ||||||
| new MainReactPackage(){{ packageClassInstances }} | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| """ | ||||||
| class ReactNativeModules { | ||||||
| private Logger logger | ||||||
| private Project project | ||||||
| private DefaultSettings defaultSettings | ||||||
| private ExtraPropertiesExtension extension | ||||||
| private ArrayList<HashMap<String, String>> reactNativeModules | ||||||
| private static String LOG_PREFIX = ":ReactNative:" | ||||||
| private static String REACT_NATIVE_CLI_BIN = "node_modules${File.separator}@react-native-community${File.separator}cli${File.separator}build${File.separator}index.js" | ||||||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RN can technically be in monorepo so we can't make assumptions about where node_modules with cli are. That's why in iOS implementation we spawn a Node process and use its
| ||||||
| cmdProcess =Runtime.getRuntime().exec(REACT_NATIVE_CONFIG_CMD, null, getReactNativeProjectRoot()) |
| if (this.extension.has("reactNativeProjectRoot")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so it won't be seamless but at least that's supported. We need to add documentation on how the autolinking is working on how to configure it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Salakar, we already have config.root in our config outputted from react-native config. You could use that one.
Also, you can just do console.log(require.resolve('react-native')) script and exec node to get the exact location. I think this is what we use on iOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if there's any way we can wrap an instance of ReactPackage here to LazyReactPackage. By default, packageClassInstance is e.g. new CodePushPackage() and in order to convert it to a LazyPackage, we would have to update that package itself.
Is there a way to wrap it or create our custom lazy package for each ReactPackage, that will lazily create it and return everything what's needed?
SalakarApr 18, 2019 •
edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the CodePushPackage class itself would need to extend LazyReactPackage instead of ReactPackage for this to work? Not something we can do? 🤷♂️
Would forcing every package to be lazy also cause issues for packages that are not inherently meant to be lazy, e.g. modules that have app initialization logic that must always be run?
Not 100% sure
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,7 @@ | ||
| "xmldoc": "^0.4.0" | ||
| }, | ||
| "files": [ | ||
| "build" | ||
| "build", | ||
| "native_modules.gradle" | ||
| ] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.