When gradle build
ing my project, I'm getting this error:
FAILURE: Build failed with an exception.
Where:
Build file 'App/build.gradle' line: 45What went wrong:
A problem occurred evaluating project ':App'.
Ambiguous method overloading for method java.io.File#.
Cannot resolve which method to invoke for [null, class java.lang.String] due to overlapping prototypes between:
[class java.lang.String, class java.lang.String]
[class java.io.File, class java.lang.String]
Said line is the first proguardFile
rule:
buildTypes { release { debuggable false jniDebugBuild false signingConfig signingConfigs.(System.getenv("SIGNING_CONFIG") ?: "release") runProguard true proguardFile getDefaultProguardFile('proguard-android-optimize.txt') proguardFile 'proguard-rules.txt' } }
I haven't got any local.properties
file, nor opened the project in Android Studio.
What is wrong with my project? How can I fix this error?
There are ambiguities while using variable arguments in Java. This happens because two methods can definitely be valid enough to be called by data values. Due to this, the compiler doesn't have the knowledge as to which method to call.
Ambiguity errors occur when erasure causes two seemingly distinct generic declarations to resolve to the same erased type, causing a conflict. Here is an example that involves method overloading: Notice that MyGenClass declares two generic types: T and V.
It is not possible to decide to execute which method based on the return type, therefore, overloading is not possible just by changing the return type of the method.
Yes, We can overload the main method in java but JVM only calls the original main method, it will never call our overloaded main method.
The error message has been changed in September 2014. It is now clearer and explicitely points out that the problem is that Gradle can't find the SDK; the rest of the answer still applies to old versions (<0.13) of the Gradle plugin.
This is due to Gradle not being able to find the SDK location, and thus failling when doing something that needs the Android SDK, such as getting the default Proguard file location.
Actually, this is what Gradle will tell you if you temporarily comment out that line:
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
You can fix it:
By defining the SDK location in local.properties
: simply add sdk.dir=/path/to/sdk
to that file.
By setting the SDK location in environment variable ANDROID_HOME
: you just need to set the environment variable by adding ANDROID_HOME=/path/to/sdk
before gradle
.
Example: ANDROID_HOME=/path/to/sdk gradle build
.
When using a version control system, it is perfectly fine to set the location locally in your own local.properties
, as manually setting the environment variable every time you need to use Gradle would be annoying. Just make sure to not check it into your repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With