Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method apt()

I'm trying to work with Dagger2, I am using Android studio 2.2.2 but I have an error with gradle:

Error:(34, 0) Could not find method apt() for arguments
[com.google.dagger:dagger-compiler:2.6] on object of type
 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
<a href="openFile:C:\Users\edi.bershatsky\Google
Drive\Android\eWave\MyCode\MyDagger2\app\build.gradle">Open File</a>

please help me to understand what is wrong with my gradle

this is my project gradle:

// 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:2.2.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven{
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

this is my module gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.edi.mydagger2"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


}

ext {
    JUNIT_VERSION = '4.12'
    DAGGER_VERSION ='2.4'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.1.1'

    compile 'com.google.dagger:dagger:2.6'
    apt 'com.google.dagger:dagger-compiler:2.6'
}
like image 509
ediBersh Avatar asked Mar 12 '17 16:03

ediBersh


4 Answers

Add

compile 'com.google.dagger:dagger:2.6'
annotationProcessor "com.google.dagger:dagger-compiler:2.6"

inside dependencies

NOTE:

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 which called annotationProcessor.

like image 71
abdullahselek Avatar answered Sep 22 '22 07:09

abdullahselek


Use annotationProcessor instead of apt

like image 43
shmakova Avatar answered Sep 22 '22 07:09

shmakova


use

compile 'com.google.dagger:dagger:2.19'
annotationProcessor "com.google.dagger:dagger-compiler:2.19"

in your dependencies instead of

 compile 'com.google.dagger:dagger:2.19'
 apt 'com.google.dagger:dagger-compiler:2.19'
like image 35
Felhi Abdelhafidh Avatar answered Sep 22 '22 07:09

Felhi Abdelhafidh


You forgot to actually apply android-apt plugin

 apply plugin: 'com.neenbedankt.android-apt'

(but now you should just remove it and use annotationProcessor or kapt with kotlin-kapt depending on your language anyways)

like image 30
EpicPandaForce Avatar answered Sep 21 '22 07:09

EpicPandaForce