toothpick icon indicating copy to clipboard operation
toothpick copied to clipboard

@Qualifier annotations and proguard rules

Open horseunnamed opened this issue 4 years ago • 1 comments

Hi. I noticed that proguard rules at TP wiki don't cover situations when we use injections with qualifiers.

For example, I have

@Qualifier
annotation class MyQualifier

And class with such constructor

class Foo @Inject constructor(@MyQualifier bar: String)

Toothpick generates Foo__Factory with code that tries to get instance of qualified argument with full classname of MyQualifier before obfuscation.

String param1 = scope.getInstance(String.class, "com.example.MyQualifier");

But in runtime it will be bound with full classname after obfuscation and that causes crash. I tried proguard rules from TP Wiki with R8 to reproduce this case.

This proguard rule helped me to avoid crash:

-keep @javax.inject.Qualifier @interface *

Should it be added to wiki or am I missing something?

horseunnamed avatar May 27 '20 11:05 horseunnamed

Hi @horseunnamed

It looks like our rules on the wiki and inside smoothie might not cover that use case. Taking into account that you already found the solution, do you wanna contribute by updating:

  1. https://github.com/stephanenicolas/toothpick/blob/master/smoothie/proguard-rules.txt
  2. Wiki: https://github.com/stephanenicolas/toothpick/wiki/Proguard-&-TP

Thx for the issue!

btw, sorry for the delay

dlemures avatar Jun 12 '20 23:06 dlemures