“运行 android”时构建失败:无法解析类 com.android.build.OutputFile @ 第 3 行,第 1 列。导入 com.android.build.OutputFile
Posted
技术标签:
【中文标题】“运行 android”时构建失败:无法解析类 com.android.build.OutputFile @ 第 3 行,第 1 列。导入 com.android.build.OutputFile【英文标题】:Build Failed while 'run android' : unable to resolve class com.android.build.OutputFile @ line 3, column 1. import com.android.build.OutputFile 【发布时间】:2021-12-01 03:25:03 【问题描述】:所以我刚刚使用 '$ npx react-native init tracking' 创建了一个反应原生应用程序'tracks',当我尝试运行命令 '$ npx react-native run- android',它显示以下错误。我尝试将类路径 gradle 版本(默认 4.2.2)更改为许多其他版本,但没有用。 几天来我一直无法绕过它。请帮忙**
CMD:
info Running jetifier to migrate libraries to androidX. You can disable it using "--no-jetifier" flag.
Jetifier found 871 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Installing the app...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\utsar\Desktop\ReactProjects\tracks\android\app\build.gradle' line: 3
* What went wrong:
Could not compile build file 'C:\Users\utsar\Desktop\ReactProjects\tracks\android\app\build.gradle'.
> startup failed:
build file 'C:\Users\utsar\Desktop\ReactProjects\tracks\android\app\build.gradle': 3: unable to resolve class com.android.build.OutputFile
@ line 3, column 1.
import com.android.build.OutputFile
^
1 error
* 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 https://help.gradle.org
BUILD FAILED in 6s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\utsar\Desktop\ReactProjects\tracks\android\app\build.gradle' line: 3
* What went wrong:
Could not compile build file 'C:\Users\utsar\Desktop\ReactProjects\tracks\android\app\build.gradle'.
> startup failed:
build file 'C:\Users\utsar\Desktop\ReactProjects\tracks\android\app\build.gradle': 3: unable to resolve class com.android.build.OutputFile
@ line 3, column 1.
import com.android.build.OutputFile
^
1 error
* 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 https://help.gradle.org
BUILD FAILED in 6s
at makeError (C:\Users\utsar\Desktop\ReactProjects\tracks\node_modules\execa\index.js:174:9)
at C:\Users\utsar\Desktop\ReactProjects\tracks\node_modules\execa\index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async runOnAllDevices (C:\Users\utsar\Desktop\ReactProjects\tracks\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:106:5)
at async Command.handleAction (C:\Users\utsar\Desktop\ReactProjects\tracks\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
【问题讨论】:
【参考方案1】:我能提供的最佳帮助是,如果您的 build.gradle 文件不应用 android 插件,它将无法解析导入“com.android.build.OutputFile”。
您使用“com.android.build.OutputFile”的 gradle 文件需要这一行:
apply plugin: 'com.android.application'
此行只应添加到应用模块级构建文件中。
不幸的是,我不太了解本地反应。我只是从我在正常项目中遇到这个问题时如何解决这个问题来回答。
【讨论】:
以上是关于“运行 android”时构建失败:无法解析类 com.android.build.OutputFile @ 第 3 行,第 1 列。导入 com.android.build.OutputFile的主要内容,如果未能解决你的问题,请参考以下文章
React-Native Android 构建失败 - 无法找到请求目标的有效认证路径
为啥在 Visual Studio 中构建失败,因为它无法从引用的程序集中解析命名空间?