Add Github Library as Dependency to Android Studio Project

Android Studio - add ownCloud library from GitHub

I have tried to import this library as a module but found error while importing:
Error: Module name is not valid

So I tried to find a solution and here it is:

1. Download library from Github here.

Sample Image

2. Unzip library.

3. Start Android Studio.

4. Follow to File -> New -> Import Module .

Sample Image

5. Go to the path where your extracted library is located and select it.

Sample Image

6. Uncheck other modules and add 'androidlibrarymaster' described in below picture.

Sample Image

7. Add Gradle dependency and Its Done!

  compile project(':androidlibrarymaster');

Add GitHub library as dependency to Android Studio project

It will work when you put this line in your project build.gradle, in the dependencies section:

compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'

Also, add:

repositories {
mavenCentral()
}

So:

repositories {
mavenCentral()
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}

Gradle will download the needed resources automatically for you.

How to include github library to Android Studio project

If by "it doesn't work" you mean you don't have access to any of its classes in your code, make sure you also have the JitPack maven repository in your Project-level Gradle build file.

// Include repositories here for which dependencies can be retrieved from.
repositories {
maven {
url "https://jitpack.io"
}
// For example:
// google()
// jcenter()
}

If you do have access to the library in your code, and the library itself is not working as expected, I would check its github issues page for help.

As a last resort, you can pull the GitHub repository and compile the library yourself into an .AAR for your project.

Add github library as dependency not working

This does not look like it is a valid library.

Within the app/build.gradle it references

apply plugin: 'com.android.application'

a library should be

apply plugin: 'com.android.library'

If you really want to use this I would suggest getting the code and creating your own library module within your project.

how to import your own github forked library into android studio

I think the accepted answer is outdated. There is actually a really easy way to do this nowadays: jitpack.io

All you need to do is.

  1. add in your root build.gradle at the end of allprojects repositories:

    allprojects {
    repositories {
    ...
    maven { url 'https://jitpack.io' }
    }
    }

  2. Add the dependency in your app build.gradle:

    dependencies {
    implementation 'com.github.User:Repo:Tag'
    }

If you don't have any releases/tags, you can also just do com.github.User:Repo:branchname-SNAPSHOT to build from the latest commit on that branch.

How to use my github repository as dependency in android?

Uploading your files to GitHub will not make your code to be available to be included as a dependency. First, make sure that your project is a library, and follow these steps to upload your library to Bintray's jcenter() repository so that your library can be included as a dependency.

How to Add My Android Library's Dependencies in Github Packages?

  • The library file (aar) shown in the tutorial will not include the transitive dependencies.
  • For Maven repos, Gradle will download the dependencies using the pom file which will contain the dependencies list.
  • In the project shown in the tutorial the pom file does not generate the nested dependencies list. Either you have to specify the dependencies in your project or you’ll have to modify the code to generate a pom file with dependencies included.
  • Use the below code and update your build.gradle file inside the Android library module to generate the .pom file with information about dependencies included.

publications {
bar(MavenPublication) {
groupId getGroupId()
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies
final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)
if (!dep.transitive) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }

configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }

configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
}
}
}

the above code is referred from Publish an Android library to Maven with aar and source jar



Related Topics



Leave a reply



Submit