web-dev-qa-db-fra.com

compileReleaseKotlin échoue avec Java.lang.ClassNotFoundException: com.Sun.tools.javac.util.Context

J'essaie de construire mon projet Android (qui contient un module de bibliothèque) via un terminal à l'aide de gradlew. À partir d’Android Studio, il est compilé et installé avec succès, mais lorsque j’essaie d’exécuter ./gradlew assembleDebug, j’obtiens le stacktrace suivant:

Using kotlin incremental compilation
e: Java.lang.ClassNotFoundException: com.Sun.tools.javac.util.Context
        at Java.net.URLClassLoader.findClass(URLClassLoader.Java:381)
        at Java.lang.ClassLoader.loadClass(ClassLoader.Java:424)
        at Java.lang.ClassLoader.loadClass(ClassLoader.Java:357)
        at Java.lang.Class.forName0(Native Method)
        at Java.lang.Class.forName(Class.Java:264)
        at org.jetbrains.kotlin.gradle.tasks.JarSearchingUtilKt.findToolsJar(jarSearchingUtil.kt:48)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$toolsJar$2.invoke(GradleCompilerEnvironment.kt:21)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment$toolsJar$2.invoke(GradleCompilerEnvironment.kt:15)
        at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:131)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment.getToolsJar(GradleCompilerEnvironment.kt)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment.getCompilerClasspath(GradleCompilerEnvironment.kt:24)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.getDaemonConnection(GradleKotlinCompilerRunner.kt:289)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemon(GradleKotlinCompilerRunner.kt:132)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:112)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.compileWithDaemonOrFallback(GradleKotlinCompilerRunner.kt:49)
        at org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner.runCompiler(KotlinCompilerRunner.kt:134)
        at org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner.runJvmCompiler(GradleKotlinCompilerRunner.kt:73)
        at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:259)
        at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:160)
        at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:141)
        at Sun.reflect.GeneratedMethodAccessor530.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: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)
        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.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.Java:28)
        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)
        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)

e: Compiler terminated with internal error
:render-engine:compileReleaseKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':render-engine:compileReleaseKotlin'.
> Internal compiler error. See log for more details

construction principale:

buildscript {
    ext.kotlin_version = '1.1.2-2'
    ext.anko_version = '0.9'
    ext.Android_plugin_version = '2.3.1'
    ext.appcompat = '25.3.1'

    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.Android.tools.build:gradle:$Android_plugin_version"
    }
}

allprojects {
    /**
     *  REQUIRED FOR IGNORING JAVADOCS FOR KT FILES
     */
    tasks.withType(Javadoc) {
        excludes = ['**/*.kt']
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }

    repositories {
        maven { url "https://jitpack.io" }

        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }

        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

le module build.gradle:

apply plugin: 'com.Android.library'
apply plugin: 'maven-publish'
apply plugin: 'kotlin-Android'
apply plugin: 'kotlin-Android-extensions'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

Android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName version

        testInstrumentationRunner "Android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-Android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main.Java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    // TEST
    compile fileTree(dir: 'libs', include: ['*.jar'])
    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'
    testCompile 'junit:junit:4.12'

    // GOOGLE
    compile 'com.google.code.gson:gson:2.8.0'
    compile "com.Android.support:appcompat-v7:$appcompat"
    compile "com.Android.support:cardview-v7:$appcompat"
    compile "com.Android.support:design:$appcompat"

    // OTHER
    compile('org.simpleframework:simple-xml:2.7.+') {
        exclude module: 'stax'
        exclude module: 'stax-api'
        exclude module: 'xpp3'
    }
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'org.Apache.commons:commons-io:1.3.2'

    // RX Android
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'

    // KOTLIN
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    // ANKO
    compile "org.jetbrains.anko:anko-common:$anko_version"
    compile "org.jetbrains.anko:anko-sdk15:$anko_version"
    compile "org.jetbrains.anko:anko-support-v4:$anko_version"
    compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
}

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-Android-extensions:$kotlin_version"
    }
}

kapt {
    generateStubs = true
}

IMPORTANT: J'essaie cela sur le système d'exploitation Elmentary (openjdk1.8.0) et le même projet peut être exécuté sur un autre ordinateur avec Ubuntu

13
Humble Student

OK, le problème est avec JDK, j'utilisais Open JDK 8 et il manquait tools.jar pour une raison quelconque, je suis passé à Oracle JDK et maintenant cela fonctionne à merveille! 

17
Humble Student

Je l'ai résolu uniquement en remplaçant dans build.gradle this

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.30"

avec ça:

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.30"
4
vovahost

J'ai compris que sur CentOS 7, cette erreur pouvait être provoquée par l'absence du bon package Java. Donc, au lieu de yum install Java-1.8.0-openjdk, j’ai utilisé yum install Java-1.8.0-openjdk-devel et cela a fonctionné. Sur Ubuntu, il n'y a pas de paquetage devel, mais j'espère que cette réponse aidera quand même.

1
Anton

J'ai eu ce problème exact sous Windows lorsque le répertoire bin du JDK n'était pas dans PATH.

Le processus est décrit ici: http://docs.Oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#path

1
Sean Dawson

Le problème est dû à C:\ProgramData\Oracle\Java\javapath, qui pointe sur le jre non-jdk, ne trouvant donc pas de fichiers jar spécifiques à javac. Supprimez-le avec C:\Program Files\Java\jdk1.8.0_171\bin (par exemple).

1
Raj Kumar

Si vous avez des fenêtres, changez votre PATH pour qu'il inclue C:\Program Files\Java\jdk1.8.0_151\bin au lieu de C:\ProgramData\Oracle\Java\javapath

Ouais, ça peut casser dans une mise à jour ou autre, mais vu qu'une mise à jour a cassé ma machine ... Au moins, vous contrôlez maintenant.

Mon hypothèse est que C:\ProgramData\Oracle\Java\javapath pointe vers le jre non-jdk, ne trouvant donc pas de fichiers jar spécifiques à javac.

1
Raul