一直以为keep就是不要混淆,近期发现还有另外一个作用,见官方文档:
Testing your app should reveal any errors caused by inappropriately removed code, but you can also inspect what code was removed by generating a report of removed code.
To fix errors and force R8 to keep certain code, add a -keep line in the ProGuard rules file. For example:
-keep public class MyClass
Alternatively, you can add the @Keep annotation to the code you want to keep. Adding @Keep on a class keeps the entire class as-is. Adding it on a method or field will keep the method/field (and its name) as well as the class name intact. Note that this annotation is available only when using the AndroidX Annotations Library and when you include the ProGuard rules file that is packaged with the Android Gradle plugin, as described in the section about how to enable shrinking.
仔细读会发现keep作用是不被任何优化,除了混淆还有删除,因为ProGuard的过程中会清理没有使用的类或方法等代码,设置keep后,这部分就不会被作任何优化,包括被清理