Gradle sync failed: Could not create task ':flutter_plugin_android_lifecycle:generateDebugUnitTestConfig'. this and base files have different roots

268

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

Share:
268
Hammas Ali
Author by

Hammas Ali

Updated on January 04, 2023

Comments

  • Hammas Ali
    Hammas Ali over 1 year

    I am using flutter for my project. And I am using android studio for my android app. When I pressed on the build This is the error I am getting. Whenever I press on to build my ap build but I face this error. Please help me to fix this error.

    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
    }
    
    • Dpedrinha
      Dpedrinha about 2 years
      Did you fix this problem?
    • Hammas Ali
      Hammas Ali almost 2 years
      yes and I have marked the answer as well