Closed AndroidDeveloperLB closed 8 years ago
it does not affect app performance at all as it generates the code at compile time instead of scanning classes and doing reflection work at runtime (which is slow)
proguard rules are needed to avoid generated classes obfuscation, not for protection. If you do not use proguard in your app - you have nothing to tweak.
Excellent answer @livotov 👍
Cool. But if it's auto-generated, why do I need to add functions, instead of just the annotations?
In "Activity", for example, why do I have to call Icepick.restoreInstanceState(this, savedInstanceState); and Icepick.saveInstanceState(this, outState); ?
Can't it auto-generate this code, by checking if there is an implementation of "onCreate" and "onSaveInstanceState" , and add the code accordingly?
Is it possible?
@AndroidDeveloperLB Those functions are used to link the generated code to the hand written one. Note that icepick is not adding code to classes that you've written: it's generating entirely new classes. To do what you propose you'd need to perform bytecode injection which is way over the top for a simple use case like this.
So auto-generating classes is easier than adding code to existing ones? I wonder then, does Google inject code in any of its libraries ?
@AndroidDeveloperLB Annotation processing api does not allow to preprocess and modify the existing source code (one you wrote in IDE), it only allows to generate new standalone classes. That's why you have to put a bit of manual work like Icepick.saveInstanceState(...)
So I see. Does Google inject code ?
Ask Google
haha I was just curious.
I ask this because on the one hand, you wrote " It uses annotation processing to generate code that does bundle manipulation and key generation" , yet on the other hand, you wrote it needs proguard rules. If it creates the code while building, why does it need protection of code?
How does it work?