moxy-community / Moxy

Moxy is MVP library for Android with incremental annotation processor and ktx features
MIT License
324 stars 33 forks source link

Compile error after migration from 1.5.3 to 2.2.0 #120

Closed stan-ko closed 3 years ago

stan-ko commented 3 years ago

Recently I started to update legacy project which uses Moxy 1.5.3 (and it has new features written in kotlin while the rest part in Java) to use AndroidX. So I need to use newer moxy library version which utilizes AndroidX as well. I followed migration guide but in the end I've stuck with the following issue:

[kapt] An exception occurred: java.lang.NoSuchMethodError: kotlin.jvm.internal.PropertyReference1Impl.(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V at moxy.compiler.presenterbinder.InjectPresenterProcessor$collectFields$2$tag$1.(InjectPresenterProcessor.kt) at moxy.compiler.presenterbinder.InjectPresenterProcessor$collectFields$2$tag$1.(InjectPresenterProcessor.kt) at moxy.compiler.presenterbinder.InjectPresenterProcessor.collectFields(InjectPresenterProcessor.kt:66) at moxy.compiler.presenterbinder.InjectPresenterProcessor.process(InjectPresenterProcessor.kt:41) at moxy.compiler.presenterbinder.InjectPresenterProcessor.process(InjectPresenterProcessor.kt:22) at moxy.compiler.MvpCompiler.generateCode(MvpCompiler.kt:181) at moxy.compiler.MvpCompiler.processInjectors(MvpCompiler.kt:162) at moxy.compiler.MvpCompiler.throwableProcess(MvpCompiler.kt:108) at moxy.compiler.MvpCompiler.process(MvpCompiler.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.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 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:357) 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:573) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

Moxy section in gradle.build:

//MVP - Moxy 2.2.0
implementation "com.github.moxy-community:moxy:$rootProject.moxy"
implementation "com.github.moxy-community:moxy-androidx:$rootProject.moxy"
kapt "com.github.moxy-community:moxy-compiler:$rootProject.moxy"

compileSdkVersion 29
buildToolsVersion "29.0.2"

AndroidStudio version: 3.5.3 Gradle.Wrapper.Properties: distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        jcenter()
        google()
        mavenCentral()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        gradle.startParameter.taskNames.each { task ->
            if (task.contains(":app") && !task.toLowerCase().contains("amazon")){
                classpath 'com.google.gms:google-services:4.3.3'
            }
        }
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'io.fabric.tools:gradle:1.31.2'
    }
}
ext {
    moxy = '2.2.0'
    okHttpVersion = '3.10.0'
    gsonVersion = '2.8.6'
    retrofitVersion = '2.4.0'
    loopJVersion = '1.4.7'
}

project build.gradle:

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

android {

    useLibrary 'org.apache.http.legacy'

    packagingOptions {
        exclude 'AndroidManifest.xml'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        signingConfig signingConfigs.config
    }

    lintOptions {
        checkAllWarnings true
        checkReleaseBuilds false
        abortOnError false
    }

    dexOptions {
        javaMaxHeapSize "5120M"
    }

    flavorDimensions "default"
    productFlavors {
...
    }

    bundle {
//        language {
//            enableSplit = true
//        }
        density {
            enableSplit = true
        }
        abi {
            enableSplit = true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    gradle.startParameter.taskNames.each { task ->
        if (task.contains(":app") && !task.toLowerCase().contains("amazon")) {
            apply plugin: 'com.google.gms.google-services'
        }
    }

}

dependencies {
    //Network
    implementation project(':libraries:network')
    implementation files('libs/httpclient-android-4.3.5.1.jar')
    implementation files('libs/httpmime-4.3.jar')
    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.6.0'

    //Image
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
//    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    kapt 'com.github.bumptech.glide:compiler:4.8.0'
    implementation("com.github.bumptech.glide:glide:4.8.0") {
        exclude group: "com.android.support"
    }
    implementation 'jp.wasabeef:glide-transformations:4.0.1'
    implementation 'com.alexvasilkov:gesture-views:2.6.0'
    implementation 'com.squareup.picasso:picasso:2.71828'

    //Video
    implementation project(':libraries:jcvideoplayer-lib')
    implementation 'com.googlecode.mp4parser:isoparser:1.0.2'

    //Web
    implementation project(':libraries:agentweb-core')
    implementation project(':libraries:agentweb-download')
    implementation project(':libraries:agentweb-filechooser')
    implementation 'org.jsoup:jsoup:1.12.1'

    //MVP - Moxy 2.2.0
    implementation "com.github.moxy-community:moxy:$rootProject.moxy"
    implementation "com.github.moxy-community:moxy-androidx:$rootProject.moxy"
//    annotationProcessor "com.github.moxy-community:moxy-compiler:$rootProject.moxy"
//    implementation "com.github.moxy-community:moxy-ktx:$rootProject.moxy"
    kapt "com.github.moxy-community:moxy-compiler:$rootProject.moxy"

    //UI
    implementation project(':libraries:flexible-adapter')
    implementation project(':libraries:libraryStick')
    implementation project(':libraries:libraryCrouton')
    implementation project(':libraries:libraryPick')
    implementation project(':libraries:libSwipeRefresh')
    implementation 'cat.ereza:customactivityoncrash:2.1.0'
    implementation 'jp.wasabeef:recyclerview-animators:2.2.7'
    implementation 'com.daimajia.androidanimations:library:2.3@aar'
    implementation 'com.github.lzyzsd:circleprogress:1.2.1'
    implementation 'com.lantouzi.wheelview:library:1.1.2'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'
    implementation 'com.google.android:flexbox:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.romandanylyk:pageindicatorview:1.0.2'
    implementation 'com.contrarywind:Android-PickerView:4.1.9'

    //Utils
    implementation project(':libraries:sdp-android')
    implementation project(':libraries:ssp-android')
    implementation 'joda-time:joda-time:2.9.4'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'org.apache.commons:commons-lang3:3.0'
    implementation 'org.greenrobot:eventbus:3.1.1'
    implementation 'com.daimajia.easing:library:2.0@aar'
    implementation 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.2.1'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "com.google.firebase:firebase-messaging:18.0.0"
    implementation "com.crashlytics.sdk.android:crashlytics:2.10.1"
    implementation 'com.google.firebase:firebase-analytics:16.5.0'
    implementation 'com.github.deano2390:FlowTextView:2.0.5'

}

As for now I was able to migrate to AndroidX using 3rd party fork - [(https://jitpack.io/p/sergevalevich/moxy)]

    //MVP - Moxy 1.5.8 fork on AndroidX
    implementation 'tech.schoolhelper:moxy-x:1.7.0'
    implementation 'tech.schoolhelper:moxy-x-androidx:1.7.0'
    annotationProcessor 'tech.schoolhelper:moxy-x-compiler:1.7.0'
    kapt 'tech.schoolhelper:moxy-x-compiler:1.7.0'

Using this lib does not require following the migration guide since it built on Moxy 1.5.8.

So, project builds/compiles with Moxy 1.5.8 fork OK, works OK and if I switch to official Moxy 2.2.0 (no more changes except required according to migration guide) I will got the issue.

aasitnikov commented 3 years ago

Can you please also provide result of ./gradlew :<module-name>:dependencies task with Moxy version 2.2.0?

aasitnikov commented 3 years ago

@stan-ko this stacktrace doesn't look like the one from :dependencies, cause :dependencies task does not run compilation

stan-ko commented 3 years ago

Dependencies log is 312 Kb, I guess its a bas idea to post it here, so I sent it via Telegram

aasitnikov commented 3 years ago
Screenshot 2020-09-29 at 19 17 32 Screenshot 2020-09-29 at 19 17 24

So as you can see from screenshots above, kotlin 1.4 introduced new constructor in this class, and Moxy 2.2.0 compiled against 1.4.10. This class didn't change from 1.3.61 to 1.3.70, but using 1.3.70 in sample you provided somehow resolves the issue. I think it's a bug in kapt 1.3.61, where it uses wrong classpath to do annotation processing.

So updating to Kotlin 1.3.70 or higher should resolve the issue

stan-ko commented 3 years ago

Yes, thanks, kotlin version 1.3.70 fixed the issue!

bejibx commented 3 years ago

Should we close this issue then?

stan-ko commented 3 years ago

yes