How to include dependency repos on published android library - android

I am working on a library that uses custom repositories (i.e. with specific URLs) to get some of the dependencies.
maven {
url 'https://someURL/'
}
I've published the library and set it on our private repository and noticed that I couldn't compile because gradle couldn't locate these dependencies. I could fix that by adding the same custom repositories to the testing app project-level build.gradle, but I want to know if there's an option to avoid this, meaning, have the testing application get the custom repositories information from the published packages.

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?

Gradle Android repositories url issue

I have a library module where I used a dependency which is based on a private maven repository, I can use this dependency in my library and everything works well.
The problem occurs when I try to use the library module inside my application, the build is failing, for some reason is looking to get this dependency from a different maven repository (in this case, my personal one, which is available only in my app)
I've switched from implementation to api and viceversa, just so check if this might solve the issue, but it is not.
If I add the maven repository url also in my app, everything works well, but I don't what that. Is this the expected behaviour?
Thanks!
Yes, repositories declared in one subproject are not shared with other subprojects. Other than with Maven, repositories are also not taken from a dependency POM file or otherwise inherited from a dependency. On this topic, the Gradle docs state the following:
Strict limitation to declared repositories
Maven POM metadata can reference additional repositories. These will be ignored by Gradle, which will only use the repositories declared in the build itself.
However, you can probably centralize the repository declaration in your top-level settings.gradle(.kts) file:
dependencyResolutionManagement {
repositories {
// TODO Configure the shared repository here.
}
}
You can find more details on this centralization in the Gradle docs.

How to implement implementations in android without error?

I want to add AdView to my activity and I click on download and then it automatically implements the necessary library. But then I get the following error:
Error 1
I get the same error when I try to add GridLayout to my library.
Here is my gradle file: gradle file
I already tried to set the Global Gradle settings to offline work but it doesn't help.
I have android studio 3.4.2
This is a problem that bothers me for a while now and there seems no solution to this. Is it possible that these things are not available for androidx yet? Thank you for your help!
From the documentation:
To make the Google Play services APIs available to your app:
Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
Add a new build rule under dependencies for the latest version of play-services, using one of the APIs listed below.
Ensure that your top-level build.gradle contains a reference to the google() repo or to maven { url "https://maven.google.com" }.
Save the changes, and click Sync Project with Gradle Files in the toolbar.
You can now begin developing features with the Google Play services APIs.
This is often a common mistake. If you have multiple repositories in your gradle, make sure that maven google is at the top of the list.
eg.
repositories {
maven { url "https://maven.google.com" }
...
}
This package:
// https://mvnrepository.com/artifact/com.google.android.gms/play-services-ads
implementation "com.google.android.gms:play-services-ads:18.1.1"
is either available from repository google() or from repository mavenCentral():
repositories {
google()
mavenCentral()
...
}
see the quick-start.

How to install my own Java library?

I created a Java class for helping me to use some common debuggin stuffs, for example to get the type of value, I have a method call typeOf()
Help help = new Help();
String s = "Something";
help.alert(help.typeOf(s));
above is a sample code in my class
Now every time I start a project, I need copy the class file to my project, so I want to know is there any way I can install this in my OS, then can import it to any of project whenever I needed.
In C you can move the header file to a location, then you can #include it whenever you want
If you using gradle, you can learn it from Building your own Android library but need to publish your library to jCenter or Maven Central.
Fortunately, you can make the library as a local artifact using maven plugin in the library. Read more at Deploying an Artifact to the Local Cache in Gradle
In your project, you need to add mavenLocal() to the repositories in your root build.gradle:
repositories {
mavenCentral()
mavenLocal()
}
And add the dependencies to your project build.gradle:
dependencies {
...
compile 'com.your.library:x.y.z'
...
}
But if your project is shared in your local network, you need to use Repository management like Artifactory by JFrog or Nexus Repository Manager by Sonatype.

Android vs. Maven Internal Repositories

Say I need to use some proprietary jars in my android library. I want my library to be conveniently available from Maven Central, but I can't just put dependencies there due to legal issues.
I figured it's possible to use Internal Repository to host dependencies so they would be resolved automatically.
I've used Github repo, just like this one, and declared it in library pom.xml
However Gradle doesn't seem to be resolving this dependencies. If I manually declare my repository in main build.gradle everything works fine. Am I doing something wrong here, or android gradle plugind just don't support internal repositories?
It's discouraged in the Maven community to have repository declarations in published POMs, and Gradle won't honor them. Instead, downstream builds will have to declare the internal repository in one way or another (which shouldn't be a big deal).
If you (only) publish POMs for proprietary dependencies to Maven Central (which is a common solution to this problem at least if you own the dependencies), downstream builds will need to declare the internal repository as follows:
repositories {
maven {
url "https://repo1.maven.org/maven2"
artifactUrls "https://some.internal.repo"
}
}
If you don't publish proprietary dependencies to Maven Central at all (not even POMs), downstream builds will have to declare the internal repository as another regular Maven repository:
repositories {
mavenCentral()
maven {
url "https://some.internal.repo"
}
}
Note however that last time I checked, one of the rules of publishing to Maven Central was that dependencies needed to be available from Maven Central as well.
PS: Whether you are publishing a Java or Android library shouldn't matter here.

Categories

Resources