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

soat7uwm  于 2023-09-29  发布在  Android
关注(0)|答案(6)|浏览(409)

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

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'
}

这是我的项目级构建。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
}
uqdfh47h

uqdfh47h1#

我通过以下方式修复了此问题
1.运行flutter clean
1.然后在android studio中再次将项目与gradle文件同步

nue99wik

nue99wik2#

打开Android -> build.gradle文件

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

把你的版本改成这个。工作正常.

llycmphe

llycmphe3#

似乎flutter_plugin_android_lifecycle-2.0.5还不兼容Gradle版本>= 7.0.0。
因此,您所能做的就是降级您的gradle版本或等待库中的修复。

kg7wmglp

kg7wmglp4#

我已经更新了gradle版本从7.0.0到7.0.3,还有Kotlin版本,它是ext.kotlin_version = 'latest_version',现在它工作正常

oyt4ldly

oyt4ldly5#

将项目路径更改为与配置文件相同的驱动器。
因此,如果您的C:\Users\Username位于此处,则只需将项目从D:\Projects\Name移动到C:\Projects\Name即可
关于stackoverflow answergithub thread

ryoqjall

ryoqjall6#

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

flutter pub upgrade

相关问题