React Native Android:使用gradle导入另一个项目不起作用



我正在使用ReactNative构建一个Android项目。我正试图通过Gradle将另一个Android项目导入到我的React Native Android项目中。但当我运行该项目时,它抛出了一个错误。

我将另一个项目文件夹复制到我的ReactNative项目{root}/另一个项目中

然后我把settings.gradle文件改成了这个

rootProject.name = 'TestReactNative'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':anotherproject'
project(':anotherproject').projectDir = new File('../anotherproject')

当我跑";react native run android";,我得到以下错误。

FAILURE: Build failed with an exception.
* What went wrong:
Project 'app' not found in root project 'TestReactNative'.

我所做的事情出了什么问题?我该如何解决?

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org

在settings.gradle中,您应该添加另一个项目的android/app的路径。

include ':anotherproject'
project(':anotherproject').projectDir = file('../anotherproject/android/app')

在父项目的android/app/build.gradle中,您需要添加另一个项目作为依赖项。

dependencies {
implementation project(":anotherproject")
}

最后,另一个项目应该只有android目录中的应用程序文件夹。在app/build.gradle中,确保它是一个库,而不是像这样的应用程序:

apply plugin: "com.android.library"

最新更新