Gradle 同步失败:无法创建任务“:flutter_plugin_android_lifecycle:generateDebugUnitTestConfig”。该文件和基础文件具有不同的根

发布于 01-17 07:52 字数 3053 浏览 6 评论 0原文

当我按下构建时,这是我收到的错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

剩余の解释 2025-01-24 07:52:33

解决了这个问题

  1. 我通过
    运行flutter clean
  2. 然后在android studio中再次将项目与gradle文件同步

I fixed this problem by

  1. running flutter clean
  2. then synchronize project with gradle files again in android studio
灵芸 2025-01-24 07:52:33

打开安卓-> build.gradle 文件

classpath 'com.android.tools.build:gradle:4.1.0'

将您的版本更改为此。工作正常。

open Android -> build.gradle file

classpath 'com.android.tools.build:gradle:4.1.0'

change your version to this. works fine.

抱着落日 2025-01-24 07:52:33

似乎 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.

梦魇绽荼蘼 2025-01-24 07:52:33

我已将 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

笛声青案梦长安 2025-01-24 07:52:33

将项目路径更改为与个人资料文件相同的驱动器。

因此,只需将您的项目从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 to C:\Projects\Name if your C:\Users\Username lays in here

Related to stackoverflow answer and github thread

明月松间行 2025-01-24 07:52:33

它对我有用,请检查您的 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

手心的海 2025-01-24 07:52:33

我最近有类似的问题。您可以在终端中运行升级。

flutter pub upgrade

I had a similar issue recently. You may run upgrade in your terminal.

flutter pub upgrade
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文