I want to change the targetSdkVersion my Android project from 25 to 27. The problem is that I used Kotlin, but there are some big changes:

1) changed the signature View.findViewById() . Now I need to use findViewById<View>

2) the getContext() fragment has become not null safety, so I need to add !! to all context values ​​in all fragments.

Is there a way to fix this automatically for the whole project? This is not a small project, and it will take a long time to complete these fixes manually.

  • 1) not always. if you have an explicit View type, then it is not necessary to pass it. - Flippy

1 answer 1

  1. Instead of View.findViewById() you can use the Kotlin Android Extensions: https://kotlinlang.org/docs/tutorials/android-plugin.html (which is much more convenient)
  2. And to get the context in the fragment, you can refer to the variable activity . For example: startActivity(Intent(activity, SomeActivity::class.java))

    Well, you need to fix everything manually (at least I don’t know a quick way). Is that in the Android Studio Find and replace Ctrl + Shift + R.