title: Android app build failed while trying to run a Flutter Android app in debug mode
body: <p>I am trying to run my Flutter app on a physical Android device and the build is being failed with the bellow error message:</p>
  <pre><code>    ERROR:: D8: Cannot fit requested classes in a single dex file (# methods: 68628 &gt; 65536)
  com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
  The number of method references in a .dex file cannot exceed 64K.
  Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
      at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:128)
      at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:115)
      at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:111)
      at com.android.build.gradle.internal.tasks.DexMergingWorkAction.merge(DexMergingTask.kt:805)
      at com.android.build.gradle.internal.tasks.DexMergingWorkAction.run(DexMergingTask.kt:760)
      at com.android.build.gradle.internal.profile.ProfileAwareWorkAction.execute(ProfileAwareWorkAction.kt:74)
      at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
      at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:67)
      at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:63)
      at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:97)
      at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:63)
      at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
      at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
      at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
      at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
      at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
      at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
      at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
      at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
      at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
      at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
      at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
      at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
      at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
      at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:60)
      at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$2(DefaultWorkerExecutor.java:200)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:215)
      at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:164)
      at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:131)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
      at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
      at java.base/java.lang.Thread.run(Thread.java:834)
  Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: null
      at Version.fakeStackEntry(Version_2.2.66.java:0)
      at com.android.tools.r8.utils.a0.a(SourceFile:89)
      at com.android.tools.r8.D8.run(D8.java:11)
      at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:113)
      ... 36 more
  Caused by: com.android.tools.r8.utils.b: Cannot fit requested classes in a single dex file (# methods: 68628 &gt; 65536)
      at com.android.tools.r8.utils.V0.a(SourceFile:22)
      at com.android.tools.r8.utils.V0.a(SourceFile:25)
      at com.android.tools.r8.dex.P.a(SourceFile:55)
      at com.android.tools.r8.dex.P$h.a(SourceFile:7)
      at com.android.tools.r8.dex.b.a(SourceFile:14)
      at com.android.tools.r8.dex.b.c(SourceFile:30)
      at com.android.tools.r8.D8.d(D8.java:163)
      at com.android.tools.r8.D8.b(D8.java:1)
      at com.android.tools.r8.utils.a0.a(SourceFile:47)
      ... 38 more
  
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':app:mergeDexDebug'.
  &gt; A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingTaskDelegate
     &gt; There was a failure while executing work items
        &gt; A failure occurred while executing com.android.build.gradle.internal.tasks.DexMergingWorkAction
           &gt; com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
             The number of method references in a .dex file cannot exceed 64K.
             Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  
  * Get more help at https://help.gradle.org
  
  BUILD FAILED in 33s
  [!] The shrinker may have failed to optimize the Java bytecode.
      To disable the shrinker, pass the `--no-shrink` flag to this command.
      To learn more, see: https://developer.android.com/studio/build/shrink-code
  Exception: Gradle task assembleDebug failed with exit code 1
  </code></pre>
  <p>What is the issue here?
  Earlier to this, I was running apps in debug mode without any issue, the problem started when I have upgraded the Flutter SDK version to 2.2.0 and then again downgraded to 2.0.2.</p>