您是否需要按照 Android 与 React Native 的手动链接步骤进行操作?

Do you need to follow manual linking steps for Android with React Native?

当我将第三方组件添加到 React Native 应用程序时,例如 this one,它经常说由于自动链接,您不必遵循手动链接步骤。对于 Android,我注意到在手动链接步骤中添加的代码有 none,例如将代码添加到 MainApplication.java,其中 none 是自动添加的。

谁能解释一下这是怎么回事?尽管自动链接,我是否需要为 Android 执行手动链接步骤?

对于 android,不需要 linking。自 react-native 0.6 以来,auto-link 不直接添加 int MainApplication.java.

在androidsettings.gradle中可以看到这段代码:

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); 

native_modules.gradle 中它将添加包。代码很复杂。我看了几天,只知道一点点。但是我们可以从名字和评论中得到。

def generatedFileName = "PackageList.java"
def generatedFilePackage = "com.facebook.react"
...
  /**
   * Include the react native modules android projects and specify their project directory
   */
  void addReactNativeModuleProjects(DefaultSettings defaultSettings) 

  //here are add the package list
  /**
   * Adds the react native modules as dependencies to the users `app` project
   */
  void addReactNativeModuleDependencies(Project appProject)

  /**
   * Code-gen a java file with all the detected ReactNativePackage instances automatically added
   *
   * @param outputDir
   * @param generatedFileName
   * @param generatedFileContentsTemplate
   */
  void generatePackagesFile(File outputDir, String generatedFileName, String 
  generatedFileContentsTemplate)

最后,我们只需要知道我们不需要link