Gradle DSL method not found: 'apt()'
Solution 1
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.
Solution 2
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/
Solution 3
Instead of:
plugins {id "net.ltgt.apt" version "0.6"}
try:
apply plugin: 'android-apt'
Solution 4
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'
}
}
Related videos on Youtube
![Michel Feinstein](https://i.stack.imgur.com/GrxLO.jpg?s=256&g=1)
Michel Feinstein
8+ years of experience as a Software Engineer, 3 years building Flutter Applications, 6 years building Android Applications. Worked with many different technologies, such as Mobile Apps, Serverless Applications, Micro-Services, Desktop Apps, Robotics, Embedded Systems, IoT, and others. Managed projects from start to finish, with clients in Brazil, Canada, and Israel. Advanced experience with Dart, Java, C#, C, C++, and SQL, moderate experience with Javascript. If you want to see some of my work, here are some public projects I have done or contributed to. Feel free to contact me over LinkedIn.
Updated on July 09, 2022Comments
-
Michel Feinstein almost 2 years
I am trying to add the latest version of butterknife and I get this error from gradle:
Error:(31, 0) Gradle DSL method not found: 'apt()' Possible causes:
- The project 'MyProject' may be using a version of Gradle that does not contain the method. Gradle settings
- The build file may be missing a Gradle plugin. Apply Gradle plugin
Where my gradle
mobile
build.gradle
is:plugins { id "net.ltgt.apt" version "0.6" } apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.mynamspace.myproject" minSdkVersion 19 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) wearApp project(':wear') testCompile 'junit:junit:4.12' compile 'com.jakewharton:butterknife:8.0.0' apt 'com.jakewharton:butterknife-compiler:8.0.0' compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.google.android.gms:play-services:8.4.0' compile 'com.android.support:design:23.3.0' compile 'com.android.support:support-v4:23.3.0' compile 'com.android.support:recyclerview-v7:23.3.0' }
What's wrong with the gradle-apt-plugin?
-
CommonsWare about 8 yearsI haven't seen that
plugins
syntax before, and that does not appear to be theandroid-apt
plugin. -
Michel Feinstein about 8 yearsThat's the new mecanism of gradle plugins: plugins.gradle.org/plugin/net.ltgt.apt (look for the "About the new plugin mechanism").
-
Michel Feinstein about 8 yearsWhere do I get the
android-apt
plugin?...I confess I am a bit lost here, I don't know much about gradle, I just got this plugin in a google search for "gradle apt"
-
Michel Feinstein about 8 yearsThanks for the help! The project's page (jakewharton.github.io/butterknife) have these configurations missing.....but the github page doesnt (github.com/JakeWharton/butterknife) and they are pretty much the same as your code.
-
Matthew Housser about 8 yearsComing from ButterKnife 7.0.1 to 8.0.1 - the upgrade was not at all obvious. All these extra Gradle entries were not explained very well at all. Finally have it working now thanks to your advice, @CommonsWare!
-
m02ph3u5 about 8 years
apply at top
did it -
q... over 7 yearsthis is for Android Gradle Plugin >= 2.2, if < 2.2 use the accepted answer