Как настроить ProGuard для сборки релиза Android с Kotlin - PullRequest
0 голосов
/ 29 октября 2018

Я добавил Kotlin 1.2.71 в свой проект приложения для Android (Java). Проект настроен для Java 8:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Вот изменения Kotlin:

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71"

...

apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"

...

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.71"
kapt "org.parceler:parceler:1.1.11"

Я заметил, что сборка релиза с ProGuard не удалась. Процесс сборки выводит следующую информацию:

Warning: kotlin.internal.jdk8.JDK8PlatformImplementations: can't find referenced 
    method 'int start(java.lang.String)' in library class java.util.regex.Matcher
Warning: kotlin.internal.jdk8.JDK8PlatformImplementations: can't find referenced 
    method 'int end(java.lang.String)' in library class java.util.regex.Matcher
Warning: kotlin.internal.jdk8.JDK8PlatformImplementations: can't find referenced 
    method 'java.lang.String group(java.lang.String)' in library class java.util.regex.Matcher

Note: kotlin.internal.PlatformImplementationsKt: can't find dynamically 
    referenced class kotlin.internal.JRE8PlatformImplementations
Note: kotlin.internal.PlatformImplementationsKt: can't find dynamically 
    referenced class kotlin.internal.JRE7PlatformImplementations
Note: kotlin.jvm.internal.Reflection: can't find dynamically 
    referenced class kotlin.reflect.jvm.internal.ReflectionFactoryImpl

Note: the configuration keeps the entry point 
    'com.google.android.gms.flags.impl.FlagProviderImpl { void init(com.google.android.gms.dynamic.zzd); }', 
    but not the descriptor class 'com.google.android.gms.dynamic.zzd'

Note: there were 1 unkept descriptor classes in kept class members.
      You should consider explicitly keeping the mentioned classes
      (using '-keep').
      (http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
Note: there were 3 unresolved dynamic references to classes or interfaces.
      You should check if you need to specify additional program jars.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Warning: there were 3 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
Thread(Tasks limiter_9): destruction

Насколько мне известно, Kotlin не требует каких-либо специальных правил ProGuard. Люди рекомендуют (сообщение от 2015 года) просто изложить правила:

-dontwarn kotlin.**

Это все еще рекомендуемое решение?

Относящиеся

1 Ответ

0 голосов
/ 29 октября 2018

Просмотр фактических предупреждений показывает, что он не может найти конкретные методы в стандартной библиотеке Java.

Ссылка Matcher.end(String) показывает, что этот метод доступен, только если ваш minSdk равен 26. Это был уровень SDK, когда была добавлена ​​поддержка Java-8.

Проще говоря, вы пытаетесь использовать библиотеку kotlin уровня java8 с android sdk, который ее не поддерживает, что приводит к ошибкам, которые вы наблюдаете.

...