java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files
Asked Answered
S

13

59

I build the project at gitlab ci

./gradlew assembleDebug --stacktrace

and sometimes it throws an error:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files

At my local pc it works correctly.

kotlin version is 1.2

multidex is enabled

What is the reason of this error?

Summary answered 13/12, 2017 at 10:51 Comment(7)
have you enables mutlidex true and added library for mutlidex?Tine
yes, i've edited the questionSummary
@Summary Found any solution?Lipchitz
@AndiGeeky, no, exception did not appear several daysSummary
I am seeing this issue on buddybuild but on my local development machine it works fine. Any ideas are appreciated. I tried enabling multidexing but it didn't change anything.Centrifuge
Delete app/build file and then run the appElectrify
@Electrify I run it at CI server, there is no build directory because every build is cleanSummary
S
9

It seems I found the solution. At the build moment gradle was showing warnings for me:

Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

app: 'androidProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.arello-mobile:moxy-compiler:1.5.3' and apply the kapt plugin: "apply plugin: 'kotlin-kapt'".

I made a misspelling and forgot to remove unnecessary annotationProcessor for library:

annotationProcessor "com.arello-mobile:moxy-compiler:$moxyVersion"
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"

So I removed first line.

After that I applied kapt plugin apply plugin: 'kotlin-kapt' and fixed some build errors in code after it.

After all I realized that I forgot to replace compile to implementation in some places. It is weird but without it build didn't work.

This changes fix my error build.

Summary answered 25/12, 2017 at 17:38 Comment(0)
D
116

./gradlew clean fixed the same error for me.

Dumortierite answered 12/1, 2018 at 18:45 Comment(5)
No need to clean build and waste time. Better to just restart Android Studio.Bailiwick
@VinayakGarg: The asker mentions they are building via gitlab ci, so Android Studio is irrelevant here.Roussillon
in a cordova project use ./platforms/android/gradlew cleanSalomon
Or in a cordova project use cordova cleanSooksoon
Or in Flutter use flutter cleanErotomania
P
58

For Cordova developers,

If you get this build error in your project, as said Pierrick Martellière in the comments of this answer, in you project folder use :

cordova clean

It makes a cleaning and a build immediately

Parrish answered 17/2, 2019 at 9:22 Comment(1)
Yep, this is the fix for Cordova projects. You can also just clean android side by adding android at the end of that command.Cristophercristy
S
9

It seems I found the solution. At the build moment gradle was showing warnings for me:

Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

app: 'androidProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.arello-mobile:moxy-compiler:1.5.3' and apply the kapt plugin: "apply plugin: 'kotlin-kapt'".

I made a misspelling and forgot to remove unnecessary annotationProcessor for library:

annotationProcessor "com.arello-mobile:moxy-compiler:$moxyVersion"
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"

So I removed first line.

After that I applied kapt plugin apply plugin: 'kotlin-kapt' and fixed some build errors in code after it.

After all I realized that I forgot to replace compile to implementation in some places. It is weird but without it build didn't work.

This changes fix my error build.

Summary answered 25/12, 2017 at 17:38 Comment(0)
S
9

Simple Solution

For Ionic and Cordove Projects

cordova clean
Streamlined answered 6/7, 2019 at 11:18 Comment(0)
O
4

Above answer is mostly right but in my case, i get this exception when i crate same name java and kotlin file then deletes one of them.

Solutions are: just Build -> Clean Project my project and it works. And my project also enabled multiDex.

defaultConfig {
        ...
        // Enabling multidex support.
        multiDexEnabled true
    }
Overdye answered 26/1, 2018 at 14:56 Comment(0)
C
4

As mentioned above by @mixel cleaning gets the job done. But as an option not to do it manually just add the gradle 'clean' task into app run configuration so it will be done all the time before launch. Of cource, it can slow down the whole process a bit.

Cyb answered 20/4, 2018 at 9:20 Comment(0)
C
1

Configuring for multidexing did not solve this issue for me.

However I did come up with a resolution...of sorts. Basically it involved creating a pull request for a second branch on the same commit as the build that was failing. The build for this pull request succeeded, and then Bitbucket thought that the original pull request was ok and allowed us to merge, even though we had made no changes on that branch. There is some unexplained weirdness there but the technique worked.

Here's how I did it:

Assume that the branch that is failing is called bad-branch.

I created a new branch called bad-branch-copy on the commit that was common between bad-branch and develop. Then I merged bad-branch into bad-branch-copy. The end result of this was a fast forward such that bad-branch-copy ended up on the same commit as bad-branch. I was expecting a separate commit so this result surprised me, but I was grasping at straws anyway so I kept going.

I then pushed bad-branch-copy to GitHub and created a pull request from bad-branch-copy to develop. This triggered a build on bad-branch-copy -> develop, which was successful.

At that point, buddybuild showed a successful build on bad-branch-copy -> develop and still showed a failure on bad-branch -> develop. However, Bitbucket showed a successful build on the pull request for bad-branch. Yes, that's right: buddybuild showed a failure but Bitbucket said it was ok.

We were then able to merge the bad-branch pull request and all was well with the world. Please don't ask me why, I will not answer. :)

I think the same thing could be accomplished with

git checkout bad-build
git checkout -b bad-build-copy
git push origin bad-build-copy

followed by creating a pull request for bad-build-copy.

Centrifuge answered 20/12, 2017 at 22:11 Comment(0)
B
1

I was able to get the problem to go away by closing and restarting Android Studio. Perhaps even a Rebuild Project would have done it as well (did not try that though).

Bandy answered 15/1, 2018 at 14:44 Comment(1)
Rebuild does it for me.Sharpedged
O
1

Currently using Android Studio 3.3.2 I just disabled the instant run and it worked.

Orchard answered 30/4, 2019 at 19:47 Comment(0)
U
0

What resolved the issue for me was manually adding all the conflicting files manually. For example in my gradle file I had:

implementation 'com.android.support:support-compat:27.1.1'

it was underlined with red. I hovered over the line and android studio said there was a conflict with another file using a lower version. The error was similar to

come.android.support:support-annotations:26.0.1 conflicts/mix versions with 27.1.1.

It gave me the names of the files and I manually added them with the corresponding version so they would all match

compile 'com.android.support:support-annotations:27.1.1'
compile 'com.android.support:support-compat:27.1.1'
compile 'com.android.support:support-core-ui:27.1.1'
compile 'com.android.support:animated-vector-drawable:27.1.1'
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:design:27.1.1'
Uncalledfor answered 9/5, 2018 at 6:16 Comment(0)
D
0

None of the current solutions worked for me and it was fixed by simply disabling Instant Run.

Doting answered 3/4, 2019 at 20:10 Comment(0)
O
0

On react native,

I just

cd android/ && ./gradlew clean && cd .. && yarn android

this did thee trick for me.

Oilcan answered 3/2 at 10:25 Comment(0)
R
-4

please find here the solution of this problem,

 defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
dependencies {
  compile 'com.android.support:multidex:1.0.0'
}
Rowney answered 13/12, 2017 at 12:11 Comment(3)
Have you added multidex dependencies, as per I wrote in code?Rowney
yes, of course, I used com.android.support:multidex:1.0.2Summary
Ok, please follow this steps developer.android.com/studio/build/multidex.htmlRowney

© 2022 - 2024 — McMap. All rights reserved.