Android studio 2.2 how to apply dagger2 without android-apt-plugin

my build.gradle project

buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0-alpha3' classpath 'com.google.dagger:dagger-compiler:2.2' classpath 'com.google.guava:guava:19.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } 

my build.gradle module

 android { compileSdkVersion 24 buildToolsVersion '24.0.0' defaultConfig { applicationId "com.aber.app.acgtalk" minSdkVersion 19 targetSdkVersion 24 versionCode 1 versionName "1.0" jackOptions { enabled true } } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } ext { supportLibVersion = '24.0.0' } dependencies { compile 'com.google.dagger:dagger:2.2' annotationProcessor 'com.google.dagger:dagger-compiler:2.2' debugAnnotationProcessor 'com.google.dagger:dagger-compiler:2.2' provided 'javax.annotation:jsr250-api:1.0' compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile "com.android.support:appcompat-v7:${supportLibVersion}"; compile "com.android.support:recyclerview-v7:${supportLibVersion}"; compile "com.android.support:design:${supportLibVersion}"; compile "com.android.support:support-v13:${supportLibVersion}"; compile "com.android.support:support-annotations:${supportLibVersion}"; compile "com.android.support:gridlayout-v7:${supportLibVersion}"; compile "com.android.support:cardview-v7:${supportLibVersion}"; compile "com.android.support:preference-v14:${supportLibVersion}"; compile 'com.squareup.okhttp3:okhttp:3.2.0'; compile 'com.google.code.gson:gson:2.6.2' compile 'com.squareup.retrofit2:retrofit:2.0.2' compile 'com.squareup.retrofit2:converter-gson:2.0.2' } 

What's wrong with this, how to use the annotationProcessor function in Android 2.2 studio, how to properly handle the dagger2 annotation processor?

new annotation processors Jack

+7
android android-studio
source share
2 answers

Yes, with the release of plugin 2.2.0 from android gradle, the android-apt plugin is no longer needed to process annotations. The apt function was included in the latest Android gradle plugin. He called annotationProcessor now what you had in your build script. However, the script had a few misconfigured elements.

First of all, the dagger compiler should not be added to the classpath. So delete this line: classpath 'com.google.dagger:dagger-compiler:2.2' .

And you are using the Android version of gradle alpha3 . Try using the latest version, so change to classpath 'com.android.tools.build:gradle:2.2.2' .

The dependency declaration block looks legal. So try making the above changes to see if this will work.

+9
source share

You have implemented the plugin class plugin. Delete the following line in your project assembly:

 classpath 'com.google.dagger:dagger-compiler:2.2' 

and paste:

 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 

Then, in the build.gradle module, add the following code after applying the application for Android plugins:

 // add after applying plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' 

Add the following dependencies to your dependencies:

 // apt command comes from the android-apt plugin apt 'com.google.dagger:dagger-compiler:2.2' compile 'com.google.dagger:dagger:2.2' provided 'javax.annotation:jsr250-api:1.0' 

For more information read here:
https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2

and for an example project, visit here:
https://github.com/spirosoik/AndroidArchitecturePadawans

-one
source share

All Articles