I have an unsupported gradle method instrumentTestCompile when including espresso in my Android project gradle.build on Android studio following Google instructions:
https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions.
gradle.build:
dependencies {
instrumentTestCompile files('libs/espresso-1.1.jar',
'libs/testrunner-1.1.jar',
'libs/testrunner-runtime-1.1.jar')
instrumentTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-library:1.1'
}
Complete error:
Build script error, unsupported Gradle DSL method found: ‘instrumentTestCompile()’!
Possible causes could be:
– you are using Gradle version where the method is absent
– you didn’t apply Gradle plugin which provides the method
– or there is a mistake in a build script
I found the response here:
http://android.amberfog.com/?p=894
instrumentTestCompile() was renamed to androidTestCompile() in the latest version of gradle plugin.
Related
Here is the following snippet from the Gradle build file:
implementation "com.google.dagger:dagger:${versions.dagger}"
implementation "com.google.dagger:dagger-android:${versions.dagger}"
implementation "com.google.dagger:dagger-android-support:${versions.dagger}"
kapt "com.google.dagger:dagger-compiler:${versions.dagger}"
kapt "com.google.dagger:dagger-android-processor:${versions.dagger}"
If I set the ${versions.dagger} to anything over 2.24 e.g. 2.25.x the gradle sync fails to resolve.
ERROR: Failed to resolve: com.google.dagger:dagger-android-support:2.25.2
EDIT: I checked the maven repository and the latest version available is 2.25.4
EDIT: Upgrading from 2.24
I am migrating my Android project to Gradle 4.4 and Android Gradle plugin 3.1.2.
It has a library module which depends on parceler library and defines its dependency as follows:
build.gradle of library module:
...
// parceler for serialization (https://github.com/johncarl81/parceler)
implementation "org.parceler:parceler-api:1.0.4"
annotationProcessor "org.parceler:parceler:1.0.4"
...
This seems to compile well and generates my aar file.
Further, my main app module also has a direct dependency on parceler module and contains above lines as dependencies in its build.gradle, along with above aar file.
build.gradle of main app module:
...
api(group: 'com.example.mylibrary', name: 'mylibrary', version: "1.0.7", ext: 'aar') {
transitive = true;
changing = true
}
// parceler for serialization (https://github.com/johncarl81/parceler)
implementation "org.parceler:parceler-api:1.0.4"
annotationProcessor "org.parceler:parceler:1.0.4"
...
Everything works until I try to generate my APK, which fails with the following error.
D8: Program type already present: org.parceler.Parceler$$Parcels$1
Task :MPCApp:transformDexArchiveWithDexMergerForRelease FAILED
When I expand my library project in Android studio, I see Parcels.class under org.parceler package. But it seems similar file is also generated by main app module under the same package which is causing the clash.
Upgrade to the latest (currently 1.1.10) - We got rid of the Parcels generated class.
I am using gradle version - 3.3-all and gradle plugin - gradle:2.3.3
I want to write test cases. So as per this page, I included the following in the the app's top build.gradle file.
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
But I get the error saying
Error:(11, 0) Gradle DSL method not found: 'testCompile()'
Possible causes:<ul><li>The project 'TopLevelProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
What could be the issue?
Add the Java plugin
apply plugin: 'java'
In gradle the configurations: compile runtime testCompile etc are coming from java plugin
But in android i think you need apply plugin: 'com.android.application'
Edit: Please share your root build.gradle and app build.gradle especially android closure, dependencies and plugins and describe which is where.
Sometimes is a structural problem and app related stuff lands in root build.gradle
I don't have the reputation to comment, so I post this as an answer.
I had a similar problem, try applying the Java plugin and the testCompiles in the app's build file, that is in: project/app/build.gradle, not the project's build file.
apply plugin: 'com.android.application'
dependencies {
...
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
}
After upgrading from 2.2 to 2.3 I see this warning
and when I try to compile the project I see this compilation error
How can i solve this issue without downgrading to a previous gradle version?
Is there any update of android-apt that can solve this issue?
The android-apt plugin has been deprecated.
Check here for the migration guide:
As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin.
You can remove android-apt by following the migration guide to get the equivalent functionalities.
The important parts from the migration guide:
Make sure you are on the Android Gradle 2.2 plugin or newer.
Remove the android-apt plugin from your build scripts
Change all apt, androidTestApt and testApt dependencies to their new format:
dependencies {
compile 'com.google.dagger:dagger:2.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
Also in the Android Gradle plugin there is an explicit check for this, which is what you are seeing:
using incompatible plugins for the annotation processing android-apt
Future Android Gradle plugin versions will not be compatible with the way android-apt works, which is the reason for that check.
For me, I was having this error while using Contentful's Vault library which specifies that you include:
apply plugin: 'com.neenbedankt.android-apt'
and
compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'
What you need to do is DELETE apply plugin: 'com.neenbedankt.android-apt'
and then CHANGE:
compile 'com.contentful.vault:core:2.1.0'
apt 'com.contentful.vault:compiler:2.1.0'
to
annotationProcessor 'com.contentful.vault:compiler:2.1.0'
annotationProcessor 'com.contentful.vault:core:3.0.1'
You can always check https://github.com/contentful/vault for the latest versions
Remove apt plugin
Change:
apt -> compile
testApt -> testAnnotationProcessor
androidTestApt -> androidTestAnnotationProcessor
In your build.gradle (app), add to defaultConfig:
vectorDrawables.useSupportLibrary = true
Piggybacking on #Gabriele Mariotti here since his answer is pretty spot on and implies this but doesn't state it. Gradle also does not suggest this as a valid option though it is as well. The testing equivalent for androidTestApt and testApt is androidTestAnnotationProcessor and testAnnotationProcessor.
Example:
testApt "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestApt "com.google.dagger:dagger-compiler:$daggerVersion"
Should be changed to
testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
In case the annotation processor has arguments, one also might have to change this:
apt {
arguments {
KEY "VALUE"
}
}
to this:
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ['KEY': 'VALUE']
}
}
}
}
Getting the below error when trying to build flavour types of my lib modules.
Error:(210, 0) Gradle DSL method not found: 'flavourOneReleaseCompile()'
Possible causes:<ul><li>The project 'MyProject' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Fix plugin version and sync project</li><li>The project 'MyProject' may be using a version of Gradle that does not contain the method.
Gradle settings</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
build file
android{......}
configurations{
flavorOneDebugCompile{}
flavorOneReleaseCompileCompile{}
flavorTwoDebugCompile{}
flavorTworeleaseCompile{}
}
dependencies {
flavorOneDebugCompile project(path: ':lib', configuration: 'flavorOneDebug')
flavorOneReleaseCompile project(path: ':lib', configuration: 'flavorOneRelease')
flavorTwoDebugCompile project(path: ':lib', configuration: 'flavorTwoDebug')
flavorTwoReleaseCompile project(path: ':lib', configuration: 'flavorTwoRelease')
}
Im using
classpath 'com.android.tools.build:gradle:1.3.1'
i was following this guide on how to target specific build flavours
https://developer.android.com/studio/build/gradle-tips.html#target-specific-builds-with-dependency-configurations
You are using spelling mistake flavorOneReleaseCompileCompile in
configurations{
flavorOneDebugCompile{}
flavorOneReleaseCompileCompile{}
flavorTwoDebugCompile{}
flavorTworeleaseCompile{}
}
Try replacing flavorOneReleaseCompileCompile with flavorOneReleaseCompile