Circular dependency between the following tasks

30,890

Solution 1

This can occur when a module depends on itself!

For example, suppose this for module app:

...

dependencies {
    compile project(':app') // !!!
    ...
}

Solution 2

But minifyEnabled is important in production. I have tried the following arrangement and it worked with instant run enabled:

minifyEnabled true
useProguard true
shrinkResources false

So this tends to happen when instant Run is enabled and shrinkResources is set to true as well.

Solution 3

For errors such this:

Circular dependency between the following tasks::app:bundleDebugClasses
\--- :app:compileDebugJavaWithJavac
     \--- :package_name:bundleLibCompileToJarDebug
          \--- :package_name:compileDebugJavaWithJavac
               \--- :app:bundleDebugClasses (*)

This error occurs because you have created a cycle between dependencies. This means two implementations that one belongs to the other is used, so you should remove additional implementation from below build.gradle in list of gradles. Another example: If package A is implemented in package B and also you needed to put B implementation in A and you did that, it makes this error.

Solution 4

minified, userProguard, shrink resources can produce errors in debug mode. These features are needed to be used in Release version. So you need to disable them or you can add debuggable=false.

debug {
            minifyEnabled true
            useProguard true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
Share:
30,890

Related videos on Youtube

Артем Протасов
Author by

Артем Протасов

Updated on April 14, 2021

Comments

  • Артем Протасов
    Артем Протасов about 3 years

    I try to solve this problem for more than 5 hours. What could be the problem?

    Circular dependency between the following tasks:
    :app:checkManifestChangesDevelopDebug
    \--- :app:instantRunMainApkResourcesDevelopDebug
         \--- :app:transformClassesAndDexWithShrinkResForDevelopDebug
              \--- :app:transformDexArchiveWithDexMergerForDevelopDebug
                   +--- :app:preColdswapDevelopDebug
                   |    \--- :app:incrementalDevelopDebugTasks
                   |         +--- :app:transformClassesAndClassesEnhancedWithInstantReloadDexForDevelopDebug
                   |         |    \--- :app:transformClassesWithInstantRunForDevelopDebug
                   |         |         \--- :app:checkManifestChangesDevelopDebug (*)
                   |         \--- :app:transformClassesWithInstantRunForDevelopDebug (*)
                   \--- :app:transformClassesWithDexBuilderForDevelopDebug
                        +--- :app:preColdswapDevelopDebug (*)
                        \--- :app:transformClassesWithInstantRunForDevelopDebug (*)
    
    (*) - details omitted (listed previously)
    

    I added:

    org.gradle.configureondemand=true

    But the problem is still present

    build.gradle (Module: app)

    buildscript {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
        }
    
        dependencies {
            classpath 'io.fabric.tools:gradle:1+'
        }
    }
    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'
    apply plugin: 'realm-android'
    
    
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    
    static def getFullDate() {
        return new Date().format('dd.MM.yyyy-HH.mm')
    }
    
    static def getDate() {
        return new Date().format('dd.MM.yyyy')
    }
    
    android {
        compileSdkVersion rootProject.ext.compileSdkVersion
        buildToolsVersion '28.0.2'
    
        defaultConfig {
            applicationId "com.MYPROJECT"
            minSdkVersion rootProject.ext.minSdkVersion
            targetSdkVersion rootProject.ext.targetSdkVersion
            versionCode 47
            versionName "2.11d"
    //      project.ext.set("archivesBaseName", "MYPROJECT_" + versionName + "_" + getFullDate())
            project.ext.set("archivesBaseName", "MYPROJECT_" + versionName + "_" + getDate())
            vectorDrawables.useSupportLibrary = true
            multiDexEnabled true
    
            externalNativeBuild {
                cmake {
                    cppFlags "-std=c++11"
                }
            }
        }
    
        buildTypes {
            debug {
                minifyEnabled true
                useProguard true
                shrinkResources true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        externalNativeBuild {
            cmake {
                path "CMakeLists.txt"
            }
        }
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        flavorDimensions "app"
    
        productFlavors {
    
            prod {
                buildConfigField 'String', 'SERVER_BASE_URL', '"http://MYPROJECT.com/"'
                dimension "app"
            }
    
            develop {
                buildConfigField 'String', 'SERVER_BASE_URL', '"http://MYPROJECT.com/"'
                buildConfigField 'String', 'YOUTUBE_API_KEY', '"AIzaSyD5eJIAcqUtMkBoorw_K8mh1d_TQSgjRwMT"'
                applicationIdSuffix = ".dev"
                versionNameSuffix = "-dev"
                dimension "app"
            }
    
        }
        dexOptions {
        }
    }
    
    
    dependencies {
        implementation "com.jakewharton:butterknife:$rootProject.butterKnifeVersion"
        annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.butterKnifeVersion"
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
            transitive = true
        }
    
        //Google Supports
        implementation "com.android.support:design:$rootProject.supportLibraryVersion"
        implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
        implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
        implementation "com.android.support:preference-v7:$rootProject.supportLibraryVersion"
    
        //Network
        implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
        implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
        implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
        implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttpVersion"
    
        //Constraint layout
        implementation "com.android.support.constraint:constraint-layout:$rootProject.constraintLayoutVersion"
    
        //Google services
        implementation "com.google.android.gms:play-services-maps:$rootProject.googleServiceVersion"
        implementation "com.google.android.gms:play-services-location:$rootProject.googleServiceVersion"
        implementation "com.google.android.gms:play-services-gcm:$rootProject.googleServiceVersion"
    
        //RxJava
        implementation "io.reactivex.rxjava2:rxjava:$rootProject.rxjavaVersion"
        implementation "io.reactivex.rxjava2:rxandroid:$rootProject.rxandroidVersion"
    
        //Lifecycle
        implementation "android.arch.lifecycle:runtime:$project.lifecycleVersion"
        implementation "android.arch.lifecycle:extensions:$project.lifecycleVersion"
        implementation "android.arch.lifecycle:viewmodel:$project.lifecycleVersion"
        annotationProcessor "android.arch.lifecycle:compiler:$project.lifecycleVersion"
    
        //Dagger dependencies
        implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
        implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
        implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
        annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
        annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
    
        //RxPermissions
        implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'
    
        //RxBinding
        implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
    
        //TIMBER
    
        //implementation 'com.jakewharton.timber:timber:4.7.0'
        testImplementation "junit:junit:$rootProject.junitVersion"
    
        //Glide
        implementation "com.github.bumptech.glide:glide:$rootProject.glideVersion"
        annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.glideVersion"
        implementation files('src/main/jniLibs/aacdecoder-android-0.8.jar')
    
        //Youtube
        implementation files('libs/YouTubeAndroidPlayerApi.jar')
    
        //Vitamio video player
    
        //implementation project(':vitamio')
    
        //VideoPlayer
        implementation 'cn.jzvd:jiaozivideoplayer:6.2.12'
        implementation 'org.greenrobot:eventbus:3.1.1'
        implementation 'com.github.splatte:ViewPagerIndicator:3.0.0'
        implementation 'com.h6ah4i.android.tablayouthelper:tablayouthelper:0.7.0'
    
        //Rate App
        implementation 'com.github.hotchemi:android-rate:1.0.1'
        implementation 'de.hdodenhof:circleimageview:2.2.0'
        implementation 'com.github.vbartacek:aacdecoder-android:0.8'
        implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.11'
        implementation 'com.github.arimorty:floatingsearchview:2.1.1'
        implementation 'jp.wasabeef:glide-transformations:3.2.0'
        implementation 'org.adw.library:discrete-seekbar:1.0.1'
        implementation 'com.android.support:multidex:1.0.3'
    
        //RouteController
        implementation 'com.ncapdevi:frag-nav:3.0.0-RC3'
    
        //Joda Time
        implementation 'net.danlew:android.joda:2.9.9.4'
    
        //ReactLocation
        implementation 'pl.charmas.android:android-reactive-location2:2.1@aar'
    
        //SeekBar
        implementation 'com.xw.repo:bubbleseekbar:3.16-lite'
    
        //Lombok
    
        //Warning! Versions above 1.16.20 do not work with lambda (throws an exception when compiling)
        compileOnly "org.projectlombok:lombok:$rootProject.lombokVersion"
        annotationProcessor "org.projectlombok:lombok:$rootProject.lombokVersion"
    
        //nv-websocket-client
        implementation "com.neovisionaries:nv-websocket-client:$rootProject.nvWebSocketClientVersion"
    
        //Custom tabs
        implementation "com.android.support:customtabs:$rootProject.supportLibraryVersion"
    
        //Auto scroll view pager for Suggestion
        implementation("cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:$rootProject.autoScrollViewPagerVersion") {
            exclude module: 'support-v4'
        }
    
        //Paging library
        implementation "android.arch.paging:runtime:$rootProject.pagingLibraryVersion"
    
        //Beacon Library
        implementation 'org.altbeacon:android-beacon-library:2.15'
    }
    

    and build.gradle (Project: myproject)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
        jcenter()
        google()
    
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url "https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath "io.realm:realm-gradle-plugin:5.1.0"
        classpath 'me.tatarka:gradle-retrolambda:3.7.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    } }
    
    allprojects {
    repositories {
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven { url  "http://dl.bintray.com/populov/maven" }
        mavenCentral()
        jcenter()
    
        maven { url "https://jitpack.io" }
    }
    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }
            }
        }
    } }
    
    task clean(type: Delete) {
    delete rootProject.buildDir }
    
    // Define versions in a single place ext {
    // Sdk and tools
    minSdkVersion = 19
    targetSdkVersion = 27
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'
    
    // App dependencies
    supportLibraryVersion = '28.0.0'
    butterKnifeVersion = '8.8.1'
    retrofitVersion = '2.3.0'
    okhttpVersion = '3.8.0'
    junitVersion = '4.12'
    glideVersion = '4.7.1'
    googleServiceVersion = '15.0.1'
    permissionDispatcherVersion = '3.1.0'
    rxjavaVersion = '2.1.12'
    rxandroidVersion = '2.0.2'
    lifecycleVersion = '1.1.1'
    daggerVersion = '2.16'
    pagingLibraryVersion = '1.0.1'
    autoScrollViewPagerVersion = '1.1.2'
    nvWebSocketClientVersion = '2.5'
    lombokVersion = '1.16.20'
    constraintLayoutVersion = '1.1.3' }
    
    • bto
      bto over 5 years
      The Circular dependency refers to the fact that the task :app:checkManifestChangesDevelopDebug, through its dependencies listed in that graph, will eventually lead to itself being called again. We'll need to see your build.gradle to try to make sense of why the circular dependency exists.
    • Артем Протасов
      Артем Протасов over 5 years
      @bto I updated my question
    • Sagar
      Sagar almost 5 years
      @TouhidulIslam Have you solved this ?
  • mmdreza baqalpour
    mmdreza baqalpour about 2 years
    My problem was I was imported module data into app and module app into data
  • Inliner
    Inliner almost 2 years
    In my case, I was using plugin from buildSrc that contained common dependency for the module itself