Gradle 同步失败:无法创建任务“:flutter_plugin_android_lifecycle:generateDebugUnitTestConfig”。该文件和基础文件具有不同的根
当我按下构建时,这是我收到的错误:
Gradle sync failed: Could not create task ':flutter_plugin_android_lifecycle:generateDebugUnitTestConfig'.
this and base files have different roots: E:\flutter\peak_property\build\flutter_plugin_android_lifecycle and C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-2.0.5\android. (1 m 11 s 576 ms)
这是我的应用程序级别构建 Gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.peak_property"
minSdkVersion 23
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
task wrapper(type: Wrapper) {
gradleVersion = '6.7.1'
}
这是我的项目级别 build.Gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When I pressed on the build This is the error I am getting:
Gradle sync failed: Could not create task ':flutter_plugin_android_lifecycle:generateDebugUnitTestConfig'.
this and base files have different roots: E:\flutter\peak_property\build\flutter_plugin_android_lifecycle and C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_plugin_android_lifecycle-2.0.5\android. (1 m 11 s 576 ms)
This is my App Level build Gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.peak_property"
minSdkVersion 23
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
task wrapper(type: Wrapper) {
gradleVersion = '6.7.1'
}
This is my Project-level build.Gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
解决了这个问题
运行
flutter clean
I fixed this problem by
flutter clean
打开安卓-> build.gradle 文件
将您的版本更改为此。工作正常。
open Android -> build.gradle file
change your version to this. works fine.
似乎
flutter_plugin_android_lifecycle-2.0.5
尚未与 gradle 版本 >= 7.0.0 兼容。所以你所能做的就是降级你的 gradle 版本或等待库中的修复。
Seems like
flutter_plugin_android_lifecycle-2.0.5
is not yet compatible with gradle version >= 7.0.0.So all you can do is downgrade your gradle version or wait for a fix in the library.
我已将 gradle 版本从 7.0.0 更新到 7.0.3,还更新了 kotlin 版本,即 ext.kotlin_version = 'latest_version' 现在工作正常
I have updated the gradle version from 7.0.0 to 7.0.3 and also kotlin version which is ext.kotlin_version = 'latest_version' and now its working fine
将项目路径更改为与个人资料文件相同的驱动器。
因此,只需将您的项目从
d:\ Projects \ name
转移到c:\ projects \ name
如果您的c:\ users \ users \ username
lays在此处与 stackoverflow'> stackoverflow答案和 github thread
Change your project path to the same drive as your profile files is.
So, just move your project from
D:\Projects\Name
toC:\Projects\Name
if yourC:\Users\Username
lays in hereRelated to stackoverflow answer and github thread
它对我有用,请检查您的 IDE(android studio 或 Vs code)fultter 和 dart 扩展是否更新,如果没有,请更新两者然后它会工作,重新启动 IDE 。
VS 代码>扩展>颤动、飞镖
Android Studio >文件>设置>插件>颤动、飞镖
It's worked for me, please check your IDE (android studio or Vs code ) fultter and dart extensions are updated , if not please update both then it will work , restart the IDE.
vs code> Extencions > flutter, Dart
Android Studio > File > settings > plugins > Flutter, Dart
我最近有类似的问题。您可以在终端中运行升级。
I had a similar issue recently. You may run upgrade in your terminal.