【问题标题】:How to include AAR in React Native Android?如何在 React Native Android 中包含 AAR?
【发布时间】:2022-10-20 19:37:16
【问题描述】:

在我的 React Native Android 项目中,我想使用我自己的包含 AAR 文件的库。 有人可以指导如何在我的 Android 版本中使用 AAR 文件。

以下是我的配置 -

  1. 反应原生 - 0.69.1
  2. gradle - 7.4.2
  3. Android Studio Bumblebee - 2021.1.1 补丁 3
  4. openjdk - “18.0.1.1” 2022-04-22

    我在创建构建时遇到错误 -

    Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :library-name project caused this error**

【问题讨论】:

    标签: android react-native android-studio gradle android-gradle-plugin


    【解决方案1】:

    在“react-native-module-name/android/app/build.gradle”中使用它:

    dependencies {
      implementation fileTree(dir: "libs", include: ["*.aar"])
    }
    

    将 .aar 文件复制到“react-native-module-name/android/app/libs”

    由于此解决方案不起作用 你可以这样做 -

    从 /libs 中删除库并使用 -

    File -> New -> New Module -> Import .JAR/.AAR
    

    创建一个新目录并将以下依赖项放入 build.gradle

    dependencies {
     implementation project(":imported_aar_module")
    }
    

    将 .aar 文件放在这里到下一个目录,在 build.gradle 文件旁边

    将创建的 Gradle 项目添加到 settings.gradle -

    include(":pathToTheCreatedDirectory")
    

    将文件包含到目录中 -

    implementation project(":pathToTheCreatedDirectory", 
    configuration = "default")
    

    【讨论】:

    • 但我不想手动执行,我希望在安装库时,我的 react-native android 模块从库的库中获取 aar 文件
    • 我遇到了与我的问题中提到的相同的错误
    • @ShubhamBisht,我添加了更改看看
    • 我需要确认一件事,当您使用 react-native-module-name 时,您是指我的 React-Native 项目还是我在 React-Native 项目中使用的库?
    • 你的 react-native 项目
    【解决方案2】:

    library.aar 文件复制到react-native-module-name/android/app/libs。如果libs 文件夹不存在,请创建它。

    react-native-module-name/android/app/build.gradle:

    dependencies {
     implementation fileTree(dir: "libs", include: ["*.aar"])
     implementation 'com.facebook.react:react-native:+'  // From node_modules
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 2021-06-22
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多