【问题标题】:Gradle sync failed: Could not create task ':flutter_plugin_android_lifecycle:generateDebugUnitTestConfig'. this and base files have different rootsGradle 同步失败:无法创建任务“:flutter_plugin_android_lifecycle:generateDebugUnitTestConfig”。 this 和 base 文件有不同的根
【发布时间】:2022-06-15 19:39:32
【问题描述】:

我正在为我的项目使用颤振。我正在为我的 android 应用程序使用 android studio。当我按下构建时,这是我得到的错误。每当我按下构建我的应用程序构建但我面临这个错误。请帮我解决这个错误。

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
}

【问题讨论】:

  • 你解决了这个问题吗?
  • 是的,我也标记了答案

标签: android flutter android-studio android-gradle-plugin build.gradle


【解决方案1】:

我通过

解决了这个问题
  1. 运行flutter clean
  2. 然后在 android studio 中再次将项目与 gradle 文件同步

【讨论】:

    【解决方案2】:

    似乎flutter_plugin_android_lifecycle-2.0.5 尚不兼容 gradle 版本 >= 7.0.0。

    所以您所能做的就是降级您的 gradle 版本或等待库中的修复。

    【讨论】:

      【解决方案3】:

      我已将 gradle 版本从 7.0.0 更新到 7.0.3 以及 ext.kotlin_version = 'latest_version' 的 kotlin 版本,现在可以正常工作了

      【讨论】:

        【解决方案4】:

        Android->build.gradle-> classpath 'com.android.tools.build:gradle:4.1.0' 将您的版本更改为此。工作正常。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2021-12-08
          • 2020-09-21
          • 2022-07-28
          • 1970-01-01
          • 2016-12-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多