1

I added Kotlin 1.2.71 to my Android (Java) application project. The project is configured for Java 8:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Here are the Kotlin changes:

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"

I noticed that the release build with ProGuard fails. The build process outputs the following information:

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 does not require any special ProGuard rules as far as I saw. People recommend (post from 2015) to put just simply rules:

-dontwarn kotlin.**

Is this still the recommended solution?

Related

JJD
  • 50,076
  • 60
  • 203
  • 339
  • 1
    not sure using `kotlin-stdlib-jdk8` is a good idea on android since full support for jdk8 classes isn't available unless you use `minSdkVersion 24`, see https://developer.android.com/studio/write/java8-support - your error look like that could be the issue. Try `kotlin-stdlib-jdk7` – zapl Oct 29 '18 at 20:52
  • That should not be an issue as I also use `compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }` in my `build.gradle` configuration. – JJD Oct 29 '18 at 20:54
  • 1
    That is something different. The android build uses a tool to convert java 8 syntax / class files to java7 or lower (android) dex files. See link above what's available on which api level. The tool can't emulate methods that didn't exist in that api level. It can emulate lambdas for example. – zapl Oct 29 '18 at 20:56
  • Sorry for my pride. Using `kotlin-stdlib-jdk7` actually lets the release build succeed. Thank you! – JJD Oct 29 '18 at 21:02

1 Answers1

3

Looking at the actual warnings tells you it cannot find specific methods in the java standard library.

Referencing Matcher.end(String) shows that it is a method that is only available if your minSdk is 26. This was the SDK level when Java-8 support was added.

Simply put, you're trying to use the java8-level kotlin library with an android sdk that does not support it, leading to the errors you're observing.

Kiskae
  • 24,655
  • 2
  • 77
  • 74