Turn off code generation for kotlin android extensions


#1

Is there any way to remove the generated code for kotlin android extensions?

I don’t find the finding view by id functionality useful and would like to know if I can somehow remove it from being generated in the bytecode. For some reason, it bothers me that it is there and I am curious to know if this is achievable.

Thanks in advance. Cheers.


#2

Generating that code is the only functionality provided by the Kotlin Android extensions. If you don’t need that functionality, you can remove the apply plugin: 'kotlin-android-extensions' line from your build.gradle.


#3

Thank you, I understand that logic. The thing is, I didn’t have that line in my build.gradle in the first place. You can check with a new project and an empty activity class.

Anything new on this issue? I guess that that code should only be generated if kotlin-android-extensions plugin is applied, which is not in my case.


#4

i have the same issue


#5

If you don’t have the apply plugin: 'kotlin-android-extensions' line in your build.gradle file, Android Extensions simply does not generate any code for you.
By the way, why do you think code is generated?


#6

Can you please do me a favour and open a new, blank android project. Setup the kotlin gradle plugin and convert MainActivity to kotlin code. Make sure kotlin-android-extensions is not enabled or part of the build.gradle files. Now please, click on the Tools menu, then Kotlin and click show Kotlin bytecode. Here, I am seeing the code generated by kotlin-android-extensions, even though it is not applied to my project.

Can you see the same code? Cheers.


#7

The “Show Kotlin bytecode” action shows the bytecode generated by the compiler running inside the IDE, not by the Gradle build. If you want to check the bytecode generated by the Gradle build, you need to run javap on the .class files in your build output directory.


#8

I get that. Why does it then show the findViewById and caching functions? Can you please do me a favour and go through the steps mentioned and see if you can replicate my experience?


#9

For now Android Extensions plugin is always enabled in IDE.
We will include a project-level checkbox in further releases of Kotlin.


#10

Finally a reasonable explanation. Thank You Sir for clearing this up.