Android build failed: Could not resolve all files for configuration ':debugCompileClasspath' - gradle

I'm new to Android development and keep running into this specific error when I try building my test app via the Windows command: python setup.py android -s:
Could not resolve all files for configuration ':debugCompileClasspath'
Could not find com.android.support:appcompat-v7:25.1.1.
So how do I resolve all files for configuration?
After several hours of troubleshooting, related answers to this question have not worked for me. For instance, I have tried manipulating my build.gradle file in the following manner:
Modified maven() to maven {url "https://maven.google.com" }
Modified jcenter() to jcenter { url "http://jcenter.bintray.com/" }
Moved jcenter... to be the last item in the list under repositories { .... (there is no allprojects { ... category)
Added buildToolsVersion "27.0.3" under android { ....
Modified the classpath version to the latest gradle version 3.1.0 like so classpath 'com.android.tools.build:gradle:3.1.0' (it was initially using an out of date version)
Updated Android Studio IDE
Uninstalled and reinstalled all SDK-tools under the SDK Manager
(Full build.gradle here, on pastebin)
The only remaining helpful hint I have here is the information provided by the log.
It tells me that it can't find files in directories on my hard drive. All other related outputs I've seen from others is the location specifiying actual websites related to google or gradle.
Could not resolve all files for configuration ':debugCompileClasspath'.
> Could not find com.android.support:appcompat-v7:25.1.1.
Searched in the following locations:
file:/C:/Users/USERNAME/AppData/Local/Android/sdk/extras/m2repository/com/android/support/appcompat-v7/25.1.1/appcompat-v7-25.1.1.pom
file:/C:/Users/USERNAME/AppData/Local/Android/sdk/extras/m2repository/com/android/support/appcompat-v7/25.1.1/appcompat-v7-25.1.1.jar
file:/C:/Users/USERNAME/AppData/Local/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.1.1/appcompat-v7-25.1.1.pom
file:/C:/Users/USERNAME/AppData/Local/Android/sdk/extras/google/m2repository/com/android/support/appcompat-v7/25.1.1/appcompat-v7-25.1.1.jar
file:/C:/Users/USERNAME/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.1.1/appcompat-v7-25.1.1.pom
file:/C:/Users/USERNAME/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/25.1.1/appcompat-v7-25.1.1.jar
I also have this error, which may or may not contribute to the files not being in the specified directory:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.7/userguide/command_line_interface.html#sec:command_line_warnings
Can anyone help me troubleshoot this issue and essentially resolve all files for configuration so that I can run my test app? Any help is greatly appreciated. Feel free to let me know if there's any additional I can provide.

Related

Building open source dependencies using gradle

I really don't have much experience in developing let alone using build tools.
I was assigned a task to build dependencies locally and get the jar files.
say I have a list of deps (GAV) like this:-
1. org.jetbrains.kotlin:kotlin-stdlib:1.6.0-RC
2. com.auth0:java-jwt:3.18.2, etc
3. openapi4j:openapi-operation-validator:1.0.7, etc
So i was able to download the source code url from maven repository and source code from github programmatically, for example :-
org.jetbrains.kotlin:kotlin-stdlib:1.6.0-RC - https://github.com/JetBrains/kotlin
com.auth0:java-jwt:3.18.2 - https://github.com/auth0/java-jwt
openapi4j-openapi-operation-validator-1.0.7 https://github.com/openapi4j/openapi4j
but there are many build.gradle files in different directories, how do I know which directory should I move into before running the gradle build command.
Things I have already tried and failed:-
For deps like this openapi4j:openapi-operation-validator:1.0.7, i can directly go into the openapi-operation-validator folder in the Github repo (https://github.com/openapi4j/openapi4j ) and run the gradle build command, but not all projects are structured like that I guess?
For deps like this com.auth0:java-jwt:3.18.2, the artifactId (java-jwt
) is already present in the github path (https://github.com/auth0/java-jwt), so i can run the gradle build command on the root github repo.
From the spring guides , among all the Gradle.build files available I can check which file has:-
jar {
archiveBaseName = <artifactId>
archiveVersion = <version>
}
, then I can move to that dir and run Gradle build, but not all build.gradle files have this.
None of the above approaches are concrete, is there any other firm approach that I can use to tackle the problem?
Your approach is generally correct.
You need to find the source code in github/gitlab/wherever, read the readme file and try to build it with whatever build tool was used there.
This may or may not work.

google errorprone java.lang.NoSuchMethodError

We are facing a strange problem. We are using net.ltgt.errorprone, version (0.0.8), along with guava(version 21) and gradle(version 3.1). Everything was working fine till today's morning. But suddenly all developers started getting this error
[system.err] An exception has occurred in the compiler (1.8.0_162). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.NoSuchMethodError: com.google.common.base.Verify.verify(ZLjava/lang/String;Ljava/lang/Object;)V
at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:132)
We searched through internet, most of the solutions are related to guava, but there was no change in guava version or
errorprone or gradle since a long time. We tried running old code also, getting the same error. We are unable to understand root cause of the problem. Did anyone face the same problem?
com.google.collections:google-collections was renamed to com.google.guava:guava which is really annoying and can often lead to two versions of the library on the classpath.
Here's how I'd diagnose the problem
Run gradle dependencies in the "broken" build
Go back in history in source control (git?) until you have a working version
Run gradle dependencies in the "working" build
Look for differences in versions of com.google.collections:google-collections
Look for differences in versions of com.google.guava:guava
See here in the Gradle docs where guava rename is discussed
You might need to add this to build.gradle
dependencies {
modules {
module("com.google.collections:google-collections") {
replacedBy("com.google.guava:guava", "google-collections is now part of Guava")
}
}
}
A new version(2.3.0) of errorprone was released, this broke our build.
We find out the dependency using this command
./gradlew -q dependencyInsight --configuration errorprone --dependency error_prone_core
This clearly showed that latest version is being used. We fixed it by using a last workable version forcefully. Following lines were added to build.gradle file
configurations.all {
resolutionStrategy {
force 'com.google.errorprone:error_prone_core:2.2.0'
}
}

Downloaded path for Gradle comple statement [duplicate]

How does Gradle store downloaded jar files on the local file system? Maven stores them in the .m2 directory under USER_HOME, but where does Gradle store them? I checked the .gradle folder there, but saw only compiled scripts.
On Mac, Linux and Windows i.e. on all 3 of the major platforms, Gradle stores dependencies at:
~/.gradle/caches/modules-2/files-2.1
Gradle caches artifacts in USER_HOME/.gradle folder. The compiled scripts are usually in the .gradle folder in your project folder.
If you can't find the cache, maybe it's because you have not cached any artifacts yet. You can always see where Gradle has cached artifacts with a simple script:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:12.0'
}
task showMeCache doLast() {
configurations.compileClasspath.each { println it }
}
Now if you run gradle showMeCache it should download the dependencies into the cache and print the full path.
In Windows 10 PC, it is saved at:
C:\Users\%USERNAME%\.gradle\caches\modules-2\files-2.1\
Gradle's local repository folder is:
$USER_HOME/.gradle/caches/modules-2/files-2.1
Defined dependencies will be loaded from remote repositories into gradle's local repository folder. For each loaded file, gradle will be create a new folder named with md5 value of the original file (pom,jar,..). Full path for the dependency file is made up from :
groupid + artifactid + version + FILE_MD5_VALUE + FILE_NAME
If our defined dependency is:
compile 'org.springframework:spring-jdbc:4.3.4.RELEASE'
Then the library will be loaded into :
/$USER_HOME/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/4.3.4.RELEASE/42175d194cf6aa7c716c0887f30255e5c0a5262c/spring-jdbc-4.3.4.RELEASE.jar
In fact the cache location depends on the GRADLE_USER_HOME environment variable value.
By default, it is $USER_HOME/.gradle on Unix-OS based and %userprofile%.\gradle on Windows.
But if you set this variable, the cache directory would be located from this path.
And whatever the case, you should dig into caches\modules-2\files-2.1 to find the dependencies.
If you want your dependency files to be in some specific folder you can simply use a copy task for it. For Eg.
task copyDepJars(type: Copy) {
from configurations.compile
into 'C:\\Users\\athakur\\Desktop\\lib'
}
I am on windows,
You should be able find the dependencies inside
$USER_HOME.gradle\caches\artifacts-24\filestore
Many answers are correct!
I want to add that you can easily find your download location with
gradle --info build
like described in https://stackoverflow.com/a/54000767/4471199.
New downloaded artifacts will be shown in stdout:
Downloading https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-parent/2.1.7.RELEASE/spring-boot-parent-2.1.7.RELEASE.pom to /tmp/gradle_download551283009937119777bin
In this case, I used the docker image gradle:5.6.2-jdk12.
As you can see, the docker container uses /tmp as download location.
You can use the gradle argument --project-cache-dir "/Users/whatever/.gradle/" to force the gradle cache directory.
In this way you can be darn sure you know what directory is being used (as well as create different caches for different projects)
I just stumbled onto this while searching for this answer. If you are using intellij, you can navigate to the file location, but opening the external lib folder in the project explorer, right clicking on the jar, and select Open Library Settings.
It took me a while to realize this, hence the additional answer. Hopefully it can save folks time. Note that if you are running sudo gradle the dependencies may not be in your home directory, even if sudo echo $HOME returns /Users/<my-non-root-user>/. On my Mac, Gradle was caching the dependencies in /private/var/root/.gradle/caches/.
In case it is an Android gradle project - you can find the android libraries below your $ANDROID_HOME/extras/android/m2repository folder
In android studio do the following steps to check the gradle downloaded jar file.
Set project structure view to "Project"
At bottom External library section available, expand it.
Here you can see downloaded jar files.
On my windows machine with "Buildship 2.0.2" plugin installed in eclipse, dependencies are stored :
$USER_HOME.gradle\caches\modules-2\files-2.1
For my case, I was using an Ivy repository, and my Gradle dependencies were stored in ~/.ivy2/.

findbugsMain task in gradle fails

I'm trying to run the findbugsMain task in Gradle 1.10 (or more specific "gradlew check") but the only thing I get is an error like
building findbugsMain 33% > ...
:findbugsMain FAILED
It seems to download the required jars though:
...
Download http://repo1.maven.org/maven2/jaxen/jaxen/1.1.1/jaxen-1.1.1.jar
Download http://repo1.maven.org/maven2/asm/asm/3.3/asm-3.3.jar
Download http://repo1.maven.org/maven2/asm/asm-tree/3.3/asm-tree-3.3.jar
Download http://repo1.maven.org/maven2/asm/asm-commons/3.3/asm-commons-3.3.jar
Download http://repo1.maven.org/maven2/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
Download http://repo1.maven.org/maven2/jdom/jdom/1.0/jdom-1.0.jar
Download http://repo1.maven.org/maven2/xerces/xercesImpl/2.6.2/xercesImpl-2.6.2.jar
Download http://repo1.maven.org/maven2/xom/xom/1.0/xom-1.0.jar
Download http://repo1.maven.org/maven2/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar
Download http://repo1.maven.org/maven2/xalan/xalan/2.6.0/xalan-2.6.0.jar
Download http://repo1.maven.org/maven2/com/ibm/icu/icu4j/2.6.1/icu4j-2.6.1.jar
:findbugsMain FAILED
I ran the task using --stacktravce again and this is what I got:
Pastebin link
My build.gradle is also on Pastebin
I'm relatively new to build management tools in general and gradle in particular, so it might be my fault (e.g. buildscript has an error).
Judging from the stack trace, some internal error occurs. This could be due to an incompatibility between the version of the ASM library used by Gradle, and the version expected by FindBugs. Would you mind to file an issue over at http://forums.gradle.org, ideally including a minimal reproducible example?
As it seems FindBugs up to version 2.0.3 has problems with some Java 8 classfiles. These
problems will be addressed in the next major version of FindBugs. Until then you have to use Java 7.
So, the short version is, that I changed the language level to 1.7 and everything runs just fine now.
Thanks #peter for the help.

Unsupported method: GradleProject.getBuildScript()

I am getting this error while importing an adt project(after exporting and creating gradle file) into Android Studio on mac os x.
The android-studio version is 3.6 (latest) and the gradle version is 1.8 (latest).
The error shows up as:
Unsupported method: GradleProject.getBuildScript(). The version of
Gradle you connect to does not support that method. To resolve the
problem you can change/upgrade the target version of Gradle you
connect to. Alternatively, you can ignore this exception and read
other information from the model.
Consult IDE log for more details (Help | Show Log)
I have no idea where to look for IDE logs...
I was getting a similar error today opening a project after upgrading to Android Studio 0.3.6. Here is what I had to change to get it working again for me.
Changed the following line in gradle-wrapper.properties from gradle-1.6-bin.zip to gradle-1.8-bin.zip
distributionUrl=http://services.gradle.org/distributions/gradle-1.8-bin.zip
Also changed the following line in build.gradle from 0.5.+ to 0.6.+
classpath 'com.android.tools.build:gradle:0.6.+'
In Windows, gradle-wrapper.properties is located at \project folder\gradle\wrapper\gradle-wrapper.properties
build.gradle is located at \project folder\module folder\build.gradle
The Files that Needed changed are highlighted in the project explorer screen shot below.
After those changes I sync'd the project with the gradle files and then could build and test.
Hope that helps.
Note that you should use default or customizable gradle wrapper:

Resources