Gradle DSL method not found: 'apt()'

大兔子大兔子 提交于 2019-11-30 02:41:07

It's entirely possible that there's a way to get your plugins to work. Given your error, I'd start by following what the ButterKnife project uses, get that working, then see if there is a recipe for what you're trying.

First, in your top-level build.gradle file, include classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' in the buildscript dependencies, such as:

  buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
      classpath 'com.android.tools.build:gradle:2.0.0'
      classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
  }

Then, in your module's build.gradle file, include apply plugin: 'com.neenbedankt.android-apt' towards the top.

The links are to the relevant files from the ButterKnife GitHub repo, from the project and the dedicated sample app.

q...

apt is obsolete, Change apt to new format:

change

apt 'com.jakewharton:butterknife-compiler:8.5.1'

to

annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

https://bitbucket.org/hvisser/android-apt/wiki/Migration

http://jakewharton.github.io/butterknife/

Instead of:

    plugins {id "net.ltgt.apt" version "0.6"}

try:

    apply plugin: 'android-apt'

In my case helped: adding to your build.gradle (not main, but project one) :

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

and

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
    }
}

Add your apt code into the apps build.gradle NOT in main build.gradle.

dependencies {
    apt group: 'group name here', name: 'artifact name here', version:'version here'
}

Of Course, you'll have to add the following code in your main build.gradle

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!