• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    Java
  • Created about 12 years ago
  • Updated over 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ALL YOUR LIB ARE BELONG TO US

ALL YOUR LIB ARE BELONG TO US

Code Smell

Introduction

This project is a proof of concept to show how to integrate Dagger, Otto and AndroidAnnotations.

We can benefit from all those librairies to write Android apps that are both easy to maintain and lightning fast.

Here is what the result looks like:

@EActivity(R.layout.hello_activity)
public class HelloAndroidActivity extends BaseActivity {

	@Subscribe
	public void onUpdateTitle(UpdateTitleEvent event) {
		setTitle(event.title);
	}

}
@EFragment(R.layout.hello_fragment)
public class HelloFragment extends BaseFragment {

	@Inject
	Bus bus;

	@Click
	void fragmentButtonClicked() {
		bus.post(new UpdateTitleEvent("Button clicked"));
	}
}

This project contains only a few classes, go and read the source!

Building and running

Command line

Here is how to build this project from the command line.

  • First, make sure you have a device plugged in so that the integration tests can run.
  • Then you just need to run the following commands:
git clone [email protected]:pyricau/CleanAndroidCode.git
cd CleanAndroidCode
git submodule init
git submodule update
# We use a custom version of Otto, see below
cd otto
mvn clean install -DskipTests
cd ..
# Build, install on device and run the integration tests
mvn clean install

Eclipse

This project compiles and runs fine on Eclipse Juno. I have commited all the configuration files to make sure you do not spend time configuring it. You should be able to import everything "as maven projects".

I haven't tried with IntelliJ, but since everybody keeps telling me how good this IDE is, I assume everything will work perfectly fine :) .

Gotchas

Dagger & AndroidAnnotations

Dagger requires the definition of entry points on an @Module annotation. These entry points are our activities and fragments, created by the system.

When using both Dagger & AndroidAnnotations, one obvious configuration would be:

@Module(
  entryPoints = {
    HelloFragment_.class,
   	HelloAndroidActivity_.class,
  },
  complete = false
)
public class EntryPointsModule {
}

However, this cannot work directly when doing a full build. Even when you take care of the processor order so that you run AndroidAnnotations first and then Dagger, they run both in the same round, so the classes generated by AndroidAnnotations are not compiled yet when Dagger runs. The @Module annotation therefore references an unknown class.

This can be solved by having an extra annotation processor that generates this module at compile time. The module is picked up by Dagger on a second round, where the generated classes are compiled and therefore available.

This extra annotation processor is the cleanandroidcode-processor project.

Since this processor creates one class out of several annotations, it needs a caching mechanism to handle Eclipse incremental compiler.

Check out the DaggerAAIntegrationProcessor to learn more about this processor.

Otto & AndroidAnnotations

Unlike its Guava sister, Otto doesn't look for @Produce and @Subscribe annotations through the class hierarchy for performance reasons.

However, there is a custom version of Otto that replaces reflection with annotation processing and code generation. It is a proof of concept from Jake Wharton, available on this branch on the Square Otto repo.

Questions?

Any question? Create a new issue or ask @Piwai.

More Repositories

1

fragnums

An enum based library to replace fragments.
Java
578
star
2

frenchtoast

Stale Android Toasts made tasty.
Java
363
star
3

shipfaster

Dagger + Otto + Retrofit + Robolectric + Picasso + OkHttp
Java
328
star
4

androidsrc

Find Android sources
Ruby
173
star
5

SharkApp

Kotlin
42
star
6

diy

Kotlin
40
star
7

BuilderGen

Automatically generated builders
Java
31
star
8

pyricau.github.com

p-y.wtf static website
30
star
9

CatchLeaks

Bring your laptops and your investigative skills, we're going on a memory leak hunt!
Kotlin
29
star
10

dagger2-mortar-flow-experiment

Experimental hack to get Dagger 2, Mortar and Flow to work together
Java
26
star
11

FunkyJFunctional

A funky way to use functional programming in Java
Java
21
star
12

simpleperf-cleanup

Kotlin
18
star
13

androidannotations-dagger-example

An example of how to integrate AndroidAnnotations with Dagger. Experimental.
Java
16
star
14

toohardforyou

2H4U, which stands for Too Hard For You, is a mix between a Tetris-like game and a wall breaker.
Java
14
star
15

rockslide

Rockslide generates dynamic presentations
JavaScript
13
star
16

handler-thread-leaks

A simple projects that reproduces HandlerThread leaks
Kotlin
9
star
17

slides-formation-gwt

GWT Webapp based slides for the GWT training
Java
6
star
18

neveridle

Kotlin
5
star
19

TechTrekSummer2014

An app that consumes data from govtrack.us
Java
4
star
20

bisouland

Jeu par navigateur, volez des points d'amour ร  vos adversaires en leur envoyant des bisous !
PHP
4
star
21

waste-o-meter

Android application to compute the cost of waiting for your computer
Java
3
star
22

express-board-android

Repository for eXpress JobZ, an Android client for two french Job Boards
Java
3
star
23

FormationAndroid

Repo pour les TP de la formation Android
Java
3
star
24

DevoxxBeerCounter

App for AA talk at Devoxx 2012
Java
2
star
25

excilys-teaser-formation-gwt

Mini site pour les inscriptions ร  la formation GWT
2
star
26

cv-piwai

My online GWT Curriculum Vitae
Java
2
star
27

maven-forplay-archetype

A Maven archetype to quickly get started with ForPlay
Java
2
star
28

leakcanary-shell

An empty shell app to inject LeakCanary into other APKs
2
star
29

forplay-clone-pyricau

Clone to test forplay
Java
2
star
30

greenhouse-androidannotations

Porting greenhouse-android to AndroidAnnotations
Java
1
star
31

chromium-webview-leak

Repo that reproduces a Chromium Webview memory leak
Kotlin
1
star
32

androidannotations-scoping

A fake Android project that demonstrate how scoping would look like if implemented in AndroidAnnotations
Java
1
star
33

french-keyboard-putain

Type French in One Word
Java
1
star
34

fosdem-sms

Java
1
star
35

deRPC-big-payload

Sample demo GWT project to show how deRPC can generate big payloads
1
star
36

Formalys

App liรฉe ร  la gestion des formations Excilys
Java
1
star
37

BugAptEclipse

Reproduces a bug in Eclipse + APT
Java
1
star
38

slides-gwt-android-intro

Slides for a GWT & Android presentation at INSA Rouen
Java
1
star
39

speakerz

Java
1
star
40

maven-aa-apt-eclipse

Sample project using AA and annotation processing, trying to set everything right on Eclipse.
Java
1
star