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

Gradle构建报错::expo-permissions:compileDebugKotlin执行失败

Expo项目Gradle构建失败::expo-permissions:compileDebugKotlin 任务报错

在Android目录下执行./gradlew assembleDebug --stacktrace,配置阶段100%完成后,执行到54%时触发以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':expo-permissions:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction

项目配置文件

根目录build.gradle

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

buildscript {
    ext {
        buildToolsVersion = '29.0.3'
        minSdkVersion = Integer.parseInt(findProperty('android.minSdkVersion') ?: '23')
        compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '34')
        targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '34')
        kotlinVersion = '1.9.0'
        // kotlinVersion = findProperty('android.kotlinVersion') ?: '1.9.23'

        ndkVersion = "27.0.12077973"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle')
        classpath('com.facebook.react:react-native-gradle-plugin')
        // Use the correct property name
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

apply plugin: "com.facebook.react.rootproject"

allprojects {
    repositories {
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
        }
        maven {
            // Android JSC is installed from npm
            url(new File(['node', '--print', "require.resolve('jsc-android/package.json', { paths: [require.resolve('react-native/package.json')] })"].execute(null, rootDir).text.trim(), '../dist'))
        }

        google()
        mavenCentral()
        maven { url 'https://www.jitpack.io' }
    }
}

package.json

{
  "name": "my-app",
  "main": "expo-router/entry",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start",
    "reset-project": "node ./scripts/reset-project.js",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo-google-fonts/poppins": "^0.2.3",
    "@expo/vector-icons": "^14.0.2",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-community/datetimepicker": "8.0.1",
    "@react-native-firebase/app": "^20.4.0",
    "@react-native-firebase/messaging": "^20.4.0",
    "@react-navigation/drawer": "^6.7.2",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/stack": "^6.4.1",
    "@react-navigation/tabs": "^0.0.0-alpha.12",
    "axios": "^1.7.3",
    "date-fns": "^3.6.0",
    "expo": "^51.0.26",
    "expo-av": "^14.0.6",
    "expo-constants": "~16.0.2",
    "expo-device": "^6.0.2",
    "expo-font": "~12.0.9",
    "expo-image-picker": "~15.0.7",
    "expo-linking": "~6.3.1",
    "expo-notifications": "^0.28.15",
    "expo-permissions": "^14.4.0",
    "expo-router": "^3.5.21",
    "expo-splash-screen": "~0.27.5",
    "expo-status-bar": "~1.12.1",
    "expo-system-ui": "~3.0.7",
    "expo-web-browser": "~13.0.3",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.52.2",
    "react-native": "^0.74.5",
    "react-native-crypto-js": "^1.0.0",
    "react-native-element-dropdown": "^2.12.1",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-pager-view": "6.3.0",
    "react-native-paper": "^5.12.5",
    "react-native-reanimated": "~3.10.1",
    "react-native-safe-area-context": "4.10.5",
    "react-native-screens": "3.31.1",
    "react-native-tab-view": "^3.5.2",
    "react-native-vector-icons": "^10.1.0",
    "react-native-web": "~0.19.10"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/jest": "^29.5.12",
    "@types/react": "~18.2.45",
    "@types/react-test-renderer": "^18.0.7",
    "jest": "^29.2.1",
    "jest-expo": "~51.0.3",
    "react-test-renderer": "18.2.0",
    "typescript": "~5.3.3"
  },
  "private": true
}

解决步骤

1. 升级Kotlin版本

Expo 51和React Native 0.74.5需要兼容的Kotlin版本,修改根目录build.gradle中的kotlinVersion:

kotlinVersion = '1.9.23'

2. 移除废弃的expo-permissions依赖

Expo 48+已弃用expo-permissions,权限请求已整合到对应功能模块(如expo-image-picker、expo-av),执行以下操作:

npm uninstall expo-permissions

3. 清理构建缓存

# 清理Gradle缓存
cd android && ./gradlew clean
# 清理Node依赖缓存
cd .. && rm -rf node_modules package-lock.json
# 重新安装依赖
npm install

4. 重新构建项目

cd android && ./gradlew assembleDebug --stacktrace

额外检查

  • 确保Android SDK已安装compileSdkVersion 34对应的SDK包
  • 确认Gradle版本与com.android.tools.build:gradle兼容(React Native 0.74.x推荐Gradle 8.6)

内容的提问来源于stack exchange,提问作者Abhi-Radadiya

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 16:55:04