e: [kapt] 'com.sun.tools.javac.util.Context' class can't be found ('tools.jar' is absent in the plugin classpath). Kapt won't work
Asked Answered
P

2

4

My project is always working fine before, until I upgrade into API 28 And refactor into Androidx. First I think I must solve the problem code because too much the unresolve reference code after refactoring. After I solve many problem, I still getting error

org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:kaptGenerateStubsDevKotlin'.
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:145)
    at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:115)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
    at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
    ... 30 more

So from gradle console I getting error like this

:app:clean
:clean
:app:checkDevClasspath
:app:preBuild UP-TO-DATE
:app:preDevBuild
:app:compileDevAidl NO-SOURCE
:app:compileDevRenderscript
:app:nodeSetup UP-TO-DATE
npm WARN deprecated [email protected]: The 'apollo-codegen' command has been replaced with the more-powerful 'apollo' CLI. Switch to 'apollo' to ensure future updates and visit https://npm.im/apollo#code-generation for more information.
:app:installApolloCodegen
:app:generateDevApolloIR
:app:generateDevApolloClasses
:app:checkDevManifest
:app:generateDevBuildConfig
:app:mainApkListPersistenceDev
:app:generateDevResValues
:app:generateDevResources
:app:processDevGoogleServices
Parsing json file: /media/rachmad/Data/PROJECT/appety/android/app/src/dev/google-services.json
:app:mergeDevResources
:app:createDevCompatibleScreenManifests
:app:processDevManifest
:app:splitsDiscoveryTaskDev
:app:processDevResources
e: [kapt] 'com.sun.tools.javac.util.Context' class can't be found ('tools.jar' is absent in the plugin classpath). Kapt won't work.
:app:kaptGenerateStubsDevKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptGenerateStubsDevKotlin'.
> Compilation error. See log for more details

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

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptGenerateStubsDevKotlin'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    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.run(DefaultTaskGraphExecuter.java:256)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
    at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:16)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:453)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:415)
    at org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask.execute(KaptGenerateStubsTask.kt:99)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
    ... 30 more


* Get more help at https://help.gradle.org

From that error, I getting error like this

e: [kapt] 'com.sun.tools.javac.util.Context' class can't be found ('tools.jar' is absent in the plugin classpath). Kapt won't work.
:app:kaptGenerateStubsDevKotlin FAILED

So, I think this is the problem why my code cannot compile successful

here is my build.gradle

buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//        classpath 'com.apollographql.apollo:gradle-plugin:0.3.2'
        classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.0.1-SNAPSHOT'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.2.0'
    }

}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
        maven { url "https://google.bintray.com/flexbox-layout" }
    }
}

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

build.gradle (App)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.apollographql.android'
apply plugin: 'kotlin-kapt'

android {
    signingConfigs {
        config {
            keyAlias 'key0'
            keyPassword 'admin123'
            storeFile file('/media/rachmad/Data/SIGNEDAPK/signed.jks')
            storePassword 'admin123'
        }
    }
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "coba.coba.id"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 15
        versionName "0.1.15"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
//        consumerProguardFiles 'proguard-file.pro'
        signingConfig signingConfigs.config
        multiDexEnabled true

        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    buildTypes {
        debug {
            buildConfigField "String", "SERVER_URL", '"http://10.88.16.29:5000"'
            applicationIdSuffix = ".debug"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            debuggable true
            buildConfigField "String", "SERVER_URL", '"https://coba.coba.id"'
            signingConfig signingConfigs.config
        }
    }
}

apollo {
    apollo {
        customTypeMapping = [
                "Date"    : "java.util.Date",
                "DateTime": "java.util.Date"
        ]
    }
    useSemanticNaming = false
}

dependencies {
    def lifecycle_version = "2.0.0"

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'com.google.android.material:material:1.1.0-alpha01'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.palette:palette:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.android.gms:play-services-places:16.0.0'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0-alpha01'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0-alpha01'
    implementation 'androidx.mediarouter:mediarouter:1.1.0-alpha01'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0-alpha01'
    implementation 'androidx.exifinterface:exifinterface:1.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.palette:palette:1.0.0'
    implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    implementation "androidx.paging:paging-runtime:$lifecycle_version"
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
    implementation "androidx.room:room-runtime:$lifecycle_version"
    implementation "androidx.room:room-rxjava2:$lifecycle_version"
    kapt "androidx.room:room-compiler:$lifecycle_version"
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.google.firebase:firebase-config:16.1.0'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okio:okio:1.14.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.1.0'
    implementation 'com.facebook.android:facebook-android-sdk:4.33.0'
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'com.google.guava:guava:25.0-android'
    implementation ('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
    implementation 'com.google.zxing:core:3.3.2'
    implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
    implementation 'com.google.android:flexbox:1.1.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'com.nulab-inc:zxcvbn:1.2.2'

    implementation 'com.jakewharton.rxbinding:rxbinding:1.0.0'
    implementation 'io.reactivex:rxjava:1.2.3'
    implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
    implementation 'com.apollographql.apollo:apollo-runtime:1.0.0-alpha3'
    implementation "com.apollographql.apollo:apollo-android-support:1.0.0-alpha3"
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5'
}
apply plugin: 'com.google.gms.google-services'
Patric answered 13/12, 2018 at 10:23 Comment(2)
Possible duplicate of compileReleaseKotlin fails with java.lang.ClassNotFoundException: com.sun.tools.javac.util.ContextConsumable
You should check if the bundled java files in the Android Studio Package isn't blocked. Especially if you have to do a new install (zip -> unzip, unblock the downloaded file prior to unzipping) (ie AS3.5C8 -> AS3.5C9 where new install is necessary)Torres
I
10

Did you check your jdk path which folder name contain special symbol like '+', I change to '_'. error be fix. example: folder name is 1.8.0+282 -> 1.8.0_282.

PS: If you use the soft link that: /Library/Java/JavaVirtualMachines/openjdk-8.jdk, you should update the link:

cd /Library/Java/JavaVirtualMachines/
sudo rm openjdk-8.jdk
sudo ln -s /usr/local/Cellar/openjdk@8/1.8.0_282/libexec/openjdk.jdk openjdk-8.jdk
Indogermanic answered 29/6, 2021 at 8:53 Comment(3)
I used homebrew openjdk@8 which was installed at /usr/local/Cellar/openjdk@8/1.8.0+282, can confirm that this + sign made the compilation failed. Changing to a more standard path fixed the issue.Johannejohannes
Same setup as @Johannejohannes here. Renaming the directory by replacing the + with a _ as suggested by ysjia's answer did the trick. I wonder how you guys figured out this was the issue.Rathskeller
This was also the fix for me, mostly. However, after I renamed the directory, gradle complained that it couldn't find Java. Therefore I also had to add export JAVA_HOME=/usr/local/Cellar/openjdk@8/1.8.0_302/libexec/openjdk.jdk/Contents/Home and that works.Udale
G
5

enter image description here

I recently had the same problem and solved it in a very simple way, but first I need to contextualize it. In my case I tried to build an app for android directly from the terminal using ./gradlew

So I just ran the commands below on my terminal:

export CLASSPATH=/Library/Java/JavaVirtualMachines/<your_jdk_version>/Contents/Home/lib export JAVA_HOME=/Library/Java/JavaVirtualMachines/<your_jdk_version>/Contents/Home

In my scenario, I was using adoptopenjdk-8.jdk, check which jdk you are using and follow the same principle. You can define an environment variable with these commands as well. But this is the fastest way (but it will never be the only one)

Grease answered 8/4, 2021 at 13:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.