Reputation: 33
Recently I've started to play with Kotlin language and I try to run a very simple app. I have two files: MainActivity.kt and VersionSupport.kt with a few kotlin methods.
I don't have any problems with the app on Nexus 5 (a real device and emulator) with Android 5.x and 6.0. Problems begin when I try to run the app on 4.x versions of the OS.
In my MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.apply { text = "Hello kotlin!" }
supportsKitKat { longToast("kitKat") }
}
And here is the support methods implementation
public fun supportsKitKat(code: () -> Unit) {
supportsVersion(code, Build.VERSION_CODES.KITKAT)
}
private fun supportsVersion(code: () -> Unit, sdk: Int) {
if(Build.VERSION.SDK_INT >= sdk) {
code.invoke();
}
I use android studio 2.0 preview 3b and kotlin 1.0.0-beta-4583
FATAL EXCEPTION: main java.lang.VerifyError: pl/kpob/bootstrap/utils/VersionSupportKt
at pl.kpob.bootstrap.MainActivity.onCreate(MainActivity.kt:21)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Upvotes: 2
Views: 387
Reputation: 97288
Kotlin beta 4 is incompatible with Android Studio's Instant Run feature. You need to turn off Instant Run. The incompatibility will be resolved in the next update of Kotlin.
Upvotes: 3