Dagger + Proguard obfuscation, Errors creating object graph

前端 未结 2 914
梦毁少年i
梦毁少年i 2020-12-19 21:59

Running an obfuscated version of my application throws the following stacktrace

java.lang.RuntimeException: Unable to create service com.mycompany.myapp.asyn         


        
相关标签:
2条回答
  • 2020-12-19 22:45

    Dagger 1.x has issues with obfuscation. It can do code-shrinking with appropriate -keep statements, but obfuscation becomes problematic because of the use of String keys. The Strings are generated prior to proguarding, but consumed after proguarding, and do not line up with the newly-renamed types.

    Dagger 1.x (around 1.0.0) before we disabled reflective module adapters will work, as pure-reflection results in both provision and injection of a type to be considered "just in time" (i.e. after proguarding) so obfuscated types match up. If code-obfuscation is a higher priority than performance, do consider using this slightly older version.

    Dagger 2.x (in progress) is free of string keys, and results in direct class references, and should play very nicely with Proguard. Stay tuned to the dagger lists and project. We expect early versions of 2.x to drop within weeks of this posting.

    Also, and more specifically, make sure you -keepattributes Signature. The specific error you are seeing is because JDK5+ generics are being stripped by proguard. One never injects Lazy, one injects Lazy<Foo>. That will fix this specific error, though you will then have the problem mentioned above.

    0 讨论(0)
  • 2020-12-19 22:59

    I wasn't able to get Dagger 1.2 to work with ProGuard, and reading issue on Progruard github account I think I'm not alone - https://github.com/square/dagger/issues/202

    However, I've managed to get version 1.0.0 to work (without dagger-compiler!) with rules you mentioned above. Works fine in large Android apps, despite being quite old.

    0 讨论(0)
提交回复
热议问题