android - Injected views are null with RG 3.0 -
android - Injected views are null with RG 3.0 -
i using roboguice 3.0 in android studio straight since need back upwards actionbaractivity. dep:
compile 'org.roboguice:roboguice:3.0'
first odd thing had resolve classnotfoundexception "unable utilize annotation database(s)". seems if there's no annotation bundle given, packagelist prepended empty string , di framework complains not find annotationdatabaseimpl @ root bundle (which expected). did in manifest:
<meta-data android:name="roboguice.annotations.packages" android:value="roboguice"/>
which resolved issue. then, changed code this:
@contentview(r.layout.activity_playlists) public class playlists extends roboactionbaractivity { @injectview(r.id.toolbar) toolbar toolbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setsupportactionbar(toolbar); } }
setsupportactionbar() throws npe. stepped through debugger , viewmembersinjectors map empty when views beingness injected. thinking odd prepare had , related. somehow injectview fellow member not discovered. @contentview injection works (if remove content changed callback never called).
does know how prepare this?
one solution custom class extends application.class disable annotation database usage.
public class customapplication extends application { public void oncreate() { super.oncreate(); roboguice.setuseannotationdatabases(false); } }
another way create enviroment variable named roboguice.useannotationdatabases
it's value set false since rg3 seems check value.
this allow utilize roboguice before, though lose performance gains utilize of annotation database usage.
update
generating annotation database should prepare npe , add together performance gains application. first have include next dependency in build.gradle
.
depencencies { ... provided 'org.roboguice:roboblender:3.0' }
you should add together following:
allprojects { gradle.projectsevaluated { tasks.withtype(javacompile) { options.compilerargs << "-aguiceannotationdatabasepackagename=databasename" } } }
to database working should add together databasename in meta-data value in androidmanifest.xml
.
<meta-data android:name="roboguice.annotations.packages" android:value="roboguice,databasename"/>
android roboguice
Comments
Post a Comment