70

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.

Ricardo
  • 7,921
  • 14
  • 64
  • 111
  • 15
    Just in case someone else falls into this pitfall: Make sure to include the `maven { url ... }` into the `allprojects` block and not into the `buildscript` block. – Alexander Pacha Jun 27 '16 at 12:04

10 Answers10

175

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.

tvkanters
  • 3,519
  • 4
  • 29
  • 45
SteveMellross
  • 3,404
  • 2
  • 20
  • 18
  • 3
    didn't work for me, keep having `Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.any_jitpack_lib` – Choletski Jun 25 '18 at 10:12
  • 1
    @Choletski When you first request this dependence, Jitpack is building it, so you should wait until it finishes, and click `try again` in android studio. – LeeR Jan 03 '19 at 12:53
  • 2
    for newer android studio projects, this block has been moved to settings.gradle and we have to add it there. This was so much helpful, i was pulling my hairs for why my repos not able to fetch my lib. thankyou very very much!!!! – ansh sachdeva Aug 30 '21 at 05:29
23

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" }
}}
Torben
  • 6,317
  • 1
  • 33
  • 32
Nikhil Soni
  • 701
  • 7
  • 12
19

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
Ricardo
  • 7,921
  • 14
  • 64
  • 111
10

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.

SqueezyMo
  • 1,606
  • 2
  • 21
  • 34
3

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.

Choletski
  • 7,074
  • 6
  • 43
  • 64
  • This is the kind of thing that is immediately solved by proper error messages. Probably why this questions has so many different answers, because no matter what happens, the only error you get is "Could not find" which could mean literally anything – Recessive Jan 17 '23 at 02:06
2

Verify that maven { url "https://jitpack.io" } is in allprojects section in build.gradle (Project)

Miha_x64
  • 5,973
  • 1
  • 41
  • 63
Bacar Pereira
  • 1,025
  • 13
  • 18
2

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
  1. 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!

Omkar T
  • 755
  • 8
  • 19
  • Please note that I didnt add the /build.log as per my own instructions in end but it somehow worked – Omkar T Sep 21 '20 at 12:01
  • I am with this exact same situation and I tried different versions of your answer. At some point I saw the dependencies being downloaded by Gradle. But the dependencies seem to be non existent. No classes from the dependency appear. – Delark Jan 22 '22 at 23:15
  • @Delark maybe try with a different tag? works sometimes – Omkar T Jan 23 '22 at 19:32
0

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!

Castle
  • 53
  • 1
  • 1
  • 3
0

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.

  1. 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!
  2. 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.
  3. 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"
    }
    }
  4. After re-running the command in step 2, the Java version issue disappeared.
  5. I pushed the new version of my Kotlin repo and added a new tag.
  6. 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.
ATutorMe
  • 820
  • 8
  • 14
0

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.

Elikill58
  • 4,050
  • 24
  • 23
  • 45
maestro
  • 1
  • 1