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

React Native构建报错:无法确定:notifee_react-native:compileDebugAidl任务依赖

问题描述

在Windows环境下执行npx react-native run-android启动React Native项目时构建失败,核心错误:

无法确定任务:notifee_react-native:compileDebugAidl的依赖,提示已安装的Build Tools版本33.0.0损坏,需通过SDK Manager卸载重装。

检查发现%LOCALAPPDATA%\Android\Sdk\build-tools\33.0.0目录内容不完整,仅包含renderscript文件夹、listing.txt和package.xml;而33.0.1目录包含完整的构建工具文件。

同时构建过程中出现两个额外提示:

  • Android Gradle插件7.2.1与compileSdk 33不兼容警告
  • 系统镜像路径不一致提示

项目关键配置

android\build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.1"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.2.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:5.0.1")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        maven { url 'https://www.jitpack.io' }
    }
}

package.json

{
  "name": "PiekverbruikMonitor",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@notifee/react-native": "^7.3.0",
    "react": "18.1.0",
    "react-native": "0.70.4"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "0.72.3",
    "react-test-renderer": "18.1.0"
  },
  "jest": {
    "preset": "react-native"
  }
}
解决方案

1. 修复损坏的Build Tools 33.0.0

  • 打开Android Studio的SDK Manager,进入SDK Tools标签,取消勾选Android SDK Build-Tools 33.0.0,点击"Apply"完成卸载
  • 卸载后重新勾选该版本并安装,确保下载完整;也可直接删除%LOCALAPPDATA%\Android\Sdk\build-tools\33.0.0目录后再通过SDK Manager重装

2. 强制所有模块使用统一Build Tools版本

第三方依赖(如@notifee/react-native)可能自行指定旧版本Build Tools,需在根build.gradle的allprojects块中添加全局配置:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty("android")) {
            android {
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

3. 解决AGP与compileSdk兼容问题

Android Gradle插件7.2.1对compileSdk 33的支持存在警告,建议升级插件版本:

  • 将根build.gradle中com.android.tools.build:gradle的版本从7.2.1改为7.3.1(完美适配compileSdk 33)
  • 打开gradle/wrapper/gradle-wrapper.properties,修改gradle版本对应AGP要求:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

4. 修正系统镜像路径不一致问题

  • 打开Android Studio的SDK Manager,进入SDK Platforms标签,检查已安装的系统镜像路径,确保全部在%LOCALAPPDATA%\Android\Sdk目录下
  • 若存在路径不符的镜像,卸载后重新安装到指定SDK目录

5. 清理缓存并重新构建

执行以下命令清理构建缓存后重启项目:

cd android
./gradlew clean
cd ..
npx react-native run-android

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 02:35:48