Gradle: compiling SNAPSHOT library - android

I have this library I want to use, I can install one version, but the developer released a recent SNAPSHOT version, how can I compile it?
I've tried compile 'com.(...):1.4.0-SNAPSHOT without results?

Since SNAPSHOT is a Maven concept, it isn't treated as anything special in repository.
The best way to tell Gradle to check for updated version of a dependency is to flag the dependency as changing. Gradle will then check for updates every 24 hours, this can be configured using the resolutionStrategy DSL.
Override default module caching in Gradle:
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
Then, latest.integration will work with each SNAPSHOT:
dependencies {
compile ('projGroup:projName:latest.integration') { changing = true }
}
For example in your case, projGroup is com.prolificinteractive and projName is material-calendarview.
dependencies {
compile('com.prolificinteractive:material-calendarview:1.4.0-SNAPSHOT') { changing = true }
}
Edit:
Another problem is that bringing latest release on the central repository defined, this repository actually not contain the SNAPSHOT repository where the -SNAPSHOT was located. So that you should add to your gradle repositories section the repository URL to allow download the SNAPSHOT version uploaded.
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}

Related

Cannot resolve github dependency even though my process is correct

Basically the problem is I cannot resolve GitHub dependency even though I added this to Project level build.gradle.
build.gradle (Project)
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
and app level build.gradle
dependencies {
implementation 'com.github.mukeshsolanki:country-picker-android:<latest-version>'
How can I fix this? What is this cause possibly? I already updated to the lastest version of Android Studio.
In the string implementation 'com.github.mukeshsolanki:country-picker-android:<latest-version>' at the app level build.gradle file you must replace <latest-version> substring with the actual version of the library. Currently the latest version is 2.0.1.
So the result string should be this: implementation 'com.github.mukeshsolanki:country-picker-android:2.0.1'

How to use realm 2.2.0-Snapshot

I try to evaluate the performance of the Realm database for a specific project.
Everything works fine at the moment. I just miss one method. I need a function to get the needed space for storing my realm database.
In case of some other databases I can take the size of the files where it is stored in. How can I get the needed space for my specific realm database?
And more important for me is the version. Evertything I tried works just fine with version 0.88.0
I just need to add the following dependency to my modules gradle file.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'io.realm:realm-android:0.80.0'
...
}
If I change this to
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'io.realm:realm-android:2.2.0'
...
}
I got the following error:
Error:(24, 13) Failed to resolve: io.realm:realm-android:2.2.0-snapshot
How can I change to the newest version?
Because of debugging I got version 2.1.0 working for me. Hope that I can copy the classes of the TestProject to my bigger Evaluation Project without getting errors. If not I will report that.
But first, I need some code to get the needed diskspace for storing the whole database. I need this to compare it to other Databases.
To use Realm's SNAPSHOT version, you need to add their snapshot repository in your build gradle.
buildscript {
repositories {
jcenter()
maven {
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependencies {
classpath "io.realm:realm-gradle-plugin:<version>-SNAPSHOT"
}
}
repositories {
jcenter()
maven {
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
To use Realm in your project, you need to apply it as a Gradle plugin (since 0.88.0).
apply plugin: 'realm-android'
For more info, refer to the official documentation: https://realm.io/docs/java/latest/#installation
Remove the -SNAPSHOT part from the version and its actually 2.1.1 is the latest version as for now, so the main part should be
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:2.1.1"
}
}
They really have some issue with the realm-annotations-processor of version 2.2.0-SNAPSHOT (its missing, check here). The latest version they did provide is 2.0.2-SNAPSHOT and thus if you want to use the SNAPSHOT then you should use 2.0.2-SNAPSHOT version.

Making android github project available via gradle

I have created a library project using android studio and uploaded it on Github
What I want to do is, make the project available to anyone wanting to use it with this simple gradle command.
dependencies {
compile 'com.github.myprojectname'
}
How can I do it?
To use a project in github with gradle:
publish it in MavenCentral or Jcenter
use JitPack
In this case add the repo:
repositories {
// ...
maven { url "https://jitpack.io" }
}
and add the dependency like this:
dependencies {
compile 'com.github.User:Repo:Tag'
}
If you want to publish an artifact on MavenCentral, you can read this post.
You should upload your project on maven central or jcenter or on your own repository somewhere on the internet.
Then in the gradle.build your users specify:
repositories {
mavenCentral()
}
or similar and then they specify your dependency
dependencies {
compile 'com.github.myprojectname+'
}

jitpack.io failed to resolve github repo

I have a Github repo and pushed tags on it.
This is my gradle file of my main project.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "dropbox.ric.es.myapplication"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
//mavenCentral()
//jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.rchampa:DropboxHttpConector:1.0.1'
}
But when I sync gradle I have the following error Failed to resolve com.github.rchampa:DropboxHttpConector:1.0.1
Another attempt:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.github.rchampa:DropboxHttpConector:1.0.1'
}
Still failing.
For anyone else that made the simple mistake I made:
Ensure you add the maven { url "https://jitpack.io" } under allprojects instead of buildscript.
Project build.gradle file:
buildscript {
repositories {
jcenter()
// DO NOT ADD IT HERE!!!
}
...
}
allprojects {
repositories {
mavenLocal()
jcenter()
// ADD IT HERE
maven { url "https://jitpack.io" }
}
}
Thanks to Alexander Pacha for pointing that out in a comment above.
Newer versions of Android Studio don't use allprojects anymore.
Open the file settings.gradle and add the repository as shown below:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // <- here we go
jcenter()
}
}
Also remove the code below from the file project's build.gradle, if it is still there:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}}
After a few attempts and thanks to jitpack support now I can import my library hosted in Github as a Android Gradle dependency.
I will provide a a few very useful links:
How setup your java library
https://jitpack.io/docs/BUILDING/#gradle-projects
How check logs of your dependency in jitpack
https://jitpack.io/com/github/USER/REPO/TAG/build.log
In my case
https://jitpack.io/com/github/rchampa/DropboxHttpConector/1.0.3/build.log
I have several dependencies from Jitpack and I encountered this issue after migrating to Gradle 2.
The solution in my case was to change the version in distributionUrl in gradle-wrapper.properties from 2.10 (which was automatically set by Studio when I accepted updating the wrapper version) to the latest one.
Hallelujah I got the problem!
So I realised that PROBLEM is relied on my NETWORK! I can't acces https://jitpack.io/ from my IP that's why nothing was working. Just shared internet from a GSM module(to get a different IP) and problem is gone using #SteveMellross solution
Maybe it can be 0.001% that you have the same problem but if nothing works just try to access https://jitpack.io/ ;)
I hope there is just a firewall or internal router error and my IP is not banned by their service.
Verify that maven { url "https://jitpack.io" } is in allprojects section in build.gradle (Project)
For me I did this
1.Forked the original unmaintained repo
2.Did some changes,created the commit
3.Copied commit hash from commit details page url
eg https://github.com/omkar-tenkale/NavigationTabStrip/commit/9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0
4.Created implementation string from repo url
implementation 'com.github.User:Repo:Version'
Group: com.github.Username
Artifact: Repository Name
Version: Release tag, commit hash or master-SNAPSHOT
More at https://github.com/jitpack/jitpack.io
I used commit hash as Version
implementation
'com.github.omkar-tenkale:NavigationTabStrip:9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0'
5.Now added that in android app module's build gradle
6.But got error Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve...etc
7.Created a link in below format
https://jitpack.io/com/github/USER/REPO/TAG/build.log
In my case
https://jitpack.io/com/github/omkar-tenkale/NavigationTabStrip/9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0/
8.Opened this link in browser
9.Saw something like this
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0-javadoc.jar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0-sources.jar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.aar
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom.md5
NavigationTabStrip-9d097af9fe2167fc0dfc71d2e63d6194b2cebfb0.pom.sha1
build.log
In studio synced gradle again
It worked!
This is far better then downloading repo,importing as module in our app and then using it etc etc.
Whenever you make changes to this forked repo don't forget to update commit hash too!
I meet this problem when I try to import orhanobut/logger from github.
Then I go to jitpack.io and search for the package:
find logger in jitpack
Then I clicked the log icon,and found:
Start: Thu Jan 14 11:56:56 UTC 2016
Git:v1.9
commit 5abbc1563422457d4c23e1a0a412d2b0c7dc334e
Merge: 8ef1e6b 522d44d
Author: Orhan Obut
Date: Mon May 25 11:34:20 2015 +0200
Merge pull request #30 from orhanobut/oo/settings-fix
submodule status:
Run gradle build
Gradle build script
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Downloading https://services.gradle.org/distributions/gradle-2.2.1- all.zip
So this is it,it use gradle 2.2.1-all!
Then I go to my project and change gradle version to 2.2.1 in settings.gradle, everything worked fine!
I'm using Android Studio Arctic Fox 2020.3.1 | Canary 8 and had the issue above.
My repo project is a pure Kotlin project that I want to import into my Android project.
Here are a few steps I did that fixed the issue for me - it could be one of the steps or a combination of them that fixed the issue.
The tag I initially pushed was v0.0.1 but in my build.gradle for the Kotlin project it was version '0.0.1' without the v. So I renamed the tag to 0.0.1 and pushed the tag. #Ricardo's answer above about how to check the JitPack build log was super useful!
Next I ran ./gradlew install on my local machine in the Kotlin repo. This is one of the commands run by JitPack - see the JitPack documentation. When I did this I found this message: Declare the version of Java your build requires.
From that message I decided to specify the Java version. In the Kotlin project build.gradle I added sourceCompatibility = 1.8 and
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
After re-running the command in step 2, the Java version issue disappeared.
I pushed the new version of my Kotlin repo and added a new tag.
In the Android project, I had to add the maven { url "https://jitpack.io" } in settings.gradle. I encountered errors when adding it in the build.gradle files for the app or the root one.
I know this is old but I had this problem recently and I solved it by adding
maven { url 'https://jitpack.io' }
to the settings.gradle(ProjectSettings) under dependencyResolutionManagement{repositories{$HERE}}. I don't know if it is recommended or just a fluke since I am not that well versed yet.

In Android Gradle, is there any way to use local snapshot dependencies?

My Android app is based on Gradle and it just takes ages to build every time. This is due to the number of modules I have. Even if there are no changes in submodules, it keeps rebuilding every sources.
I was wondering if there is any way to convert these modules to local snapshot dependencies as I'm not updating them often?
I'm pretty sure it's possible but I have a very basic experience with gradle and maven so I can't figure out a simple way to do that.
Basically right now I'm listing my dependencies like that:
dependencies {
compile project(':Library:lib1')
compile project(':Library:lib2')
compile project(':Library:lib3')
}
and I'd like to use something like that:
repositories {
local()
}
dependencies {
compile 'com.lib1:lib:SNAPSHOT-1.0')
compile 'com.lib2:lib:SNAPSHOT-1.0')
compile 'com.lib3:lib:SNAPSHOT-1.0')
}
To use local snapshots use the maven-publish plugin. If you use SNAPSHOT in the version (e.g. 0.0.1-SNAPSHOT) you will publish snapshots to your local repository. For the build.gradle for lib1 you should do something like this:
apply plugin: 'java'
apply plugin: 'maven-publish'
project.version=0.0.1-SNAPSHOT
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}
and run the :publishMavenPublicationToMavenLocal target.
In you gradle build file for projects using the library use:
repositories {
local()
}
dependencies {
compile group: 'com.lib1', name: 'lib', version: 'SNAPSHOT-0.0.1', changing: true
}
The 'changing' attribute indicates that not a cached version is used (normally updated once every 24hrs) but always checks for the latest.

Categories

Resources