Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger 2 and android Studio: working but can't see generated classes

Tags:

I'm trying to use Dagger 2 in an Android Studio Project. I've used the CoffeeMaker example. I've managed to make the app build and working however: - I don't success in seeing the generated code. - If I debug, I can't see it neither. - Moreover DaggerCoffeeApp_Coffee as marked as reed (Cannot resolve symbol)

My gradle files are:

// Top-level build file where you can add configuration options common to all sub-projects/modules.  buildscript {     repositories {         jcenter()     }     dependencies {         classpath 'com.android.tools.build:gradle:1.1.3'          // NOTE: Do not place your application dependencies here; they belong         // in the individual module build.gradle files     } }  allprojects {     repositories {         jcenter()     } } 

and

apply plugin: 'com.android.application'   android {     compileSdkVersion 22     buildToolsVersion "21.1.2"      defaultConfig {         applicationId "com.mateuyabar.android.dagger2test"         minSdkVersion 22         targetSdkVersion 22         versionCode 1         versionName "1.0"     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     }     lintOptions {         abortOnError false // ignoring some references from dagger-compiler     } }  dependencies {     compile fileTree(dir: 'libs', include: ['*.jar'])     compile 'com.android.support:appcompat-v7:22.0.0'     compile 'javax.inject:javax.inject:1'     compile 'javax.annotation:javax.annotation-api:1.2'     compile 'com.google.dagger:dagger:2.0'     provided 'com.google.dagger:dagger-compiler:2.0'     provided 'org.glassfish:javax.annotation:10.0-b28'  } 

Thanks

like image 493
Mateu Avatar asked Apr 17 '15 15:04

Mateu


1 Answers

Use the Android-Apt plugin by Hugo Visser:

apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt'  buildscript {   repositories {     mavenCentral()   }    dependencies {     // the latest version of the android-apt plugin     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'   } }  android {     compileSdkVersion 22     buildToolsVersion "21.1.2"      defaultConfig {         applicationId "com.mateuyabar.android.dagger2test"         minSdkVersion 22         targetSdkVersion 22         versionCode 1         versionName "1.0"     }     buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     }     lintOptions {         abortOnError false // ignoring some references from dagger-compiler     } }  dependencies {     compile fileTree(dir: 'libs', include: ['*.jar'])     compile 'com.android.support:appcompat-v7:22.0.0'     compile 'javax.inject:javax.inject:1'     compile 'javax.annotation:javax.annotation-api:1.2'     compile 'com.google.dagger:dagger:2.0'     apt 'com.google.dagger:dagger-compiler:2.0'     provided 'org.glassfish:javax.annotation:10.0-b28' } 

Note the apt 'com.google.dagger:dagger-compiler:2.0' line as well. This should make the generated sources visible for AS.

like image 152
nhaarman Avatar answered Oct 21 '22 09:10

nhaarman