This page looks best with JavaScript enabled

Hunting Kotlin Synthetics For Views

 ·  โ˜• 2 min read  ·  โœ๏ธ Nishant
Hunting Kotlin Synthetics For Views

Kotlin Synthetics for Views is deprecated! You can read about it here.

That means if you have been using them in your project then you need to replace them with a more recommended approach i.e ViewBindings. There is a migration guide too.

But before you can start the migration you need to track down the files where Kotlin Synthetics are being used. Lets find out.

Run the below command at the root of your project in a terminal window:

1
grep -rwl . -e 'kotlinx.android.synthetic'

here

  • -r = Recursive
  • -w = Match the whole word
  • -l = Output the file name of matching files
  • -e = Match pattern used during the search

On executing the above command, the output is like below:

1
2
โฏ grep -rwl . -e 'kotlinx.android.synthetic'
./UsingKotlin/app/src/main/java/nisrulz/github/sample/usingkotlin/MainActivity.

Incase you are only interested in finding out the number of files where Kotlin Synthetics are being used, run the below command:

1
grep -rwl . -e 'kotlinx.android.synthetic' | wc -l

On executing the above command, the output is like below:

1
2
โฏ grep -rwl . -e 'kotlinx.android.synthetic' | wc -l
       1

That is all! Once you have found the places in your codebase where Kotlin Synthetics have been used, simply replace them with ViewBinding one by one. You could also completely switch to Jetpack Compose, if you want to switch to the next generation of UI development framework on Android.

Share on
Support the author with

Nishant Srivastava
WRITTEN BY
Nishant
๐Ÿ‘จโ€๐Ÿ’ป Android Engineer/๐Ÿงข Opensource enthusiast

What's on this Page