我将Kotlin 1.2.71添加到了我的Android(Java)应用程序项目中。 该项目已针对Java 8配置:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
以下是科特林的变化:
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规则。 People recommend(从2015年开始发布),只需简单地制定规则即可:
-dontwarn kotlin.**
这仍然是推荐的解决方案吗?
答案 0 :(得分:3)
查看实际警告会告诉您在Java标准库中找不到特定的方法。
引用Matcher.end(String)
表明该方法仅在您的minSdk为26
时可用。添加Java-8支持后,这就是SDK级别。
简而言之,您正在尝试将Java8级kotlin库与不支持它的android sdk结合使用,从而导致您观察到错误。