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

半城伤御伤魂 提交于 2019-12-19 19:00:13

问题


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

On compiling the project, this error containing TransformException and RuntimeException is popping up:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\hp\.gradle\caches\modules-2\files-2.1\org.brunocvcunha.instagram4j\instagram4j\1.4\e86d0ec82fb3eb4225b983e6dc14db048005bc9b\instagram4j-1.4.jar' to 'C:\Users\hp\Downloads\Hamy\app\build\intermediates\transforms\dex\debug\folders\1000\10\instagram4j-1.4_ea292e8a2c317dbd8ab0226ff9507ee97ac0794b'

Here's build.gradle (Module: app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.xxx.abc"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'LICENSE.txt'
        exclude '**/log4j.properties'
//        exclude 'log4j.properties'
        exclude 'org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib'
        exclude 'META-INF/DEPENDENCIES'
    }
}

repositories {
    mavenCentral()
}

android {
    useLibrary 'org.apache.http.legacy'
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:preference-v7:25.3.1'
    compile 'ai.api:sdk:2.0.7@aar'
    compile 'ai.api:libai:1.4.8'
    compile 'com.google.code.gson:gson:2.7'
    compile 'commons-io:commons-io:2.4'
    compile 'com.twitter.sdk.android:twitter:3.1.1'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.android.support:multidex:1.0.1'
    compile 'org.brunocvcunha.instagram4j:instagram4j:1.4'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile 'org.apache.httpcomponents:httpmime:4.3.5'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    testCompile 'junit:junit:4.12'
}

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

UPDATE:

Without changing anything in the code, I'm getting this error now:

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

and when I'm trying to delete the files they are getting created again while running the app.

Gradle console output:

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\user\Downloads\appNmae\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\user\Downloads\appName\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:50)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:43)
    at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:40)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:75)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\hp\Downloads\Hamy\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\hp\Downloads\Hamy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:176)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
    ... 78 more
Caused by: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\hp\Downloads\Hamy\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\hp\Downloads\Hamy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
    at com.android.build.gradle.internal.transforms.MultiDexTransform.transform(MultiDexTransform.java:188)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:185)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:181)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 85 more
Caused by: com.android.ide.common.process.ProcessException: Error while executing java process with main class com.android.multidex.ClassReferenceListBuilder with arguments {C:\Users\hp\Downloads\Hamy\app\build\intermediates\multi-dex\debug\componentClasses.jar C:\Users\hp\Downloads\Hamy\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
    at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:74)
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49)
    at com.android.builder.core.AndroidBuilder.createMainDexList(AndroidBuilder.java:1384)
    at com.android.build.gradle.internal.transforms.MultiDexTransform.callDx(MultiDexTransform.java:309)
    at com.android.build.gradle.internal.transforms.MultiDexTransform.computeList(MultiDexTransform.java:265)
    at com.android.build.gradle.internal.transforms.MultiDexTransform.transform(MultiDexTransform.java:186)
    ... 88 more
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Android\Android Studio\jre\bin\java.exe'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:369)
    at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:47)
    ... 92 more

UPDATE: 31-08-2017:

After trying all which is recommended in the answers below, I'm still getting this error:

Error:Error converting bytecode to dex:
Cause: PARSE ERROR:
InvokeDynamic not supported
...while preparsing cst 005c at offset 00000195
...while parsing org/brunocvcunha/instagram4j/Instagram4j.class
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\hp\.gradle\caches\modules-2\files-2.1\org.brunocvcunha.instagram4j\instagram4j\1.4\e86d0ec82fb3eb4225b983e6dc14db048005bc9b\instagram4j-1.4.jar' to 'C:\Users\hp\Downloads\abc\app\build\intermediates\transforms\dex\debug\folders\1000\10\instagram4j-1.4_ea292e8a2c317dbd8ab0226ff9507ee97ac0794b'

I'm unable to figure out why am I getting this error here. Please help me with it.


回答1:


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);
    }
}



回答2:


You are getting

DuplicateFileException: Duplicate files copied in APK

Make sure Same dependencies are calling or not .




回答3:


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'
}



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/45802830/getting-apptransformclasseswithdexfordebug-error-on-compiling-the-project-hav

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