Maven and Android - 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).

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 can I cache a local copy of Google's Maven Repo?

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).

gradle:how to speed up the looking up the maven repository for a dependency?

My project has more than 10+ maven repositories in the build.gradle, and the denpendencies speicified in my projoect are about 100 or more. This causes a problem. Each time I sync the gradle, it would try each maven repository for each dependency until it finds one providing that module.
The gradle docs contain the following:
A project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module.
However, this is really time-consuming. How can I speed up this process? Can I give some hint for a denpendency using some repository, avoid trying each one blindly?

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.

Uploading Android library to Maven Central

When using Android Studio, I am aware that you can add dependencies like so:
Then you can search to find repositories, and Android Studio will notify you when you need to update the version of your library dependency.
I also have a library (currently on Bintray), but it doesn't appear in the library dependency list (as in the first screenshot) - is this because the list shows libraries from Maven Central?
If so, how would I go about putting my library on Maven Central? I have looked at some results on Google, but different blog pages and tutorials show different steps, so it can be very confusing.
Since my library (view on GitHub) is using the Novoda Bintray Release plugin, I have tried following the instructions from this wiki page to add my library to Maven Central, but I'm not really sure where to go from here.
So, to summarise, what I am asking is:
Do I need to upload my library to Maven Central?
If so, how would I do that? Should I carry on using the Novoda plugin, or should I switch to something easier to use.
The current default maven repository for android gradle plugin is not Maven Central, but JCenter, and this is probably what you are looking for. If you currently have a library deployed to your maven repository on Bintray, publishing to JCenter (also managed by Bintray) is very easy and requires clicking a button, describing your library and waiting for approval. The whole process is neatly explained here.

Categories

Resources