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

前端 未结 5 1785
悲&欢浪女
悲&欢浪女 2021-01-18 11:40

I\'m developing an app in which I\'m using this library.

On compiling the project, this error containing TransformException and RuntimeException<

相关标签:
5条回答
  • 2021-01-18 11:53

    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 :)

    0 讨论(0)
  • 2021-01-18 11:58

    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);
        }
    }
    
    0 讨论(0)
  • 2021-01-18 11:58

    You are getting

    DuplicateFileException: Duplicate files copied in APK

    Make sure Same dependencies are calling or not .

    0 讨论(0)
  • 2021-01-18 12:02

    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'
    }
    
    0 讨论(0)
  • 2021-01-18 12:04

    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.

    0 讨论(0)
提交回复
热议问题