FAILURE:构建失败并出现异常。 * 出了什么问题:任务 ':app:compileDebugKotlin' 执行失败

问题描述 投票:0回答:1

我正在尝试为我的 React-native 项目生成 android 版本,但在编译过程中遇到此错误。我找不到问题的原因

我按照 Expo 文档中更新本机项目的步骤进行操作。因为我的项目需要从SDK49更新到SDK50。我正在使用裸工作流程项目模型

https://docs.expo.dev/bare/upgrade/?fromSdk=49&toSdk=50#androidbuildgradle

[在此处输入图像描述][1]

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Task :app:compileDebugKotlin
FAILED
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainActivity.kt:18:14 Unresolved reference: R
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainActivity.kt:35:11 Unresolved reference: BuildConfig
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainApplication.kt:35:60 Unresolved reference: BuildConfig
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainApplication.kt:37:52 Unresolved reference: BuildConfig
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainApplication.kt:38:51 Unresolved reference: BuildConfig
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainApplication.kt:48:10 Unresolved reference: BuildConfig
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainApplication.kt:51:9 Unresolved reference: BuildConfig
e: file:///home/expo/workingdir/build/android/app/src/main/java/com/schoolmobile/inspell/MainApplication.kt:55:9 Unresolved reference: BuildConfig
> Task :expo-modules-core:buildCMakeDebug[arm64-v8a]
> Task :react-native-reanimated:buildCMakeDebug[arm64-v8a]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details```


  [1]: https://i.sstatic.net/Jp8DA9k2.png
android react-native expo
1个回答
0
投票

您可以使用以下步骤和命令清理并重建项目。

  1. 从 android 文件夹中删除 .gradle 文件夹
  2. 删除节点模块
  3. 使用 npm i 命令安装节点模块
  4. cd 安卓
  5. ./gradlew 干净
  6. npx react-native start --reset-cache
  7. 运行项目

如果这些步骤对您不起作用,请在 android 的 build.gradle 文件中验证以下版本。如果不符合预期,则按照预期安装并再次执行上述 7 个步骤。

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 33
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.22"
    }

希望对你有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.