How can I specify the latest commit version in Gradle - android

I'm using Gradle in my Android project,and I have added some dependencies in build.gradle file.For some reasons,I want to point to the latest commit for one of my dependencies.For example:
dependencies {
...
compile 'com.github.ozodrukh:CircularReveal:1.1.0#aar'
}
I'm specifying CircularReveal's version to be 1.1.0#aar,and I know currently it has fixed some bugs but have not released it yet.How can I specify a commit in Gradle?I know some basics about Cocoapods,and it can be done like this:
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
Can it be done in Gradle? Any help would be greatly appreciated.

You can not do this directly from Gradle, but there are Gradle plugins and tools you can use to achieve this.
You can do this using Jitpack, an external tool. All you need to do is specify Jitpack as a repository:
repositories {
maven {
url "https://jitpack.io"
}
// Define your other dependency repositories, if any
}
Then include your dependency:
dependencies {
compile 'com.github.ozodrukh:CircularReveal:25aeca505d'
// Include your other dependencies, if any
}
You can also use use the gradle-git-repo-plugin from Layer, but I haven't tried this one yet. An advantage(?) of this plugin is that it clones the repository on your local machine and adds it as a dependency from there.

Ugo response is probably the correct one, here's an alternative for some specific cases:
dependencies {
...
compile 'com.github.ozodrukh:CircularReveal:1.1.+#aar'
// or 1.+ or even just +
}
That puts you on the latest version, no matter which one it is. Now, if you repository builds on a CI environment and deploys snapshots to Sonatype or a similar service, you can do
repositories {
maven {
url "https://project.sonatype.io"
}
}
And along with the other change you'll end up in the -SNAPSHOT versions. This behaviour reports warnings on build because your builds will not be reproducible, but that's a given if you're targeting CI versions.

Related

Android Studio: Unresolved reference despite Gradle sync successful after adding third party implementation. Works fine with previous version

I am trying to add this library:
https://github.com/blipinsk/ViewPropertyObjectAnimator
I have added this to my build.gradle file's dependencies:
implementation 'com.bartoszlipinski:viewpropertyobjectanimator:1.5.0'
The Gradle sync is successful after this too.
However when I try to use it:
ViewPropertyObjectAnimator.animate(this#CustomToolbar).topMargin(it).setDuration(200).start()
It keeps telling me Unresolved reference: ViewPropertyObjectAnimator. And I am unable to import as the com.bartoszlipinski doesn't exist when importing.
If I change the library version from 1.5.0 to 1.4.5:
implementation 'com.bartoszlipinski:viewpropertyobjectanimator:1.4.5'
it works fine and import works fine too.
I would prefer using the newer version instead of the old one. Where am I going wrong?
EDIT: I just noticed that even though Gradle sync is successful, it logs a warning:
Failed to resolve: com.bartoszlipinski:viewpropertyobjectanimator:1.5.0 Show in Project Structure dialog Affected Modules: app
And with the older version, I can see the library in the Android Studio's "External Libraries" but it's not there in the newer library version:
Edit 2: I think I figured it out. I came across this:
https://github.com/blipinsk/ViewPropertyObjectAnimator/issues/16
Using custom bintray repo is a bit unusual, and mavenCentral only has up to 1.4.5. Any chance of updating to 1.5.0 on mavenCentral too? Just curious, but technically bintray works well for me atm too
So it seems like mavenCentral doesn't have the updated version.
I recently came across this issue, I added jitpack repository to the settings.gradle file instead of the root file.
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://jitpack.io" }
}
}
Implementation in the build.gradle file was the same.
implementation 'com.github.blipinsk:ViewPropertyObjectAnimator:1.5.0'
I was able to figure this out. I came across this:
https://github.com/blipinsk/ViewPropertyObjectAnimator/issues/16
Using custom bintray repo is a bit unusual, and mavenCentral only has up to 1.4.5. Any chance of updating to 1.5.0 on mavenCentral too? Just curious, but technically bintray works well for me atm too
So it seems like mavenCentral doesn't have the updated version. As a workaround, I added
maven { url "https://jitpack.io" }
to
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
and then change the dependency to:
implementation 'com.github.blipinsk:ViewPropertyObjectAnimator:1.5.0'

Add specific artifact to a Gradle project (Androind)

I need to use, in an Android project using Gradle, a specific artifact of a repositorty.
The artifact is kotlinx-serialization-cbor version 0.20.0 (available in the readme) from the kotlinx serialization GitHub project.
I don't know where and how to add this specific dependencies. (Probably I should add something in "gradle.build" file, the one marked as Project:YourProjectName or the one Module:app
Any help?
The README in the root of the github project explains how to add the plugins to your project. So long as your gradle install is up to date you just need to add a section at the top of your app level build.gradle like this:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.70' // or any other kotlin plugin
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.70'
}
In the same file make sure jcenter is included in your repositories:
repositories {
jcenter()
}
Then again in the same file add the basic library, as well as the cbor library to the dependencies:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // or "kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0" // JVM dependency
implementation "org.jetbrains.kotlinx:kotlinx-serialization-cbor:0.20.0"
}
You should probably look here https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-serialization-cbor/0.20.0 and copy-paste from Gradle/Maven etc (build system of your choice).

How to obtain firebase libraries, e.g. firebase-messaging-9.4.0.jar

I am trying to do an automated android build in a local network segment (ie. without access to public jcenter or maven repositories). In order to do that I need to provide all dependencies in a local maven repository which is referenced from the root build.gradle. (NB: if I use the android-maven-plugin instead of gradle the situation is the same).
This works fine, only I have difficulties locating the firebase libraries like firebase-core-9.4.0.jar or firebase-messaging-9.4.0.jar. According to the gradle console output they are searched in a location
<server>/com/google/firebase/firebase-messaging/9.4.0/firebase-messaging-9.4.0.jar
This location does not exist in the public jcenter or maven repositories.
Does anyone know where to find them?
edit: I have observed Android Studio on empty caches using Wireshark (using http for the jcenter repository). The results are rather mysterious. It issues a GET request for
http://jcenter.bintray.com/com/google/firebase/firebase-messaging/9.4.0/firebase-messaging-9.4.0.jar
This request is redirected to
http://repo.jfrog.org/artifactory/libs-release-bintray/com/google/firebase/firebase-messaging/9.4.0/firebase-messaging-9.4.0.jar?referrer
The latter GET request results in HTTP 404 as the repo.jfrog.org repository has no content in the firebase-messaging/ directory. However, Android Studio extracts the jar files in the build directory and continues to build the project.It is unclear, where the jar files come from.
You can show all librarys in the oficial support.
https://firebase.google.com/docs/android/setup
Found this link, hope this help
https://github.com/unity-plugins/Google-Firebase-SDK
According to this, you should add to you build.gradle:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.1'
and that to your app/build.gradle:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:11.8.0'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Update 2020
Firebase aar are now available on maven repository at https://mvnrepository.com/artifact/com.google.firebase
For example, firebase-core aar is at https://maven.google.com/com/google/firebase/firebase-core/17.4.4/firebase-core-17.4.4.aar

How to publish an Android library as a Maven artifact on Bitbucket?

I'm trying to publish an Android library as a Maven artifact on a Bitbucket repository, starting from this article that was linked in an Android Weekly newsletter issue some time ago. The article describes how to perform publication and how to link the published artifact from another Android project. However, I have not even managed to make the publishing part to correctly work.
Currently, this is the relevant content of the build.gradle file belonging to the library project:
apply plugin: 'maven'
allprojects {
repositories {
jcenter()
maven {
url "https://raw.github.com/synergian/wagon-git/releases"
}
}
}
configurations {
deployerJar
}
dependencies {
deployerJar 'ar.com.synergian:wagon-git:0.2.5'
}
The relevant parts of the build.gradle file of the library module in the project are as follows:
apply plugin: 'maven'
uploadArchives {
configuration = rootProject.configurations.archives
repositories {
configuration = rootProject.configurations.deployerJar
mavenDeployer {
pom.groupId = 'com.example'
pom.artifactId = 'example-library'
pom.version = '1.0.0'
repository(url: "${bitbucketUrl}") {
authentication(userName: bitbucketUsername, password: bitbucketPassword)
}
}
}
}
where bitbucketUrl, bitbucketUsername and bitbucketPassword are included in the gradle.properties file at the root of the project.
So, what's the problem? When I run the uploadArchives task from Android Studio, Gradle shows that the operation has been performed successfully. But nothing appears on the Bitbucket repository.
Nothing is also written about the structure of that repository, except on Wagon Git's website (calling it documentation seems a little bit of a stretch to me) where, given repository URL of the form
git:releases://git#github.com:synergian/wagon-git.git
it is said that releases represent a branch of the repository. I obliged that part about the structure, even tried to add a repository directory (to mimick the local Maven repository on my machine) but with no luck, and, above all, no clue.
An even more severe issue is that, while I was experimentating with different configurations, I noticed I had the repository URL wrong; however, never, ever, during execution, Gradle noticed the error, and warned or informed me with a suitable message. This lead me to suspect that it wasn't even preparing the artifact to upload, nor trying to connect to Bitbucket, but I was not able to find any pointer as to understand why.
Finally, an even more strange thing happens: when I comment out the line:
configuration = rootProject.configurations.deployerJar
in the module build.gradle file and I run the uploadArchives task, Gradle stops with an error saying that it is unable to find a proper wagon to manage the git protocol, which is expected; however, in the process, the Maven artifact appears in the local repository on my machine. So, by making the publishing process crash, at least I am able to work locally with my library from other projects depending on it, through Gradle management of Maven-like dependencies.
What am I doing wrong?
Fails silently, turn on --info. Probably the biggest hurdle in debugging the problem. For some reason, the folks who wrote the wagon-git deployer decided to write out error messages at the info level. So gradle fails silently without showing you any error messages. This is one of the messages I got with --info turned on:
[INFO] [git] fatal: 'git#bitbucket.org/foragerr/mvn-deploy-test.git' does not appear to be a git repository
This is apparently a fatal error, but as far as gradle is concerned, everything is fine and dandy. Once you start reading these error messages, we can make real progress!
git url: The git URL as outlined here, starts with git:. The wagon-git deployer is activated when the url starts with git:. It is possible to use a https: url, but maven plugin will use an internal deployer rather than wagon-git. To explicitly use wagon-git, the url has to start with git:
repository(url: "git:releases://git#bitbucket.org:foragerr/mvn-bitbucket-deploy-test.git")
where
releases is branch
foragerr is bitbucket username
mvn-bitbucket-deploy-test is bitbucket repo
Authentication: wagon-git uses SSH to connect to bitbucket. You need to setup both git on the local end and bitbucket repo on the remote end to use SSH.
Setting up SSH for git (I recommend not using a passcode, less secure, but convenient for automated deployments)
All Set! deploy to your bitbucket repo using gradle uploadArchives. See example repo here.
Sample build.gradle:
group 'net.foragerr.test'
version '1.2-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = 1.5
repositories {
mavenCentral()
maven {
url "https://raw.github.com/synergian/wagon-git/releases"
}
}
configurations {
deployerJar
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
deployerJar "ar.com.synergian:wagon-git:0.2.3"
}
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployerJar;
repository(url: "git:releases://git#bitbucket.org:foragerr/mvn-bitbucket-deploy-test.git")
}
}
Here is all you need to do, you even need to use the git protocol (this examples show how to use the HTTPS instead):
1) create an app password for your app in Bitbucket
https://bitbucket.org/account/user/YOUR_USERNAME_HERE/app-passwords
2) inside build.gradle:
apply plugin: 'java'
apply plugin: 'maven'
// artifact --> rootProject.name at settings.gradle <--
// DOWN HERE just add your artifact INFO
group = 'br.com.fora.temer'
version = '0.1-SNAPSHOT'
description = """Diretas Ja"""
dependencies {
// your dependencies goes here, like this -->
// compile group: 'br.gov.governo', name: 'golpista', version:'2.0'
}
apply from: 'uploadArchives.gradle' // --> deploy configuration
3) inside uploadArchives.gradle (you need to create it):
configurations {
deployerJars
}
dependencies {
deployerJars "ar.com.synergian:wagon-git:0.2.5" // plugin
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
configuration = configurations.deployerJars
repository(url: "git:releases://https://YOUR_USERNAME:YOUR_APP_PASSWORD#bitbucket.org/YOUR_COMPANY/repo-release.git")
snapshotRepository(url: "git:snapshots://https://YOUR_USERNAME:YOUR_APP_PASSWORD#bitbucket.org/YOUR_COMPANY/repo-snapshot.git")
}
}
allprojects {
repositories {
mavenCentral()
maven { url "https://raw.github.com/synergian/wagon-git/releases"}
}
}
To deploy use:
gradle uploadArchives
TIP: beware the order of the entries... if you change it, it will break everything.
I know the question is old, but there isn't a lot of information on the topic, so I guess it is the right place to add some clues. I faced the same problems, there seemed to be no way to get it working. So there are some clues which might help:
As already been said, this whole maven plugin wagon thingy uses SSH to connect to repository (Bitbucket in my case). So you need to check a few things:
that Bitbuchet knows about your SSH key.go to your profile settings(not repository settings!) -> SSH keys and put there your public key received by keygen. There is instruction in the little 'insert key' window on Bitbucket to help you out.
that you have added your private key generated by keygen to your ssh agent (type ssh-add ~/.ssh/id_rsa fot Linux and probably mac)
also add credentials to your repository element:
repository(url: 'git:releases://git#bitbucket.org:gendalf/repo.git'){
authentication(userName: "gendalf", password: "swordfish") }
That plugin won't get confuzed about your output file. When I started to try uploading my library to the repository, I had flavors in it, so plugin didn't know which variant to select and selected nothing (apparently).
this stuff doesn't work with flavors as far as I know. So if you have flavors in the library which you are posting to private repository... consider getting rid of flavors. You probably don't need them anyway.
if you tried other publishing plugins before trying out maven (for example maven-publish), comment out all the script related to other stuff or delete it. My gradle was confused because of the additional scripts.
Consider trying out this https://jeroenmols.com/blog/2016/02/05/wagongit/ solution. It's what I used to finally publish, although it is pretty confusing about checking out from your just-created repository. Don't check out. Create the repository and publish right after that.
I hope this helps.

Studio failed to download library from gradle repository

I already saw this question, but it is not helping me. First of all, I tried to add google play services in my project using:
dependencies{
compile 'com.google.android.gms:play-services:6.5.87'
}
It was showing me error:
Then I updated my studio to 1.0.1 and gradle to 1.0.0. And then I again synced the project with gradle. And it worked! It showed me another option despite of two options shown in above screenshot. It was "Install the library"(something like that). I clicked it and it popped up a dialog, and I installed the library(it was like downloadind using SDK manager and not like gradle downloads).
Now, I tried to download this library using:
compile('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
}
And it gives me error:
My android repository is updated:
Also, my internet connection is working fine. I tried to sync project many times, but same error all the time. I am not running gradle in offline mode:
How to fix this? And what is the permanent solution? And why is all this happening?
I found this question: Studio failed to download library from gradle repository which describes the exact same error, and that question had this bit of build script that you need to add to the build file that has the dependency statement in question:
repositories {
maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
When I do this, it works for me.
As to the general question of why this happens (and the better question of why the solution is different for different libraries):
Gradle, the build system that Android Studio uses, has the ability to automatically download library dependencies from the Internet. By and large this is a big boon for developers, because instead of having to manually download archive files, put them in the right place in your project, check them into source control, and repeat the process for new versions, now you just have to add a line of build script and the build system takes care of the housekeeping for you. The major downsides are Internet connectivity woes, which affect different developers to different degrees, and some added confusion about what it means when you get an error.
How does Gradle know where to download dependencies? Most Gradle build scripts contain a block that looks like this:
repositories {
jcenter()
}
or it may be mavenCentral() instead of jcenter(). This tells the build system to look in the JCenter or Maven Central global repositories (and JCenter is in a simplistic way of thinking about it a value-added mirror of MavenCentral); these contain archives of many versions of many, many, many libraries and are very convenient to use.
You can specify other repositories as well. This swipelistview library hasn't been uploaded to Maven Central, so the developer has made a repository for it available via a URL: if you add that URL to your repositories block, it will look for it there.
I was worried about the fact that you're accessing a SNAPSHOT version of the library -- these are supposed to be unpublished by definition. But adding a dependency on the snapshot version of the library in my test project worked for me, and looking around that URL in a web browser reveals that there's only a "1.0-" (trailing dash included) version of the library, so there's some subtletly there I'm missing; if you know more, please edit my answer or comment.
In any event, there are a couple caveats to this explanation. Some libraries aren't on Maven Central or on any Internet-accessible archive (at least they're not officially published by Android), but are instead published as part of the Android SDK download and maintained via the SDK manager. The Android support libraries and Google libraries fall under this category. If you get errors about those not being found, you have to fix it via the SDK manager.
How does the build system know to look in the SDK for those, since you didn't tell it via the repositories block? This behavior is hardcoded into the Android Gradle plugin.
The other caveat is that there's a detail that trips up a lot of people, which is that you actually have two repositories blocks, though with the usual Android Studio setup they're often in different files. One is in a buildscript block, which usually lives in the top-level build.gradle file and looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
The other often also lives in the top-level build.gradle, but you can augment it with another block in your module's build.gradle file. The top-level one looks like this:
allprojects {
repositories {
jcenter()
}
}
and a module-level one would look like one of the previous examples in this answer. What do all of these mean?
The buildscript block tells Gradle where to find build system plugins. These are plugins that enhance the functionality of the build system itself but don't say anything about your actual project. In Android projects, the Android Gradle plugin is in this category, and unlike the Android/Google libraries, this one does live on Maven Central. The repositories block (in coordination with the dependencies block, which is not the same as the dependencies block for your project, keep reading) in buildscript tells the build system where to go look for these plugins.
The allprojects block in the top-level build file tells the build system to apply the bit of contained script to all build files in the project. In this example, it's telling it to add a repositories block pointing to JCenter to all subprojects. This is a convenience so you don't have to copy/paste it into multiple build files in your modules.
In your modules, you also have a repositories block, which in conjunction with the allprojects thingy, tells the build system where to go to get library dependencies for your project, as was previously discussed.

Categories

Resources