Предупреждение в синтезированном для удаления лямбды — перехода с ThreeTenABP на java.time

#java #android

#java #Android

Вопрос:

Недавно мы включили удаление Java8, чтобы перенести https://github.com/JakeWharton/ThreeTenABP чтобы java.time


build.gradle

 defaultConfig {
    minSdkVersion 16
    targetSdkVersion 29
    multiDexEnabled true

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

    targetCompatibility 1.8
    sourceCompatibility 1.8
}

dependencies {    
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
  

Проблемы с компиляцией нет. Однако, когда мы попытаемся запустить приложение в API эмулятора 18, мы получим следующее предупреждение.

 > Transform artifact desugar_jdk_libs_configuration-1.0.10.jar (com.android.tools:desugar_jdk_libs_configuration:1.0.10) with L8DexDesugarLibTransform
Warning: Type `j$.util.OptionalDouble` was not found, it is required for default or static interface methods desugaring of `j$.util.OptionalDouble j$.util.OptionalConversions.convert(java.util.OptionalDouble)`
Warning: Type `j$.util.OptionalLong` was not found, it is required for default or static interface methods desugaring of `j$.util.OptionalLong j$.util.OptionalConversions.convert(java.util.OptionalLong)`
Warning: Type `j$.util.OptionalInt` was not found, it is required for default or static interface methods desugaring of `j$.util.OptionalInt j$.util.OptionalConversions.convert(java.util.OptionalInt)`
Warning: Type `j$.time.ZonedDateTime` was not found, it is required for default or static interface methods desugaring of `j$.time.ZonedDateTime j$.time.TimeConversions.convert(java.time.ZonedDateTime)`
Warning: Type `j$.time.ZoneId` was not found, it is required for default or static interface methods desugaring of `j$.time.ZoneId j$.time.TimeConversions.convert(java.time.ZoneId)`
Warning: Type `j$.time.MonthDay` was not found, it is required for default or static interface methods desugaring of `j$.time.MonthDay j$.time.TimeConversions.convert(java.time.MonthDay)`
Warning: Type `j$.time.Instant` was not found, it is required for default or static interface methods desugaring of `j$.time.Instant j$.time.TimeConversions.convert(java.time.Instant)`
Warning: Type `j$.time.LocalDate` was not found, it is required for default or static interface methods desugaring of `j$.time.LocalDate j$.time.TimeConversions.convert(java.time.LocalDate)`
Warning: Type `j$.time.Duration` was not found, it is required for default or static interface methods desugaring of `j$.time.Duration j$.time.TimeConversions.convert(java.time.Duration)`
Warning: Type `j$.util.DesugarGregorianCalendar` was not found, it is required for default or static interface methods desugaring of `j$.time.ZonedDateTime j$.$r8$backportedMethods$utility$GregorianCalendar$toZonedDateTime$dispatchHolder.toZonedDateTime(java.util.GregorianCalendar)`
Warning: Type `j$.util.DesugarDate` was not found, it is required for default or static interface methods desugaring of `j$.time.Instant j$.$r8$backportedMethods$utility$Date$toInstant$dispatchHolder.toInstant(java.util.Date)`

> Transform artifact desugar_jdk_libs-1.0.10.jar (com.android.tools:desugar_jdk_libs:1.0.10) with L8DexDesugarLibTransform
Warning in synthesized for lambda desugaring:
  Type `j$.$r8$wrapper$java$util$function$ToDoubleFunction$-V-WRP` was not found, it is required for default or static interface methods desugaring of `java.util.Comparator java.time.chrono.-$$Lambda$AbstractChronology$5b0W7uLeaWkn0HLPDKwPXzJ7HPo.thenComparingDouble($-vivified-$.java.util.function.ToDoubleFunction)`
Warning in synthesized for lambda desugaring:
  Type `j$.$r8$wrapper$java$util$function$Function$-V-WRP` was not found, it is required for default or static interface methods desugaring of `java.util.Comparator java.time.chrono.-$$Lambda$AbstractChronology$5b0W7uLeaWkn0HLPDKwPXzJ7HPo.thenComparing($-vivified-$.java.util.function.Function)`
Warning in synthesized for lambda desugaring:
  Type `j$.$r8$wrapper$java$util$function$ToIntFunction$-V-WRP` was not found, it is required for default or static interface methods desugaring of `java.util.Comparator java.time.chrono.-$$Lambda$AbstractChronology$5b0W7uLeaWkn0HLPDKwPXzJ7HPo.thenComparingInt($-vivified-$.java.util.function.ToIntFunction)`
Warning in synthesized for lambda desugaring:
  Type `j$.$r8$wrapper$java$util$function$ToLongFunction$-V-WRP` was not found, it is required for default or static interface methods desugaring of `java.util.Comparator java.time.chrono.-$$Lambda$AbstractChronology$5b0W7uLeaWkn0HLPDKwPXzJ7HPo.thenComparingLong($-vivified-$.java.util.function.ToLongFunction)`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/stream/Collectors$Partition$1.class:
  Type `j$.$r8$wrapper$java$util$Spliterator$-WRP` was not found, it is required for default or static interface methods desugaring of `$-vivified-$.java.util.Spliterator java.util.stream.Collectors$Partition$1.spliterator()`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/stream/Collectors$Partition$1.class:
  Type `j$.$r8$wrapper$java$util$function$Consumer$-V-WRP` was not found, it is required for default or static interface methods desugaring of `void java.util.stream.Collectors$Partition$1.forEach($-vivified-$.java.util.function.Consumer)`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/stream/Collectors$Partition$1.class:
  Type `j$.$r8$wrapper$java$util$stream$Stream$-WRP` was not found, it is required for default or static interface methods desugaring of `$-vivified-$.java.util.stream.Stream java.util.stream.Collectors$Partition$1.parallelStream()`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/stream/Collectors$Partition$1.class:
  Type `j$.$r8$wrapper$java$util$function$Predicate$-V-WRP` was not found, it is required for default or static interface methods desugaring of `boolean java.util.stream.Collectors$Partition$1.removeIf($-vivified-$.java.util.function.Predicate)`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/stream/Collectors$Partition$1.class:
  Type `j$.$r8$wrapper$java$util$function$IntFunction$-V-WRP` was not found, it is required for default or static interface methods desugaring of `java.lang.Object[] java.util.stream.Collectors$Partition$1.toArray($-vivified-$.java.util.function.IntFunction)`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/DesugarCollections$SynchronizedMap.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 `void java.util.DesugarCollections$SynchronizedMap.replaceAll($-vivified-$.java.util.function.BiFunction)`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/DesugarCollections$SynchronizedMap.class:
  Type `j$.$r8$wrapper$java$util$function$BiConsumer$-V-WRP` was not found, it is required for default or static interface methods desugaring of `void java.util.DesugarCollections$SynchronizedMap.forEach($-vivified-$.java.util.function.BiConsumer)`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/concurrent/ThreadLocalRandom.class:
  Type `j$.$r8$wrapper$java$util$stream$IntStream$-WRP` was not found, it is required for default or static interface methods desugaring of `$-vivified-$.java.util.stream.IntStream java.util.concurrent.ThreadLocalRandom.ints()`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/concurrent/ThreadLocalRandom.class:
  Type `j$.$r8$wrapper$java$util$stream$LongStream$-WRP` was not found, it is required for default or static interface methods desugaring of `$-vivified-$.java.util.stream.LongStream java.util.concurrent.ThreadLocalRandom.longs()`
Warning in C:Usersyccheok.gradlecachesmodules-2files-2.1com.android.toolsdesugar_jdk_libs1.0.1061bd346a9d026c92028eb8c8c29e09368b22633cdesugar_jdk_libs-1.0.10.jar:java/util/concurrent/ThreadLocalRandom.class:
  Type `j$.$r8$wrapper$java$util$stream$DoubleStream$-WRP` was not found, it is required for default or static interface methods desugaring of `$-vivified-$.java.util.stream.DoubleStream java.util.concurrent.ThreadLocalRandom.doubles(long)`
Warning: Type `j$.util.OptionalConversions` was not found, it is required for default or static interface methods desugaring of `java.util.OptionalLong j$.$r8$wrapper$java$util$stream$LongStream$-WRP.reduce(java.util.function.LongBinaryOperator)`
Warning: Type `j$.util.LongSummaryStatisticsConversions` was not found, it is required for default or static interface methods desugaring of `java.util.LongSummaryStatistics j$.$r8$wrapper$java$util$stream$LongStream$-WRP.summaryStatistics()`
Warning: Type `j$.util.DoubleSummaryStatisticsConversions` was not found, it is required for default or static interface methods desugaring of `java.util.DoubleSummaryStatistics j$.$r8$wrapper$java$util$stream$DoubleStream$-WRP.summaryStatistics()`

> Task :app:processDebugResources

> Transform artifact desugar_jdk_libs-1.0.10.jar (com.android.tools:desugar_jdk_libs:1.0.10) with L8DexDesugarLibTransform
Warning: Type `j$.util.IntSummaryStatisticsConversions` was not found, it is required for default or static interface methods desugaring of `java.util.IntSummaryStatistics j$.$r8$wrapper$java$util$stream$IntStream$-WRP.summaryStatistics()`
  

и мы получим следующую ошибку времени выполнения.

 10-29 15:48:43.167 3959-3959/? E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: androidx.arch.core.internal.SafeIterableMap
        at androidx.lifecycle.LiveData.<init>(LiveData.java:66)
        at androidx.lifecycle.MutableLiveData.<init>(MutableLiveData.java:40)
        at com.yocto.wenote.SingleLiveEvent.<init>(SingleLiveEvent.java:38)
        at com.yocto.wenote.WeNoteApplication.<init>(WeNoteApplication.java:94)
        at java.lang.Class.newInstanceImpl(Native Method)
  

строка WeNoteApplication.java:94

 private final SingleLiveEvent<Boolean> onResumePasswordPromptSingleLiveEvent = new SingleLiveEvent<>();
  

что меня смущает и не имеет смысла. Поскольку мы не уверены, как влияет SingleLiveEvent десугаринг Java8 (унаследованный от MutableLiveData )

У вас есть идеи, как мы можем это устранить?

Ответ №1:

Для десугаринга Java 8 требуется включить MultiDex. Начиная с API 21, MultiDex поддерживается по умолчанию без использования библиотеки поддержки MultiDex.

Для правильной поддержки MultiDex в API <21 вам необходимо обновить свой Application класс:

 override fun attachBaseContext(base: Context?) {
    super.attachBaseContext(base)
    MultiDex.install(this)
}
  

Если вы этого не сделаете, классы, которые не находятся внутри первого файла dex, не будут найдены на этих устройствах.