Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 875
m.myalkin Avatar asked Dec 13 '17 10:12

m.myalkin


5 Answers

./gradlew clean fixed the same error for me.

like image 192
mixel Avatar answered Nov 02 '22 18:11

mixel


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

like image 34
w3spi Avatar answered Nov 02 '22 19:11

w3spi


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.

like image 9
m.myalkin Avatar answered Nov 02 '22 18:11

m.myalkin


Simple Solution

For Ionic and Cordove Projects

cordova clean
like image 9
Shashwat Gupta Avatar answered Nov 02 '22 20:11

Shashwat Gupta


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
    }
like image 4
Md Imran Choudhury Avatar answered Nov 02 '22 20:11

Md Imran Choudhury