android - Dagger cannot create object graph although it can produce dot file -
i'm struggling setup of dagger (1.0.1), in existing application. configured use proguard disabled test -dontobfuscate
.
when enable dagger-compiler it's able generate dot file dependencies graph, when remove compiler , build app in release mode crashes during startup, complaining it's unable create object graph.
java.lang.runtimeexception: unable start activity componentinfo{com.corp.myapp/com.corp.myapp.ui.activity.mainactivity}: java.lang.illegalstateexception: errors creating object graph: no injectable members on com.corp.myapp.core.services.connectionmonitor. want add injectable constructor? required com.corp.myapp.core.services.connectionmonitor com.corp.myapp.ui.activity.myappbaseactivity.connectionmanager no injectable members on com.corp.myapp.ui.crouton.croutonmanager. want add injectable constructor? required com.corp.myapp.ui.crouton.croutonmanager com.corp.myapp.ui.activity.myappbaseactivity.croutonmanager no injectable members on com.corp.core.assembler.resourceassembler. want add injectable constructor? required com.corp.core.assembler.resourceassembler com.corp.myapp.ui.activity.myappbaseactivity.resourceassembler
i see myappbaseactivity
, it's dependencies croutonmanager
or connectionmonitor
being displayed in generated dot file, according this comment expected work. afaik if there wrong should detected compiler-enabled build used generate dot file.
update:
i stated
in debug mode never fails
but it's not true after further testing: in debug mode doesn't fail because proguard disabled, whereas in release mode enabled default. if build app in release mode skip proguard, don't errors either , app starts. problem related proguard configuration.
dagger relies lot on reflection , class names hard-coded , manipulated strings. makes code difficult shrink/optimize/obfuscate.
the following configuration works sample dagger/examples/simple in dagger 1.1.0:
-keepattributes *annotation* -keepclassmembers,allowobfuscation class * { @javax.inject.* *; @dagger.* *; <init>(); } -keep class **$$moduleadapter -keep class **$$injectadapter -keep class **$$staticinjection -keepnames !abstract class coffee.* -keepnames class dagger.lazy
the configuration keeps fields , methods javax.inject
or dagger
annotations, , parameterless constructors. proguard might otherwise remove them if appear unused, dagger injecting/accessing them through reflection. similar roboguice.
it has keep adapter classes generated dagger.
it has keep class names related these adapter classes, names still match. in sample, classes in package coffee
, easiest way use wild-card. line different other applications.
finally, has keep name of class dagger.lazy
, since name hard-coded string in generated code.
Comments
Post a Comment