You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将React Native 0.71应用转为Library输出AAR文件遇依赖问题

React Native 0.71转Android库输出AAR编译错误解决

问题现象

将现有React Native 0.71应用转为Android库(输出AAR)时,执行./gradlew assembleDebug命令出现以下错误:

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find com.facebook.react:react-android:.
     Required by:
         project :app

已完成操作

  • 将app/build.gradle中的apply plugin: "com.android.application"修改为apply plugin: "com.android.library"
  • 删除defaultConfig块中的applicationId字段

解决方法

1. 明确指定react-android依赖版本

在app/build.gradle的dependencies块中,添加带具体版本号的react-android依赖,版本号需与项目使用的React Native 0.71对应版本一致(可查看项目package.json中的react-native版本):

dependencies {
    // 保留原有其他依赖
    implementation "com.facebook.react:react-android:0.71.14" // 替换为你的RN实际版本
}

2. 确认仓库配置正确

确保项目能拉取到React Native的Android依赖:

  • 若使用根目录build.gradle,在allprojects.repositories中添加:
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "$rootDir/../node_modules/react-native/android" }
        maven { url "$rootDir/../node_modules/jsc-android/dist" }
        // 其他仓库
    }
}
  • 若使用settings.gradle(RN 0.71默认结构),在dependencyResolutionManagement.repositories中添加:
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url "../node_modules/react-native/android" }
        maven { url "../node_modules/jsc-android/dist" }
    }
}

3. 清理并重新构建

执行以下命令清理旧构建文件并重新编译:

./gradlew clean
./gradlew assembleDebug

内容的提问来源于stack exchange,提问作者NITY

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 20:20:18