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

React Native构建报错:无法找到react-native-gradle-plugin:0.73.0

构建React Native项目时无法解析react-native-gradle-plugin:0.73.0依赖

问题概述

被该问题困扰3周,构建TranslatorApp项目时持续报错,无法找到com.facebook.react:react-native-gradle-plugin:0.73.0依赖。

完整错误日志

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'TranslatorApp'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find com.facebook.react:react-native-gradle-plugin:0.73.0.
     Searched in the following locations:
       - Google Maven仓库
       - Maven Central仓库
       - Gradle插件门户
     Required by:
         project :

* 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 Gradle官方帮助

------------------------------------------------------------
Gradle 8.0
------------------------------------------------------------

Build time:   2023-02-13 13:15:21 UTC
Revision:     62ab9b7c7f884426cf79fbedcf07658b2dbe9e97

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.12 (Oracle Corporation 17.0.12+8-LTS-286)
OS:           Windows 11 10.0 amd64

java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)

项目配置文件

frontend/package.json

{  
  "name": "translator-app",  
  "version": "1.0.0",  
  "private": true,  
  "scripts": {    
    "start": "react-native start",    
    "android": "react-native run-android",    
    "ios": "react-native run-ios",    
    "test": "jest",    
    "clean": "rm -rf node_modules && npm install && cd android && ./gradlew clean && cd ..",    
    "postinstall": "npx pod-install"  
  },  
  "dependencies": {    
    "@react-native-firebase/app": "^17.3.2",    
    "@react-native-firebase/ml": "^17.3.2",    
    "@react-native-google-signin/google-signin": "^8.0.0",    
    "@react-navigation/native": "^6.1.5",    
    "@react-navigation/stack": "^6.3.16",    
    "react": "^18.0.0",    
    "react-native": "^0.73.0",    
    "react-native-gesture-handler": "^2.12.0",    
    "react-native-reanimated": "^3.4.0",    
    "react-native-vision-camera": "^3.0.2"  
  },  
  "devDependencies": {    
    "@babel/core": "^7.23.6",    
    "@babel/runtime": "^7.23.6",    
    "@react-native-community/cli": "latest",    
    "@react-native/gradle-plugin": "0.73.0",    
    "babel-jest": "^29.5.0",    
    "jest": "^29.5.0",    
    "metro-react-native-babel-preset": "^0.77.0"  
  },  
  "jest": {    
    "preset": "react-native"  
  }
}

android/build.gradle(根目录)

pluginManagement {    
  repositories {        
    google()        
    mavenCentral()        
    gradlePluginPortal()    
  }
}

dependencyResolutionManagement {    
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)    
  repositories {        
    google()        
    mavenCentral()    
  }
}

rootProject.name = "TranslatorApp"
include(":app")

android/build.gradle(buildscript块)

buildscript {    
  repositories {        
    google()        
    mavenCentral()        
    gradlePluginPortal()    
  }    
  dependencies {        
    classpath("com.android.tools.build:gradle:8.0.2")        
    classpath("com.facebook.react:react-native-gradle-plugin:0.73.0")    
  }
}

allprojects {    
  repositories {        
    google()        
    mavenCentral()        
    maven { url("$rootDir/../frontend/node_modules/@react-native/gradle-plugin") }    
  }
}

frontend/app/src/build.gradle

plugins {    
  id("com.android.application")    
  id("com.facebook.react")    
  id("kotlin-android")
}

android {    
  namespace = "com.translatorapp"    
  compileSdk = 33

  defaultConfig {        
    applicationId = "com.translatorapp"        
    minSdk = 21        
    targetSdk = 33        
    versionCode = 1        
    versionName = "1.0"    
  }

  buildTypes {        
    release {            
      isMinifyEnabled = false            
      proguardFiles(                   
        getDefaultProguardFile("proguard-android-optimize.txt"),                    
        "proguard-rules.pro"            
      )        
    }    
  }    
  compileOptions {        
    sourceCompatibility = JavaVersion.VERSION_17        
    targetCompatibility = JavaVersion.VERSION_17    
  }
}

dependencies {    
  classpath("com.facebook.react:react-native-gradle-plugin:0.73.0")    
  implementation("androidx.appcompat:appcompat:1.4.1")    
  implementation("androidx.core:core-ktx:1.8.0")    
  implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.22")    
  implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}

已尝试的操作

  • 调整依赖版本,尝试兼容组合
  • 切换Java版本(17 ↔ 11)
  • 检查并修复系统环境变量及Path
  • 更新package.json依赖
  • 执行项目清理脚本(删除node_modules、重装依赖、gradle clean)

解决步骤

1. 添加React Native官方Maven仓库

在根目录android/build.gradle的dependencyResolutionManagement块中新增仓库:

dependencyResolutionManagement {    
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)    
  repositories {        
    google()        
    mavenCentral()
    // 新增React Native仓库
    maven { url "https://maven.facebook.com" }    
  }
}

2. 移除错误的依赖声明

frontend/app/src/build.gradle的dependencies块中,classpath属于构建脚本依赖,不应出现在模块依赖里,删除该行:

// 删除此行
classpath("com.facebook.react:react-native-gradle-plugin:0.73.0")

3. 验证本地插件存在性

检查frontend/node_modules/@react-native/gradle-plugin目录是否存在,若缺失则执行:

cd frontend
rm -rf node_modules package-lock.json
npm install

4. 升级Gradle版本适配React Native 0.73.x

React Native 0.73.x推荐Gradle 8.1+,修改gradle/wrapper/gradle-wrapper.properties中的distributionUrl:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip

5. 重新构建项目

执行清理后重新构建:

cd frontend
npm run clean
npm run android

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 03:07:34