Gradle Dependencies Download Jars - android

I'm trying to find a gradle task that will ensure that all of the dependency artifacts are downloaded into the gradle cache. If I run ./gradlew :project:dependencies, I can look at $GRADLE_USER_HOME/caches, and I can see a lot of com.x.package/artifact/version/hash/ directories, but they mostly (only?) contain .pom files. How do I ensure that .jar files are also downloaded?
For context, I'm attempting to build a docker image that has the gradle cache pre-built to avoid downloading artifacts every time.

Try
task showMeCache << {
configurations.compile.each { println it }
}
If you run it , it should download dependencies and print the location of the cached dependencies.
It may depend on your platform but the artifacts should be stored here:
~/.gradle/caches/modules-2/files-2.1

Related

Add android dependencies manually to gradle caches

I need to add android dependencies manually to gradle caches directory, as the gradle build can not get it but I can download it from my browser. This is the error:
> Could not find aapt2-7.0.4-7396180-osx.jar (com.android.tools.build:aapt2:7.0.4-7396180).
Searched in the following locations:
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/7.0.4-7396180/aapt2-7.0.4-7396180-osx.jar
I manually downloaded aapt2-7.0.4-7396180-osx.jar file and put it in the following directory:
username/.gradle/caches/modules-2/files-2.1/com.android.tools.build/aapt2/7.0.4-7396180/18ae77ce0ff3ba9da85e4674c2c92751cd1dc973/
I found the directory name: "18ae77ce0ff3ba9da85e4674c2c92751cd1dc973" from this command:
shasum aapt2-7.0.4-7396180-osx.jar
After this, I run the gradle build again, But I got the same error again and the build process tries to download the library and did not noticed that I have already downloaded it. Should I do anything else to let the build process know that this file is already downloaded?
If this is not your case.
Should I do anything else to let the build process know that this
file is already downloaded?
Try in your build.gradle append explicitly path to lib. For me
it's look like this:
Path to:
AndroidStudioProjects/DiceRoller/app/build.gradle
Source:
dependencies {
...
implementation files("~/Downloads/aapt2-7.0.4-7396180-osx.jar")
}
Run:
gradle clean

Android Gradle - How to include local .jar files as dependencies from outside the project directory

I'm working on a project that's suppossed to be running offline and I'm trying to include local .jar files as dependencies inside the build.gradle (app)
The structure of the repo can be seen here:
The main project is inside the dev folder.
In the submodules folder I have all the app and build dependencies along with the android-sdk, gradle plugin and jdk.
Trying to include all my jar files inside the build.gradle(app) like this:
implementation fileTree(include: ['*.jar'], dir: '../../submodules/app_dependencies')
Doesn't work because I'm referencing a path outside of the project's directory and when I try to build the app I get The following error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:androidDependencies'.
> Could not resolve all artifacts for configuration ':app:developDebugCompileClasspath'.
> Could not resolve org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61.
Required by:
project :app
> No cached version of org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61 available for offline mode.
> No cached version of org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61 available for offline mode.
> No cached version of org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61 available for offline mode.
> No cached version of org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61 available for offline mode.
Debugging this I see the message No meta-data file or artifact found for module 'org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.3.61' in repository 'maven' when it's looking in the following path:
file:/C:/Users/my-user-name/Desktop/android_repo/client-android/dev/submodules/dependencies/build_dependencies/org/jetbrains/kotlin/kotlin-android-extensions-runtime/1.3.61/kotlin-android-extensions-runtime-1.3.61.jar
for some reason, even if I added ../../ in the filetree(dir), gradle is still searching inside the dev directory and my dependencies are above in the submodules.
Is there a way to specify a dynamic path inside build.gradle that's outside of the project's directory?
It works with files (in kotlin notation):
dependencies {
implementation(files("../../submodules/app_dependencies/your-library.jar"))
}
If you need to include all files from some folder, you can just build a list of all jars in some directory and use it as files() argument.

Android build gradle dependencies

I have an app with 2 libraries as dependencies. I'm trying to build a script that clones those libraries into an empty folder and build the project.
I created a task within the app's build.gradle that clones the repos:
exec { commandLine "git", "clone", repo, repoFolderName }
The script starts and clones the repos, all fine but when it starts building the app if fails with the following error:
"Could not determine the dependencies of task ..."
If I run the script again it will successfully build the project.
From my initial investigation it seems that Gradle creates the dependencies as the 1st thing, before the libraries are locally cloned so the libraries are not there hence the build fails. If I run it again as the libraries are already there it will successfully build the project.
Any help is much appreciated.

Gradle offline how to cache the dependencies

I am doing nightly gradle builds on a server where I checkout the repositories from git and build them.However, there is a proxy where gradle cannot download any repository. I tried running gradlew offline mode then I get an error telling me that
"No cached version of" and then the name of the dependency.
This is obviously because I never downloaded the dependency, I was thinking of manually downloading the dependencies cache them and use that gradle cache on the server where builds can access it. My question is as follows :
Is there any way I can download a .jar file or .pom file manually and then cache them ?_
How would i cache a jar file in the $Home/.gradle/caches directory ? I tried just putting it there but it doesn't work .
any ideas?
Usually Gradle retrieves dependencies on demand, only if and when they are need. To make Gradle download all dependencies beforehand (and thus populate the local cache), you can use a task like
task resolveAllDependencies {
description "Resolves all transitive dependencies (e.g. to build offline later)."
doLast {
configurations.all {
it.resolve()
}
}
}
After running this task, you should be able to successfully build with --offline.
In Android Studio sync the dependencies once then go to
File > Settings > Build & Execution > Gradle > Enable Offline Mode > Ok!

Gradle clean task fails for not resolving all dependencies

When I ran ./gradlew clean for my Android project, the task failed for not resolving all dependencies. The complaints came from the gradle task _debugCompile.
I can verify some of the local dependencies didn't exist which failed the dependencies resolving process, but I'm still curious about why the clean task would check for dependencies while not building the project.
Shouldn't it just delete some directories as mentioned in the following link?
https://docs.gradle.org/current/userguide/java_plugin.html#sec:clean
Is there any gradle built-in task that could just clean the build folder without checking dependency?
Thanks!
Gradle already resolves dependencies during its configuration phase which precedes the execution phase, see The Build Lifecycle (it downloads dependencies only once they are needed, though). However, dependencies being out of date does not make resolution fail. If resolution fails that dependency is likely not available online anymore. If you still have the dependency in your Gradle cache you might be able to work around this by specifying the --offline switch:
$ ./gradlew --offline clean

Categories

Resources