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

4.1k views Asked by At

I'm trying yo add this third party to my project this third party used annotation processing with kotlinpoet to generate analytics classes for log user events on firebase or whatever analytical tools, but i faced this issue

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)

this is my gradle files

App build 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'

Project build 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 properties

# 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

Please keep in your mind this third party witch i'm trying to add to my project working fine on other projects but not working on my project.

1

There are 1 answers

1
jbunting On BEST ANSWER

This usually happens when you have a dependency conflict. It appears that permissionsdispatcher depends on kotlinpoet 0.6.0. However, WinAnalytics depends on kotlinpoet 1.0.0-RC2. So when you added it, it updated your version of kotlinpoet to a version incompatible with permissionsdispatcher.

The PropertySpec$Companion.varBuilder method exists in kotlinpoet 0.6.0 but was removed in 1.0.0-RC2.

I can't test this because I don't have your project but here are the things that I would try (if possible):

  1. Upgrade permissionsdispatcher to 4.0.0 -- this uses a newer version of kotlinpoet (1.0.0-RC1) although that still has the varBuilder methods.

  2. Force the kotlinpoet version to 1.0.0-RC1 (hopefully WinAnalytics will still work).

If neither of these work, then you will likely need to restructure your project so that the kotlinpoet processing for permissionsdispatcher is in a different module from the kotlinpoet processing for WinAnalytics. Exactly how to go about this depends on your project specifics.