web-dev-qa-db-ja.com

compileReleaseKotlinがJava.lang.ClassNotFoundExceptionで失敗する:com.Sun.tools.javac.util.Context

私はAndroidプロジェクト(ライブラリモジュールを含む)をターミナルからgradlewを使用してビルドしようとしています。 Android Studio内からコンパイルおよびインストールは成功しましたが、./gradlew assembleDebugを実行しようとすると、次のスタックトレースが表示されます。

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

メイン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:

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
}

重要:Elmentary OS(openjdk1.8.0)で試しており、同じプロジェクトをUbuntuを使用して他のコンピューターで実行できます

14
Humble Student

OK、問題はJDKにあります。OpenJDK 8を使用していて、何らかの理由でtools.jarが欠落していたため、Oracle JDKに切り替えたところ、魅力的に動作しました。

17
Humble Student

私はbuild.gradleをこれで置き換えるだけでそれを解決しました

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

これとともに:

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

CentOS 7では、このエラーcabは正しいJavaパッケージがないために発生します。そのため、yum install Java-1.8.0-openjdkの代わりにyum install Java-1.8.0-openjdk-develを使用し、それが機能しました。 Ubuntuにはdevel packegeはありませんが、とにかくこの答えが役に立てば幸いです。

1
Anton

JDK binディレクトリがPATHにない場合、Windowsでこの問題が発生しました。

プロセスはここに文書化されています: http://docs.Oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#path

1
Sean Dawson

この問題は、jdk以外のjreを指すC:\ ProgramData\Oracle\Java\javapathが原因であり、javac固有のjarを見つけることができません。 C:\ Program Files\Java\jdk1.8.0_171\binで削除してください(例:)

1
Raj Kumar

ウィンドウがある場合は、C:\Program Files\Java\jdk1.8.0_151\binではなくC:\ProgramData\Oracle\Java\javapathが含まれるようにPATHを変更します。

ええ、それはアップデートや何かで壊れるかもしれませんが、アップデートが私のマシンを壊したことを考慮して...少なくともあなたは今コントロールしています。

私の推測では、C:\ProgramData\Oracle\Java\javapathは非jdk jreを指しているため、javac固有のjarを見つけることができません。

1
Raul