question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CompatDx cannot fit requested classes in a single dex file

See original GitHub issue

Description of the bug:

After updating to rolling release 6.0.0-pre.20220526.1, CompatDx produces a massive amount of warnings and eventually fails with the following error:

Error: Cannot fit requested classes in a single dex file (# methods: 227417 > 65536 ; # fields: 124517 > 65536). Try supplying a main-dex list
Exception in thread "main" java.lang.AssertionError: Failure
        at com.google.devtools.build.android.r8.CompatDx.main(CompatDx.java:478)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: null
        at Version.fakeStackEntry(Version_3.3.28.java:0)
        at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:75)
        at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:28)
        at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:27)
        at com.android.tools.r8.internal.Bj.b(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:2)
        at com.android.tools.r8.D8.run(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:6)
        at com.google.devtools.build.android.r8.CompatDx.run(CompatDx.java:624)
        at com.google.devtools.build.android.r8.CompatDx.main(CompatDx.java:472)
Caused by: com.android.tools.r8.internal.f: Cannot fit requested classes in a single dex file (# methods: 227417 > 65536 ; # fields: 124517 > 65536)
        at com.android.tools.r8.internal.DT.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:14)
        at com.android.tools.r8.internal.DT.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:22)
        at com.android.tools.r8.internal.h30.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:524)
        at com.android.tools.r8.internal.c30.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:7)
        at com.android.tools.r8.internal.F2.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:371)
        at com.android.tools.r8.internal.F2.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:455)
        at com.android.tools.r8.D8.d(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:756)
        at com.android.tools.r8.D8.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:1)
        at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:24)
        ... 4 more

What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

You might need to have a classpath large enough to exceed a single dex file to reproduce this.

We are using the following dexing configuration with multidex mode set to native:

# Enable experimental d8 merger
build --define=android_dexmerger_tool=d8_dexmerger
build --define=android_incremental_dexing_tool=d8_dexbuilder
build --define=android_standalone_dexing_tool=d8_compat_dx

Reverting this PR resolves the issue. More specifically just reverting the changes in tools/android/android_sdk_repository_template.bzl is enough to build successfully again.

Which operating system are you running Bazel on?

Mac OS

What is the output of bazel info release?

6.0.0-pre.20220526.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:39 (39 by maintainers)

github_iconTop GitHub Comments

1reaction
ahumeskycommented, Jul 19, 2022

I’ve asked for the fix to be cherrypicked into 5.3.0: https://github.com/bazelbuild/bazel/pull/15917

1reaction
Bencodescommented, Jun 27, 2022

@ahumesky opened up a new issue for the stack map able warnings here https://github.com/bazelbuild/bazel/issues/15751

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot fit requested classes in a single dex file
I have multidex enabled but it still appears that it's trying to put the output into one file. Details are below. C:\Users\scott\OneDrive\ ...
Read more >
D8 dexmerger crash with multidex on bazel 5 and ... - GitHub
Error: Cannot fit requested classes in a single dex file ... Error: Could not find or load main class com.android.tools.r8.compatdx.
Read more >
Cannot fit requested classes in a single dex file (# methods
Error in android studio development with java. This video is showing you how to fix this errorWelcome to my YouTube channel for more...
Read more >
[SOLVED] Cannot fit requested classes in a single dex file ...
SOLVED Cannot fit requested classes in a single dex file # methods: 65586 65536Simply ADD your app's or module's build.gradle ...
Read more >
Cannot fit requested classes in a single dex file (Android ...
Cannot fit requested classes in a single dex file (Android Studio) 2020Add Library:multiDexEnabled trueimplementation ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found