How can I cache a local copy of Google's Maven Repo? - android

I'm trying to download a stable version of Google's Maven Repo (https://maven.google.com/web/index.html#) on my local machine. This is part of a larger effort for offline Android Development. The goal is to cache the repo's vast amount of dependencies (to include legacy versions for compatibility issues) so I can use Gradle build-scripts and use the required dependencies locally rather than having to rely on an active internet connection and need to reach remote repositories.
Without adding each individual dependency to my build.gradle(app) file, is there a way I can download the entire repo and have my build.gradle use it?
I've added common dependencies to my build.gradle(app) but still want to have the flexibility of adding more functionality later on (again, without internet access).

Related

publishing a library - how to make it so that consuming app doesn't need to add repositories for transient dependencies

I've created an Android library called Library and I want to publish it to a private maven repository and then consume it in an app called App.
I am encountering an issue however which is making the usage of the library untenable for App. The issue is that one of the dependencies of Library is hosted in a "non standard" maven repository, and is forcing the consuming App to add this repository to it's repositories block.
To explain this further; Library has lots of dependencies, most of which are pulled from google and mavenCentral repositories (both of which the consuming App has in the repositories block because all Android apps will include these repositories). However, one of the dependencies, Quikkly, is hosted in a "non standard" maven repository (i.e. one with a non standard URL), which also requires a github personal access token to access. So in my Library repositories block, I have to add this maven repo in order to pull this specific dependency:
maven {
url 'https://maven.pkg.github.com/quikkly/quikkly-android-sdk'
credentials {
username = <github_username>
password = <github_access_token>
}
}
All well and good; I can build Library just fine, and the Quikkly dependency is pulled successfully from this repository.
The issue arises when I use Library in App. I published Library to mavenLocal (or my own private maven repository depending on when I'm ready to actually push a release). When I pull Library into App and then build, the build fails because Quikkly could not be resolved.
The errors show that the locations searched were just the repositories defined in App and not those defined in Library. I can make the build succeed if I add the Quikkly custom maven repo (and github access token) to App but I don't want to force App developers to need to add custom repos just to use my library - surely my library should be responsible for properly packaging it's own dependencies such that consumers just need to use my library via a one line gradle import.
I've done some research on this, and I think the solution involves adding the custom maven repository URL to a <server> element in my libraries .pom file, however the repository also requires a github username and personal access token in order to pull the library from it... my research shows that I need to add these details to "somewhere" (but not in the .pom file as this would be insecure and/or wouldn't even work).
I'm now getting pressured to release something working, but I'm pretty stuck with this. Can anyone help?

How to use a Gradle dependency with local modifications?

I have an Android application using an Android library. The library is a pretty big open-source project on GitHub, and its authors publish the artifacts to Bintray. I can specify the dependency with the usual syntax dependencies { implementation 'group:artifact:version' } in the app's build.gradle.
Now I want to change some code in the library. I git clone it on my machine, I make my changes, then I build the library. But how can I tell my app to use the library I built locally, instead of the one in Bintray?
I don't want to follow the approach in Gradle Local Project Dependency, because that means that the library code is now part of the application project, but I really want to keep things separated.
I think the solution involves publishing to a local Maven repository. I followed the guide at https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 but the app's Gradle is still picking the original library from Bintray.
Bintray-based projects have the install task. That's the one to be used instead of publishToMavenLocal.
When using install, the artifact version is automatically set to X.X.X before publishing to the local repository. Therefore, in order for the app to pick up the local library, you have to edit the implementation row to group:artifact:X.X.X.
As the guide https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 suggests, you also need to add mavenLocal() as the first entry in the repositories section in the top-level build.gradle of the application.

Why not adding mavenLocal() in all Android apps?

When creating an Android project from scratch, Android Studio doesn't add mavenLocal() to the list of Gradle repositories. But we added it, and builds are now faster than ever.
Is there any reason to avoid adding mavenLocal() at every Android project we have? I mean, are there any cons in doing it?
What if you didn't have .m2 local repository?
mavenLocal() actually adds your .m2 to your Gradle repositories.
Gradle has its own ivy cache, and probably when you migrated the project or had a different project that used some common dependencies, its actually faster as all the dependencies been downloaded already before, therefore adding maven local repo to Gradle repositories makes the fresh project faster as it doesn't need to download them again to its local cache.
I would personally have it there as I have some maven and some Gradle projects, and yes it speeds up the build, and it doesn't use as much space to store duplicated dependencies for multiple projects. But I also think that if you are not using maven, you should let Gradle manage its dependencies.
I think #LazerBanana has pointed out the issue.
But besides that, I also want to mention the continuous integration practices everyone has nowadays for the builds. That is another thing we should not have mavenLocal(), because it makes builds depending on machines.

Android studio - Gradle - GitHub Repo

Does anyone have an idea if it's possible to use a github repo as a dependency, without it being published to maven central.
Let's say I'm developing an android library that has it's own github repo. I'd like to be able to "compile" this library has gradle dependency, in my android studio project, without having to publish to maven central (at least for the moment).
In other words : I want to use a dependency that is not on maven central. It's a straight github repo (an android library that also uses gradle).
I'd like my build.gradle to do something like this :
dependencies {
// Google Play Services (normal dependency)
compile "com.google.android.gms:play-services:5.2.08"
// The library I want to pull from github
compile "path_to_my_github_repo"
}
Thanks!
You can do that with Jitpack with Maven, Gradle and sbt.
However, I would strongly suggest to use binary artifact instead so that you are guaranteed that it is the same upon each build of your application, you control the artifact storage and you are using the official release of a project and not some downstream build. It will also make your builds much faster and more stable.
Publishing to the Central Repository is free, easy and well documented at e.g. http://central.sonatype.org/pages/producers.html and specifically for Gradle at http://central.sonatype.org/pages/gradle.html. You can also find lots of real world examples on the Nexus community site.
If you do not control the project you want to consume, I would suggest to send these pointers to the project and maybe even help them with a pull request ;-)
This should be possible and there is an unofficial gradle plugin called Gradle Git Repo plugin that claims to do what you're looking for. Note however, that I did not play with it myself to verify that it works.
What you need to use is a binary repository. It will contain your dependencies during development.
If you plan to publish your package to jcenter (and maven central) eventually, you can get a free Artifactory account in oss.jfrog.org.
Once doing that, your CI server can deploy your dependency to it and Gradle will resolve it from there.

Maven and Android

I want to use Maven Dependencies injections in my Android Project. The goal of this is not to include the libraries into the project but to bind them during runtime. However, I was wondering if the internet connection is slow what is going to be happen? Will the project crash? Will it become slow in compared with the occasion that I had include the libraries into the app?
You are mixing something up here. Maven doesn't do dependency injection. That's a spring term. Maven does build management which helps you adding the correct jars while your application gets built.
The necessary libraries are downloaded from the internet (or your local repository) when you compile your application. This is not done when the application is executed! Maven can add the correct jars in the right versions to your jar (if you configure Maven to do this).

Categories

Resources