android / android-ktx

A set of Kotlin extensions for Android app development.
https://android.github.io/android-ktx/core-ktx/
7.48k stars 565 forks source link

androidx.core.os.BundleKt.bundleOf: Imports for API 21 classes break on older devices #592

Closed tellypresence closed 5 years ago

tellypresence commented 6 years ago

Suspect that import statements for Size/SizeF (added in API 21) in https://github.com/android/android-ktx/blob/master/src/main/java/androidx/core/os/Bundle.kt are causing problems for older devices; get errors on e.g. Samsung Galaxy 4 (API 19/kitkat 4.4.2):

E/dalvikvm: Could not find class 'android.util.Size', referenced from method androidx.core.os.BundleKt.bundleOf
E/dalvikvm: Could not find class 'android.util.SizeF', referenced from method androidx.core.os.BundleKt.bundleOf

Maybe replace the imports with fully qualified paths e.g. Before

import android.util.Size
...
} else if (Build.VERSION.SDK_INT >= 21 && value is Size)

After

//import android.util.Size
...
} else if (Build.VERSION.SDK_INT >= 21 && value is android.util.Size)
JakeWharton commented 6 years ago

Imports have no effect on the bytecode, they're only a construct of source code. Are you just seeing log messages or experiencing an actual crash?

stevesamknows commented 6 years ago

After some refactoring and improvements in app code, would say those logs are safe to ignore; don't think they're causing any actual problems.