Getting 'app:transformClassesWithDexForDebug' error on compiling the project having useLibrary 'org.apache.http.legacy' in build.gradle

喜你入骨 提交于 2019-12-01 17:55:29
Razvan

Put this code in your first activity(starting activity of the app):

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

You are getting

DuplicateFileException: Duplicate files copied in APK

Make sure Same dependencies are calling or not .

Pull exclude out of the dependencies section and put in configurations. e.g.

dependencies {
    ...
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile 'org.apache.httpcomponents:httpmime:4.3.5'
    ...
}

configurations {
    all*.exclude group: 'org.apache.httpcomponents',module: 'httpclient'
}

From the log:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK log4j.properties
    File1: C:\Users\user\.gradle\caches\modules-2\files-2.1\org.brunocvcunha.inutils4j\inutils4j\0.4\566b82b1e70d7ebb8d1d3bb513d4bbf7913b118b\inutils4j-0.4.jar
    File2: C:\Users\user\.gradle\caches\modules-2\files-2.1\org.brunocvcunha.ghostme4j\ghostme4j\0.2\d44c3633f23975c355c89192d6e8daa9ce549b2d\ghostme4j-0.2.jar

It looks like you need to exclude log4j.properties from your project because it reside in both of the libraries (inutils4j and ghostme4j). You can try using:

android {
...
    packagingOptions {
         exclude '**/log4j.properties'
    }
...
}

Read more about PackagingOptions.

I think you missed to add MultiDexApplication in your manifest.

    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>

If you missed it. Add it and clean and rebuild project.

If you use Application Class, your application class should extend MultiDexApplication not Application.

class MyApplication extends MultiDexApplication

Reference: https://developer.android.com/studio/build/multidex.html

Hope it helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!