android - 找不到方法 apt()

标签 android dagger-2 apt

我正在尝试使用 Dagger2,我正在使用 Android studio 2.2.2 但我在 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>

请帮助我了解我的 gradle 有什么问题

这是我的项目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
}

这是我的模块 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'
}

最佳答案

添加

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

内部依赖

注意:

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.

关于android - 找不到方法 apt(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42749673/

相关文章:

android - OpenSL ES 改变音高

java - 我丢失了调试 keystore 文件

android - 如何将 RecyclerView 上的最后一项滚动到顶部位置?

java - 如何在 Kotlin 中注入(inject) var?

ubuntu - 如何使用 apt-get 在 Ubuntu 上安装最新的 uWSGI/stable

android - 如何混淆 Jar 或 AAR 文件

android - 如何在模块中添加 View 模型?

android - Dagger 2 注入(inject)后返回null

ubuntu - apt-get install -f 不解决依赖关系

linux - 安装 dsc21 时出错 : "dsc21 : Depends: cassandra (= 2.1.8) but 2.2.0 is to be installed"