web-dev-qa-db-de.com

compileReleaseKotlin schlägt fehl mit Java.lang.ClassNotFoundException: com.Sun.tools.javac.util.Context

Ich versuche, mein Android-Projekt (das ein Bibliotheksmodul enthält) über das Terminal mit gradlew zu erstellen. In Android Studio wird es erfolgreich kompiliert und installiert. Wenn ich jedoch ./gradlew assembleDebug ausführen möchte, erhalte ich den folgenden Stacktrace:

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

main build.gradle:

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
}

build.gradle des Moduls:

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
}

WICHTIG: Ich versuche, dass auf Elmentary OS (openjdk1.8.0) und dasselbe Projekt auf einem anderen Computer mit Ubuntu ausgeführt werden kann

13
Humble Student

OK, Problem ist mit JDK, ich habe Open JDK 8 verwendet und es fehlte tools.jar aus irgendeinem Grund, ich wechselte zu Oracle JDK und jetzt funktioniert es wie ein Zauber! 

17
Humble Student

Ich habe es nur durch das Ersetzen in build.gradle gelöst

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

mit diesem:

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

Ich habe herausgefunden, dass auf CentOS 7 dieser Fehler durch das Fehlen des richtigen Java-Pakets verursacht wird. Also habe ich anstelle von yum install Java-1.8.0-openjdkyum install Java-1.8.0-openjdk-devel verwendet und es hat funktioniert. Auf Ubuntu gibt es kein devel-Paket, aber ich hoffe, diese Antwort hilft trotzdem.

1
Anton

Ich habe genau dieses Problem unter Windows erhalten, wenn sich das JDK-Verzeichnis bin nicht in meinem Pfad befindet.

Der Prozess ist hier dokumentiert: http://docs.Oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#path

1
Sean Dawson

Das Problem ist auf C:\ProgramData\Oracle\Java\javapath zurückzuführen, das auf die nicht-jdk-jre verweist, sodass keine javac-spezifischen Gläser gefunden werden können. Bitte entfernen Sie es mit C:\Programme\Java\jdk1.8.0_171\bin (zum Beispiel)

1
Raj Kumar

Wenn Sie über Fenster verfügen, ändern Sie Ihren PFAD so, dass er C:\Program Files\Java\jdk1.8.0_151\bin anstelle von C:\ProgramData\Oracle\Java\javapath enthält.

Ja, es könnte ein Update oder was auch immer kaputt gehen, aber in Anbetracht dessen, dass ein Update meinen Rechner kaputt gemacht hat ... Zumindest haben Sie jetzt die Kontrolle.

Meine Vermutung ist, dass C:\ProgramData\Oracle\Java\javapath auf die Nicht-Jdk-Jre verweist, wodurch keine javac-spezifischen Gläser gefunden werden können.

1
Raul