Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build hanging when jackOptions is enabled for Java 1.8

I want to use lambdas in my project so I decided to switch to Java 1.8. Android Studio (2.1.3) forced me to enable jackOptions. Also I did install Java 1.8 on my mac and when I run javac -version in terminal I get javac 1.8.0_101 and the JDK in android studio points to the right one.

When I try to build my project, gradle gets stuck on: :app:compileDebugJavaWithJack

I did the following and nothing worked:

  • gradlew clean
  • git clean -fdx and reimport the project
  • gradlew --stacktrace assemble

If I revert back to Java 1.7 I lose the lambdas feature but project builds properly.

Any ideas what could be the problem?

UPDATE

Ok so after waiting for more than 5 minutes finally gradle did spit the following error:

ERROR: Dex writing phase: classes.dex has too many IDs. Try using multi-dex

com.android.jack.api.v01.CompilationException: Dex writing phase: classes.dex has too many IDs. Try using multi-dex
        at com.android.jack.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:113)
        at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1852)
        at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJack(AndroidBuilder.java:1679)
        at com.android.build.gradle.internal.transforms.JackTransform.runJack(JackTransform.java:221)
        at com.android.build.gradle.internal.transforms.JackTransform.transform(JackTransform.java:195)
        at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:178)
        at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:174)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:156)
        at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:173)
        at sun.reflect.GeneratedMethodAccessor412.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.jack.JackAbortException: Dex writing phase: classes.dex has too many IDs. Try using multi-dex
        at com.android.jack.backend.dex.DexFileWriter.run(DexFileWriter.java:90)
        at com.android.jack.backend.dex.DexFileWriter.run(DexFileWriter.java:41)
        at com.android.sched.scheduler.ScheduleInstance.runWithLog(ScheduleInstance.java:203)
        at com.android.sched.scheduler.MultiWorkersScheduleInstance$SequentialTask.process(MultiWorkersScheduleInstance.java:466)
        at com.android.sched.scheduler.MultiWorkersScheduleInstance$Worker.run(MultiWorkersScheduleInstance.java:163)
Caused by: com.android.jack.backend.dex.DexWritingException: Dex writing phase: classes.dex has too many IDs. Try using multi-dex
        at com.android.jack.backend.dex.SingleDexWritingTool.write(SingleDexWritingTool.java:59)
        at com.android.jack.backend.dex.DexFileWriter.run(DexFileWriter.java:87)
        ... 4 more
Caused by: com.android.jack.backend.dex.SingleDexOverflowException: classes.dex has too many IDs. Try using multi-dex
        ... 6 more
Caused by: com.android.jack.tools.merger.MethodIdOverflowException: Method ID overflow when trying to merge dex files
        at com.android.jack.tools.merger.ConstantManager.addDexFile(ConstantManager.java:177)
        at com.android.jack.tools.merger.JackMerger.addDexFile(JackMerger.java:69)
        at com.android.jack.backend.dex.DexWritingTool.mergeDex(DexWritingTool.java:149)
        at com.android.jack.backend.dex.SingleDexWritingTool.write(SingleDexWritingTool.java:57)
        ... 5 more
:app:transformJackWithJackForTabletsDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformJackWithJackForTabletsDebug'.
> com.android.build.api.transform.TransformException: com.android.jack.api.v01.CompilationException: Dex writing phase: classes.dex has too many IDs. Try using multi-dex

So I did turn on multidex and it got stuck on Building 96% > :app:transformJackWithJackForTabletsDebug

like image 496
Karim Fikani Avatar asked Mar 12 '23 03:03

Karim Fikani


1 Answers

I solved by add a line to app/build.gradle multiDexEnabled = true as below

android{
...
    compileSdkVersion rootProject.compileVersion
    buildToolsVersion rootProject.buildToolsVersion
    defaultConfig {
       multiDexEnabled true
    }

...
}

and in the project build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'        
    }
}

allprojects {
    repositories {
        jcenter()

    }

}

ext {
    buildToolsVersion = "24.0.3"
    supportLibVersion = "24.2.1"
}
like image 118
Yu Jiaao Avatar answered Apr 27 '23 21:04

Yu Jiaao