When i am trying to compile a imported project from github, my gradle build always fails with the following exeption.
Unable to find method \'org.gradle.api.
If you are getting this error after deleting .gradle and .idea files then the error is happening because the Gradle files are not available for this project and Android studio is unable to download the same version of the Gradle dependency. You can switch to a lower version of the Gradle choose from here and then go to gradle-wrapper-properties file and change the version, in my case I changed it from distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
to distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
. After downloading the older version of the Gradle dependency a Gradle update dialog box would prompt through which you can get the latest version back which is 5.1.1 in this case.
In the file SampleProject/gradle/wrapper/gradle-wrapper.properties
change
distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
to
distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip
for android studio path "folder project/gradle/wrapper/gradle-wrapper.properties" file change URL value distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip apropriate (previous) version from http://services.gradle.org/distributions/
I had to change the distributionUrl in the gradle-wrapper.properties
to distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
to get the build running again. This seems to be a similar problem Gradle sync failed: Unable to find method.
Looks like you are failing to resolve your testInstrumentation. Are you using facebook.screenshot api? if so you need to include it.
Otherwise, just comment out the testInstrument section and see if you can build without the tests for now if you don't care about them. otherwise you need to fix your dependency usage of it.
*comment out testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
This causes a line to get created in your manifest and it is probably not resolving properly.
I fix same as this error by add classpath 'com.android.tools.build:gradle:3.2.1'
in the build.gradle project
buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}