Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Say Good-Bye to Kotlin Android Extensions

C65cdd77b9a94aeb6a7c5407dd6c39bf?s=47 okuzawats
November 29, 2020

Say Good-Bye to Kotlin Android Extensions

Kotlin Android Extensions compiler plugin is deprecate from Kotlin 1.4.20. In this slide, I explain how to say good-bye to Kotlin Android Extensions.

C65cdd77b9a94aeb6a7c5407dd6c39bf?s=128

okuzawats

November 29, 2020
Tweet

Transcript

  1. Say good-bye to Kotlin Android Extensions okuzawats YUMEMI.apk #2 2020/11/27

    1
  2. Who? - okuzawats - Twitter: okuzawats - GitHub: okuzawats -

    Android / Flutter()@ Fuller, Inc. 2
  3. Kotlin 1.4.20-M2 Deprecate Kotlin Android Extensions compiler plugin 3

  4. Kotlin Android Extensions views parcelize 4

  5. Kotlin Android Extensions views (dead) parcelize (dead) 5

  6. views “not recommended practice” 6

  7. 7 Alternatives - findViewById: traditional way - ViewBinding: can use

    existing layout - DataBinding: can bind variables in layout file
  8. 8 Alternatives - findViewById: traditional way - ViewBinding: can use

    existing layout - DataBinding: can bind variables in layout file
  9. 9 Enable ViewBinding android { buildFeatures { viewBinding true }

    }
  10. 10 Enable ViewBinding private var _binding: FragmentHomeBinding? = null private

    val binding get() = requireNotNull(_binding)
  11. 11 Enable ViewBinding override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?,

    savedInstanceState: Bundle? ): View? { _binding = FragmentHomeBinding.inflate(inflater, container, false) return binding.root }
  12. 12 Enable ViewBinding override fun onDestroyView() { _binding = null

    super.onDestroyView() }
  13. 13 Enable ViewBinding wada811 / ViewBinding-ktx https://github.com/wada811/ViewBinding-ktx private val binding:

    DataBindingFragmentBinding by dataBinding()
  14. 14 Disable Kotlin Android Extensions (views) android { // ...

    } androidExtensions { features = ["parcelize"] }
  15. 15 Kotlin Android Extensions (parcelize) plugins { id 'kotlin-parcelize' }

  16. 16 Kotlin Android Extensions (parcelize) import kotlinx.android.parcel.Parcelize to import kotlinx.parcelize.Parcelize

    When update Kotlin 1.4.20-M2
  17. Before: plugins { id 'kotlin-android-extensions' } After: plugins { }

    17
  18. Reference. • https://github.com/JetBrains/kotlin/releases /tag/v1.4.20-M2 • https://proandroiddev.com/migrating-the-de precated-kotlin-android-extensions-compiler- plugin-to-viewbinding-d234c691dec7 18