How to get a class/interface used by third party dependency when it is desugared?

623 views Asked by At

so I have this specific warning, I use desugaring and this warning comes up. one of my third party dependencies use this Bifunction but since it can't be found, app crashes. What I've found is that maybe desugaring doesn't have Bifunction class so jackson can't convert it. I must say it only gets error on Android-API 23 marshmallow and works fine on Android-API >23 devices.

EDIT if I set desugaring to true or false this problem happens so I'm sure there is a problem with 3rd party libraries accessing Bifunction from java.util.function.

Code:

List<Message> list;
list = mapper.convertValue(mapList, new TypeReference<List<Message>>() {});

Warning comes when I try to build the application with Desugaring enabled:

Warning in C:\Users\Keivan Shirkoubian\.gradle\caches\modules-2\files-2.1\com.android.tools\desugar_jdk_libs\1.0.9\359e5e4f4784f23beb30ba454b41f6f992e58481\desugar_jdk_libs-1.0.9.jar:java/util/concurrent/ConcurrentHashMap.class:
  Type `j$.$r8$wrapper$java$util$function$BiFunction$-V-WRP` was not found, it is required for default or static interface methods desugaring of `java.lang.Object java.util.concurrent.ConcurrentHashMap.compute(java.lang.Object, $-vivified-$.java.util.function.BiFunction)`

This is the crash log, it comes when I try to map my mapList to another list (List).

W/Java7Support: Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added
W/System.err: io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.NoClassDefFoundError: java.util.function.BiFunction
        at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
        at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:126)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:7331)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
    Caused by: java.lang.NoClassDefFoundError: java.util.function.BiFunction
        at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
        at java.lang.Class.getDexCacheType(Class.java:476)
        at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:166)
        at java.lang.reflect.Method.getParameterTypes(Method.java:170)
        at java.lang.Class.getDeclaredMethods(Class.java:679)
        at com.fasterxml.jackson.databind.util.ClassUtil.getClassMethods(ClassUtil.java:1124)
        at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector._addMemberMethods(AnnotatedMethodCollector.java:110)
        at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collect(AnnotatedMethodCollector.java:42)
        at com.fasterxml.jackson.databind.introspect.AnnotatedMethodCollector.collectMethods(AnnotatedMethodCollector.java:33)
        at com.fasterxml.jackson.databind.introspect.AnnotatedClass._methods(AnnotatedClass.java:365)
        at com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:305)
        at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:525)
        at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:309)
        at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getJsonValueAccessor(POJOPropertiesCollector.java:196)
        at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findJsonValueAccessor(BasicBeanDescription.java:252)
        at com.fasterxml.jackson.databind.ser.BasicSerializerFactory.findSerializerByAnnotations(BasicSerializerFactory.java:346)
        at com.fasterxml.jackson.databind.ser.BasicSerializerFactory.buildMapSerializer(BasicSerializerFactory.java:767)
        at com.fasterxml.jackson.databind.ser.BasicSerializerFactory.buildContainerSerializer(BasicSerializerFactory.java:568)
        at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:196)
        at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:165)
        at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1388)
        at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1336)
        at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:510)
        at com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddSecondarySerializer(PropertySerializerMap.java:90)
        at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase._findAndAddDynamic(AsArraySerializerBase.java:306)
        at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:115)
        at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79)
        at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
        at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
        at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3728)
        at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3678)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView.fetchDataFromResponseGroupContentsFromUnreadNew(ChatRefactorView.java:373)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView.fetchGroupContentsFromUnReadNew(ChatRefactorView.java:362)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView.configResponseGetGroupContentsFromUnRead(ChatRefactorView.java:344)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView.configGetGroupContentsFromUnRead(ChatRefactorView.java:329)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView.access$100(ChatRefactorView.java:60)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView$1.onNext(ChatRefactorView.java:165)
        at sanay.co.esn.chat_refactor.core.ChatRefactorView$1.onNext(ChatRefactorView.java:160)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:201)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:255)
        at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:124)
        ... 7 more
    Caused by: java.lang.ClassNotFoundException: Didn't find class "java.util.function.BiFunction" on path: DexPathList[[zip file "/data/app/sanay.co.esn-2/base.apk"],nativeLibraryDirectories=[/data/app/sanay.co.esn-2/lib/arm, /data/app/sanay.co.esn-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
        ... 48 more
        Suppressed: java.lang.ClassNotFoundException: java.util.function.BiFunction
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 50 more
        Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

[EDIT] here is build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        multiDexEnabled true
        applicationId "sanay.co.esn"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 3
        versionName "1.0.5"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true

        buildFeatures{
            dataBinding = true
            viewBinding = true
        }


    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
//        debug{
//            minifyEnabled true
//            shrinkResources true
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
//        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8

        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true

    }
    packagingOptions {
        exclude 'META-INF/library_release.kotlin_module'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation platform('com.google.firebase:firebase-bom:26.3.0')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.0-rc01'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.2'
    implementation 'androidx.navigation:navigation-ui:2.2.2'
    implementation 'com.google.firebase:firebase-database:19.5.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation "androidx.preference:preference:1.1.1"

    ///////////dagger
    implementation 'com.google.dagger:dagger:2.26'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.26'

    //////butterKnife
    implementation 'com.jakewharton:butterknife:10.2.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'


    ///////////lombok
    compileOnly 'org.projectlombok:lombok:1.18.12'
    annotationProcessor 'org.projectlombok:lombok:1.18.12'


    ///////////rx
    implementation "io.reactivex.rxjava2:rxjava:2.2.11"
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'


    /////////retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
    implementation "com.squareup.okhttp3:logging-interceptor:4.2.1"


    /////////Glide
    implementation 'androidx.fragment:fragment:1.2.4'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'


    ////////Timber
    implementation "com.jakewharton.timber:timber:4.7.1"


    /////AvLoading
    implementation "com.wang.avi:library:2.1.3"


    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation "androidx.lifecycle:lifecycle-common-java8:2.2.0"


    /////Room
    implementation "androidx.room:room-runtime:2.2.5"
    annotationProcessor "androidx.room:room-compiler:2.2.5"
    testImplementation "androidx.room:room-testing:2.2.5"


    ///////indicator
    implementation "com.github.hrskrs:InstaDotView:1.1"


    implementation 'com.github.massoudss:waveformSeekBar:1.1.4'

    implementation 'com.github.Adilhusen:circle-progress-ad-android-:1.0'
    implementation 'com.github.devendroid:ReadMoreOption:1.0.2'
    implementation 'com.github.chrisbanes:PhotoView:2.1.4'


    implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'

    implementation 'com.airbnb.android:lottie:3.4.0'
    implementation 'com.download.library:Downloader:4.1.4'


    implementation 'com.google.android.exoplayer:exoplayer:2.11.3'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.11.3'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.3'




    //folding cell
    implementation 'com.ramotion.foldingcell:folding-cell:1.2.3'


    implementation 'com.github.dariushm2:PersianCaldroid:1.0.1'

    implementation 'com.github.TutorialsAndroid:FilePicker:v8.0.19'

    implementation 'org.apache.commons:commons-lang3:3.6'
    implementation 'org.apache.commons:commons-io:1.3.2'

    implementation 'com.microsoft.signalr:signalr:5.0.2'
    implementation 'org.slf4j:slf4j-jdk14:1.7.25'

    implementation 'com.github.aliab:Persian-Date-Picker-Dialog:1.5.2'

    implementation 'com.google.firebase:firebase-messaging:21.0.1'
    implementation 'com.google.firebase:firebase-analytics:18.0.1'

    // for stream support in old Android versions
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'

    implementation "androidx.tonyodev.fetch2:xfetch2:3.1.5"

    implementation 'ch.acra:acra-http:5.7.0'

    implementation "ch.acra:acra-mail:5.7.0"


    /* for refresh  */
    implementation 'com.cjj.materialrefeshlayout:library:1.3.0'

    /* for expandable layout in group Info*/
    implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'

    implementation "org.java-websocket:Java-WebSocket:1.5.1"

    implementation 'com.squareup.picasso:picasso:2.5.2'

    /* library for crash reporting to file*/
    implementation 'com.balsikandar.android:crashreporter:1.1.0'

    api 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

    implementation 'com.github.zomato:androidphotofilters:1.0.2'

    /* for security of application */
    implementation 'com.github.framgia:android-emulator-detector:1.4.0'
    implementation 'com.github.mukeshsolanki:Android-Tamper-Detector:0.0.2'

    /* for selecting multiple files */
    implementation 'com.github.jaiselrahman:FilePicker:1.3.2'

    /* for CameraX*/
    implementation "androidx.camera:camera-camera2:1.0.0-rc04"
    implementation "androidx.camera:camera-lifecycle:1.0.0-rc04"
    implementation "androidx.camera:camera-view:1.0.0-alpha23"

    /* SSLPinning */
    implementation 'com.ibm.icu:icu4j:69.1'

}

this is the other one:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.4.32'

    repositories {
        google()
        jcenter()

        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}



allprojects {
    repositories {
        mavenCentral()
        google()
        jcenter()
        maven { url "https://maven.google.com" }
        maven { url "https://jitpack.io" }

    }
}

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

There are 1 answers

2
Oleg SH On

BiFunction from java.util.function package requires your project modules to be compatible with Java 8.

Try to upgrade your Gradle plugin to version 3.0.0 (or higher) and add Java 8 language feature support. Check the docs link:

If you have already did it, please share your Gradle configuration files.