3

我的项目之前一直运行良好,直到我升级到API 28并重构为Androidx. 首先我认为我必须解决问题代码,因为重构后未解决的参考代码太多。在我解决了很多问题后,我仍然收到错误

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

所以从gradle控制台我得到这样的错误

: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 apollo-codegen@0.19.1: 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

从那个错误中,我得到这样的错误

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

所以,我认为这是我的代码无法编译成功的问题

这是我的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(应用程序)

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'
4

2 回答 2

8

您是否检查了您的 jdk 路径,其中文件夹名称包含特殊符号,例如“+”,我更改为“_”。错误得到修复。示例:文件夹名称为 1.8.0+282 -> 1.8.0_282。

于 2021-06-29T08:53:30.927 回答
3

在此处输入图像描述

我最近遇到了同样的问题,并以一种非常简单的方式解决了它,但首先我需要将其上下文化。就我而言,我尝试使用 ./gradlew 直接从终端构建一个适用于 android 的应用程序

所以我只是在终端上运行了以下命令:

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

在我的场景中,我使用的是采用openjdk-8.jdk,检查你使用的是哪个jdk并遵循相同的原则。您也可以使用这些命令定义环境变量。但这是最快的方式(但它永远不会是唯一的方式)

于 2021-04-08T13:15:59.697 回答