java.lang.NoSuchMethodError: com.squareup.kotlinpoet.PropertySpec$Companion.varBuilder

java.lang.NoSuchMethodError: com.squareup.kotlinpoet.PropertySpec$Companion.varBuilder

我正在尝试将这个 third party 添加到我的项目中这个第三方使用 kotlinpoet 的注释处理来生成分析 类 用于在 firebase 或任何分析工具上记录用户事件,但我遇到了本期

e: [kapt] An exception occurred: java.lang.NoSuchMethodError: com.squareup.kotlinpoet.PropertySpec$Companion.varBuilder(Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;[Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/PropertySpec$Builder;
    at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createPendingRequestProperty(KotlinBaseProcessorUnit.kt:97)
    at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createProperties(KotlinBaseProcessorUnit.kt:71)
    at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createFile(KotlinBaseProcessorUnit.kt:41)
    at permissions.dispatcher.processor.impl.kotlin.KotlinBaseProcessorUnit.createFile(KotlinBaseProcessorUnit.kt:18)
    at permissions.dispatcher.processor.PermissionsProcessor.processKotlin(PermissionsProcessor.kt:89)
    at permissions.dispatcher.processor.PermissionsProcessor.process(PermissionsProcessor.kt:66)
    at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:99)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access00(JavacProcessingEnvironment.java:91)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
    at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:55)
    at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:27)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:218)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:183)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:100)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration.invoke(TopDownAnalyzerFacadeForJVM.kt:95)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:105)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze.invoke(KotlinToJVMBytecodeCompiler.kt:375)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze.invoke(KotlinToJVMBytecodeCompiler.kt:67)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:366)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:120)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile.invoke(CompileServiceImpl.kt:442)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:1029)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1071)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1028)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:441)
    at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
    at sun.rmi.transport.Transport.run(Transport.java:200)
    at sun.rmi.transport.Transport.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run[=10=](TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    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)

这是我的 gradle 个文件

应用构建 gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: 'kotlin-kapt'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    dexOptions {
        javaMaxHeapSize "2g"
        jumboMode true
    }

    defaultConfig {
        applicationId "com.mohamed"

        minSdkVersion 21
        targetSdkVersion 28

        versionCode APP_VERSION_CODE as Integer
        versionName APP_VERSION_NAME

        manifestPlaceholders = [fireBaseEnabled: false]

        buildConfigField "String", "API_BASE_URL", DEV_API_BASE_URL

        setProperty("archivesBaseName", "$archivesBaseName-$versionName")

        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true

        ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "x86_64", "mips", "mips64" }
    }

    buildTypes {

        debug {
            debuggable true
            minifyEnabled false
            versionNameSuffix "-dev"
            applicationIdSuffix ".dev"
            manifestPlaceholders = [fireBaseEnabled: true]

            buildConfigField "String", "API_BASE_URL", DEV_API_BASE_URL
            buildConfigField "String", "FIREBASE_ENVIRONMENT", SUBDOMAIN_DEV

            ext.enableCrashlytics = true
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.all { output ->

            def buildType = variant.variantData.variantConfiguration.buildType.name
            def newApkName = buildType + ".apk"

            outputFileName = new File(newApkName)
        }

        buildConfigField "String", "MOBILE_API_VERSION", MOBILE_API_VERSION
    }


    lintOptions {
        abortOnError false
    }

    configurations {
        cleanedAnnotations
        compile.exclude group: 'org.jetbrains', module: 'annotations'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:2.6.8'

    implementation 'com.android.support:gridlayout-v7:28.0.0'

    implementation 'com.github.paolorotolo:expandableheightlistview:1.0.0'

    implementation 'com.orhanobut:dialogplus:1.11@aar'

    implementation 'com.makeramen:roundedimageview:2.3.0'

    implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.1.0'

    implementation 'com.android.support.constraint:constraint-layout:1.1.1'

    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation "com.android.support:design:28.0.0"

    implementation 'com.android.support:multidex:1.0.3'

    implementation 'com.android.support:support-dynamic-animation:28.0.0'

    implementation 'com.hannesdorfmann.mosby:mvp:2.0.1'

    implementation 'com.squareup.okhttp3:okhttp:3.8.1'

    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'

    implementation 'com.jakewharton:butterknife:8.8.1'
    kapt 'com.jakewharton:butterknife-compiler:8.8.1'

    implementation('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') {
        transitive = true;
    }

    implementation 'commons-io:commons-io:2.4'

    implementation 'org.apache.commons:commons-collections4:4.1'

    implementation 'org.jetbrains:annotations-java5:15.0'

    implementation 'com.google.android.gms:play-services-vision:17.0.2'

    implementation 'com.google.android:flexbox:0.3.2'

    implementation 'com.google.firebase:firebase-core:16.0.4'

    implementation 'com.google.firebase:firebase-messaging:17.3.4'

    implementation 'com.google.firebase:firebase-database:16.0.4'

    debugImplementation 'com.facebook.stetho:stetho:1.5.0'
    implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'

    implementation 'com.squareup:otto:1.3.8'

    implementation 'com.writingminds:FFmpegAndroid:0.3.2'

    implementation 'com.github.michael-rapp:android-material-validation:2.1.2'

    implementation 'com.googlecode.libphonenumber:libphonenumber:8.2.0'

    implementation 'com.instabug.library:instabug:4.5.0'

    implementation 'com.facebook.fresco:fresco:1.8.1'
    implementation 'com.facebook.fresco:imagepipeline-okhttp3:1.8.1'

    implementation 'com.getkeepsafe.relinker:relinker:1.2.3'

    implementation 'me.zhanghai.android.materialratingbar:library:1.2.0'

    implementation 'eu.davidea:flexible-adapter:5.0.0-rc4'

    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'

    implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
    implementation 'com.google.zxing:core:3.3.0'

    implementation('com.github.hotchemi:permissionsdispatcher:3.2.0') {
        exclude module: "support-v13"
    }
    kapt "com.github.hotchemi:permissionsdispatcher-processor:3.2.0"

    implementation 'com.github.yalantis:ucrop:2.2.2-native'

    implementation 'com.chaos.view:pinview:1.3.2'

    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation "android.arch.persistence.room:runtime:1.1.1"
    kapt "android.arch.persistence.room:compiler:1.1.1"
    implementation "android.arch.persistence.room:rxjava2:1.1.1"
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

    implementation 'com.google.dagger:dagger:2.17'
    implementation 'com.google.dagger:dagger-android-support:2.17'
    kapt 'com.google.dagger:dagger-compiler:2.17'
    kapt 'com.google.dagger:dagger-android-processor:2.17'

    // For support multiple screen sized
    implementation 'com.intuit.ssp:ssp-android:1.0.6'
    implementation 'com.intuit.sdp:sdp-android:1.0.6'

    implementation 'com.winfooz.winanalytics:winanalytics:1.0.3-beta'
    kapt 'com.winfooz.winanalytics:compiler:1.0.3-beta'
}
apply plugin: 'com.google.gms.google-services'

项目构建gradle

buildscript {
    ext.kotlin_version = '1.3.0'

    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

        classpath 'com.google.gms:google-services:4.0.1'

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        maven {
            url "https://maven.google.com"
        }
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://dl.bintray.com/mnayef95/WinAnalytics" }
    }
}

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

gradle 属性

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true

#subdomain
SUBDOMAIN_DEV="example"
SUBDOMAIN_STAGING="example"

MOBILE_API_VERSION="/v10/"
APP_VERSION_NAME=1.0.0
APP_VERSION_CODE=1

# API_BASE_URL
DEV_API_BASE_URL="https://example.com"
STAGING_API_BASE_URL="http://example.com"
RELEASE_API_BASE_URL="https://www.example.com"

#FireBase Real time database child nodes
# Value to handle default Firebase root node
FIREBASE_PRODUCTION_NODE="root"

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

请记住这个第三方 我正在尝试添加到我的项目中,在其他项目上工作正常,但在我的项目上不工作。

这通常发生在你有依赖冲突的时候。 permissionsdispatcher 似乎依赖于 kotlinpoet 0.6.0。但是,WinAnalytics 取决于 kotlinpoet 1.0.0-RC2。因此,当您添加它时,它会将您的 kotlinpoet 版本更新为与 permissionsdispatcher.

不兼容的版本

PropertySpec$Companion.varBuilder 方法存在于 kotlinpoet 0.6.0 中,但在 1.0.0-RC2 中被删除。

我无法对此进行测试,因为我没有您的项目,但以下是我会尝试的事情(如果可能):

  1. 升级 permissionsdispatcher4.0.0 -- 这使用更新版本的 kotlinpoet (1.0.0-RC1) 尽管它仍然有 varBuilder 方法。

  2. 强制 kotlinpoet 版本为 1.0.0-RC1(希望 WinAnalytics 仍然有效)。

如果这些都不起作用,那么您可能需要重组项目,以便 kotlinpoetpermissionsdispatcher 的处理与对 kotlinpoet 的处理位于不同的模块中=13=]。具体如何操作取决于您的项目具体情况。