我正在尝试将此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.access$1800(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$2.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$1.invoke(KotlinToJVMBytecodeCompiler.kt:375)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.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$1$1$2.invoke(CompileServiceImpl.kt:442)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1029)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.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$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.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$0(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中删除​​。

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


permissionsdispatcher升级到4.0.0-尽管它仍然具有kotlinpoet方法,但使用的是1.0.0-RC1varBuilder)的较新版本。
强制将kotlinpoet版本设置为1.0.0-RC1(希望WinAnalytics仍然可以使用)。


如果这些都不起作用,则您可能需要重组项目,以使kotlinpoetpermissionsdispatcher处理与kotlinpoetWinAnalytics处理位于不同的模块中。确切的处理方法取决于您的项目细节。

关于java - java.lang.NoSuchMethodError:com.squareup.kotlinpoet.PropertySpec $ Companion.varBuilder,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53191316/

10-10 01:23