Android Bootstrap + Dagger + ButterKnife

1,831 views
Skip to first unread message

Donn Felker

unread,
Mar 18, 2013, 2:40:12 PM3/18/13
to android-...@googlegroups.com
I have created a new branch of Android Bootstrap which will soon replace the mainline branch of development. See the branch here: https://github.com/donnfelker/android-bootstrap/tree/dagger-wip

This new branch uses Daggger for traditional IoC, ButterKnife for View Injection. Thus far this is one of the few full working examples of how to use Dagger with Android. If you see something that needs to be fixed, changed, updated please log an issue or better yet (10x better) send a pull request. :) 

The reason for the move from RoboGuice is that with Dagger we are not required to extend a super class per activity or fragment (sure you can do this in RoboGuice, but its a little more work) and Dagger is a bit faster than RoboGuice. This does require some boiler plate code (2 lines of code for dagger and butterknife), but if you put that into your own super class you have much more freedom, in my opinion. Example - Want to use SlidingMenu? No problem. Now you have Sliding Menu and IoC all in one. BAM!

I have created a branch to maintain the RoboGuice version off of master and as soon as I move the dagger-wip branch into master, the RoboGuice version will only exist in this topic branch. 

Questions and comments are welcome.  Cheers, 

Donn

Prateek Srivastava

unread,
Mar 27, 2013, 1:19:02 AM3/27/13
to android-...@googlegroups.com
Awesome update! Question about the injection; is there a reason why it's done differently in https://github.com/donnfelker/android-bootstrap/blob/master/app/src/main/java/com/donnfelker/android/bootstrap/ui/BootstrapActivity.java nad https://github.com/donnfelker/android-bootstrap/blob/master/app/src/main/java/com/donnfelker/android/bootstrap/ui/BootstrapFragmentActivity.java ?

Specifically the line 'BootstrapApplication.getInstance().inject(this);' BootstrapFragmentActivity has it in onCreate, BootstrapActivity has it in setContentView.

Neal Sanche

unread,
Apr 11, 2013, 11:31:01 AM4/11/13
to android-...@googlegroups.com
Any advice on how to build and run this in IntelliJ? I have found the only way to get a working app now is to use maven from the command-line or build using maven targets in the IDE. Anything the IDE builds crashes out because it can't find the generated sources from the Android Annotations.

Thanks.

Neal


On Monday, March 18, 2013 12:40:12 PM UTC-6, Donn Felker wrote:

Donn Felker

unread,
Apr 11, 2013, 12:39:59 PM4/11/13
to android-...@googlegroups.com
I think this is a bug I need to fix (the way injection is done). Should be done in the onCreate. Whoops.


Donn Felker
Author of Android App Dev for Dummies
http://blog.donnfelker.com
http://twitter.com/donnfelker


--
You received this message because you are subscribed to the Google Groups "Android Bootstrap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-bootst...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Donn Felker

unread,
Apr 11, 2013, 12:42:32 PM4/11/13
to android-...@googlegroups.com
@Neal - Try this: 

  • Delete the gen-external-apklibs
  • Invalidate IntelliJ caches and restart
  • After restart IntelliJ will be doing a bunch of indexing, apklib generating, etc. Let it run. 
  • Eventually you'll see an IDE error (probably) asking if you want to delete a bunch of .IML files. REMOVE them. 
  • Then refresh the maven dependencies via the maven window. 

Thats what has fixed it for my team. Pain? YES. But once its working, its golden. 

I know, not the perfect scenario. But it works. 


Donn Felker
Author of Android App Dev for Dummies
http://blog.donnfelker.com
http://twitter.com/donnfelker


On Thu, Apr 11, 2013 at 8:31 AM, Neal Sanche <thori...@gmail.com> wrote:

--

Rennie Petersen

unread,
Sep 24, 2013, 7:42:23 AM9/24/13
to android-...@googlegroups.com
I'm guessing that this is now part of the master branch, isn't it?

It's just that this thread is pinned at the top of the forum, but it doesn't mention that it is no longer off on a branch.

Donn Felker

unread,
Sep 24, 2013, 10:44:14 AM9/24/13
to android-...@googlegroups.com

Correct. Its on master. I updated the readme and website and forgot the forum. Thanks for reminding me.

--
Reply all
Reply to author
Forward
0 new messages