I am working on a project with a few modules, something like this:
:app
:coreLib
:exportLibrary
:otherLibrary
in my build.gradle for my exportLibrary module I import coreLib like this:
implementation(project("coreLib"))
and in my app I do the same to include exportLibrary:
implementation(project("exportLibrary"))
What I want to do is publish exportLibrary to a maven repository, and I want it to include everything from coreLib. I haven't found a good way to do this yet. Adding a transitive flag does not help. What am I missing?
I hope I do not need to publish coreLib too!
I am publishing using artifactoryPublish, which includes the artifacts created after running assembleRelease. So, basically how do I make assembleRelease produce a binary that includes my local dependency?
Just publish coreLibrary in the maven repo.
Then in your exportLibrary change the dependency with:
implementation "com.xxxx.coreLibrary:x.y.z"
and publish it in the maven.
At this point if you check the pom file of exportLibrary in the repo you will find the dependency to com.xxxx.coreLibrary:x.y.z.
Related
There are many posts about publishing android library in github. Is there any way to publish android library to the svn?
EDIT:
I have created a libray and build the aar file. I have imported the aar file in to a tag of the svn. (Ex: svnpath/project/tags/library0.0.1.aar)
I want to use this library in a separate project. I want to use this library as
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
like this. how can i achieve this?
As discussed in the comments, Subversion (SVN) is not an appropriate tool for what you are trying to achieve. Subversion is a version control system which manages the versioning of source code files and associated resources, much in the same manner as Git does.
What you are looking for is a dependency management system using Maven, for example Artifactory. This will allow you to publish your .aar files to either a public-facing or private repository and import those dependencies into your build.gradle file. Unfortunately the process for setting up such a service is too broad for the scope of this question, but once you have it up and running you can add it to your build.gradle file under the repositories section:
repositories {
maven {
url "<url of Maven server>"
credentials {
// If you choose to use authentication
username = <your artifactory username>
password = <your artifactory password>
}
}
}
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.
I'm new to publish own library in android.
I created my own library and uploaded it to bintray. My library depends several third party libraries. When I see pom.xml file, there are dependency information.
But when I add my library to test project gradle, it didn't import its dependencies. So I had to add it manually test project's gradle. How can I import dependency module automatically when I add my library to test project's gradle?
Is there anyone that can solve this? My library is on binary's maven repository.
I find expert in this scope now.
You need to include your library as a transitive dependency. Your build.gradle should have something like this:
compile('com.example.your.library:0.1.0#aar') {
transitive = true;
}
For example, here is MikePenz MaterialDrawer library:
compile('com.mikepenz:materialdrawer:4.6.4#aar') {
transitive = true
}
Here's another one for the FancyButtons library
compile 'com.github.medyo:fancybuttons:1.5#aar'
Where did these compile lines come from? I ask because I just forked a project and made a slight change, and now I want to use this project in my app, but I don't want to download the project, import module into Android Studio, and then go from there (I haven't had much luck). How can I create a one-line snippet.
Here's the project I want to compile using this method
For the examples your listed, they likely come from jCenter or mavenCentral. Where you get them from is determined from your build.gradle repositories section. You might have something like:
repositories {
jCenter()
}
which is basically saying, when a line like compile ... appears in the dependencies section, go look for the required files on jCenter.
How did the files get there in the first place? The authors of the original projects published their aar files to these repositories. How do you get your modified libraries up there as well? Look up publishing. Here is the help page on publishing to jCenter.
Thing to note is that, you do not necessarily have to publish to a public repository. You can even host your own local repository or even just publish to a local filesystem folder. Which ever repo you publish to, make sure to include that repo in the repositories section of the other project that you want to consume your library from and the dependency will be automatically fetched from the repo with just a compile ... line.
It is possible to easily use third party libraries with gradle. For example, the following allows me to use Retrofit in my app.
dependencies {
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
How does this work? Where does the library come from? In general terms, how would I go about publishing a library so that other people can import it like this?
Note: this is not a duplicate of Publish jar library to bintray using gradle/publish-jar-library-to-bintray-using-gradle. That question was asking a spefic question about one particular way to publish libraries.
Lots of this is answered in this tutorial.
How does this work?
Gradle imports the libraries from a Maven repository. The Maven repository can contain both regular .jar files and regular .aar files.
Where does the library come from?
By default, new versions of Android Studio import from JCenter. JCenter is a Maven Repository run by the company Bintray.
If you look at your Android Studio project's build.gradle, you'll see the following lines
repositories {
jcenter()
}
This tells gradle where it should look when attempting to import com.squareup.retrofit:retrofit:1.9.0.
In general terms, how would I go about publishing a library so that other people can import it like this?
You need to create a Bintray account in order to upload to JCenter since Bintray owns JCenter. Bintray's website is pretty easy to use compared to what Maven Central, the past default Maven Repository used by Android Studio.
After you've created a normal Library module inside Android Studio, you'll need to hand tweak your library module's build.gradle file in order to configure it for Maven. Finally, you use a pre-baked script to upload everything to Bintray.