gradle中以下任务之间的循环依赖关系

李老栓*_*李老栓 5 android

我在AndroidStudio 3.2中运行我的项目,但是有一个错误

FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:app:checkManifestChangesDebug
\--- :app:instantRunMainApkResourcesDebug
     \--- :app:transformClassesAndDexWithShrinkResForDebug
          \--- :app:transformDexArchiveWithDexMergerForDebug
               +--- :app:preColdswapDebug
               |    \--- :app:incrementalDebugTasks
               |         +--- :app:transformClassesAndClassesEnhancedWithInstantReloadDexForDebug
               |         |    \--- :app:transformClassesWithInstantRunForDebug
               |         |         \--- :app:checkManifestChangesDebug (*)
               |         \--- :app:transformClassesWithInstantRunForDebug (*)
               \--- :app:transformClassesWithDexBuilderForDebug
                    +--- :app:preColdswapDebug (*)
                    \--- :app:transformClassesWithInstantRunForDebug (*)

(*) - details omitted (listed previously)
Run Code Online (Sandbox Code Playgroud)

我仍然可以手动生成APK,但"运行"按钮不起作用.

我该如何解决这个问题?

小智 9

禁用设置的即时运行

设置>搜索即时运行>取消选中"启用即时运行以显示热交换代码/资源更改"


Dep*_*pau 8

正如@ hocine-b在评论中所指出的,如果您shrinkResources在ProGuard中启用,则可能会发生这种情况.

它仅在启用"即时运行"时发生,即在按下"运行"按钮时在调试版本中.

您可以通过仅缩小发布版本中的资源来修复它,例如,在您的模块中build.gradle:

android {
    buildTypes {
        debug {
            minifyEnabled true
            shrinkResources false  // Avoid conflicts with Instant Run 
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 没有收缩资源,没有即时运行,仍然会发生 (2认同)