Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

my project build.gradle

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 module build.gradle

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 using the annotationProcessor function within the Android studio 2.2 ,how to conifg the dagger2 annotation processor correctly?

new Jack annotations processors

like image 356
belle tian Avatar asked Jun 18 '16 05:06

belle tian


1 Answers

Yes, with android gradle plugin 2.2.0 release, the android-apt plugin is no longer needed for annotation processing. The apt function was included in the latest android gradle plugin. It's called annotationProcessor now which was what you had in your build script. However, there were a few misconfigured stuff in the script.

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

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

The dependency declaration block looks legit. So try to make the above changes to see if it would work.

like image 150
Aaron He Avatar answered Oct 16 '22 14:10

Aaron He