I want to compile the following library in my project in build.gradle:
https://github.com/theDazzler/Android-Bootstrap
It is forked from https://github.com/Bearded-Hen/Android-Bootstrap, but no documentation in the repository explains how to include in in project.
I tried something like this:
compile 'com.theDazzler:androidbootstrap:+'
but gradle failed and shows error that library not found.
Edit: Can anyone fork it and/or publish it?
This fork isn't published in the maven central repo.
Then you can't use an import like compile com.theDazzler:androidbootstrap:+
You have to:
- clone this library locally as a module in your project
Clone the
https://github.com/theDazzler/Android-Bootstrap/tree/master/AndroidBootstrap folder in your root/module1 folder.
root:
module1
build.gradle
app
build.gradle
settings.gradle
Change your settings.gradle file in
include ':module1'
include ':app'
In your app/build.gradle file you have to add:
dependencies {
// Module Library
compile project(':module1')
}
Finally in your module1/build.gradle you have to check the level used for gradle plugin.
EDIT 31/10/2015:
You can use another way to add a dependency with a github project,using the github repo and the jitpack plugin
In this case you have to add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
It can be simply done by using Jitpack.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
for eg: compile 'com.github.sachinvarma:JcPlayer:0.0.1'
The issue is: has that theDazzler/Android-Bootstrap been published anywhere? In any gradle/maven repo?
The usual build.gradle file has a section repositories which should reference that maven repo.
So it is possible any project using theDazzler/Android-Bootstrap should reference the repo where it is published, And with a project like gradle-git-repo-plugin, you could publish that fork on its own release section to publish it.
That task gets wrapped into a publishToGithub task that handles committing and pushing the change. Then you can run
gradle -Porg=layerhq -Prepo=gradle-releases publishToGithub
You can also run
gradle -Porg=layerhq -Prepo=gradle-releases publish
to stage a release in the local github repo and commit it manually.
Hi i had the same issue but with a different project :)
So first you should have the library code on your dev machine.
Next steps are: add a new file called settings.gradle to the root of your project if its not already there.
inside add this:
include 'AndroidBootStrap'
project('AndroidBootStrap').path = "path/to/AndroidBootstrap/AndroidBootStrapLibrary"
also add include for your root project if its not there.
Inside your build.gradle file add
compile project(':AndroidBootStrap')
to add the dependency.
How your folder Structure should look:
root
YourProject
settings.gradle
YourProjectModule
build.gradle
AndroidBootStrap
AndroidBootStrapLibrary
build.gradle
In the end the files look like this:
settings.gradle:
include 'AndroidBootStrap'
project('AndroidBootStrap').path = "../AndroidBootstrap/AndroidBootStrapLibrary"
include 'YourProjectModule'
build.gradle (YourModule):
...
dependencies {
...
compile project(':AndroidBootStrap')
}
Maybe its necessary to modify some point but i hope you get the idea!
Cheers
Neri
Related
How to add your own project to the gradle so other users can use it as a dependency? E.g.
dependencies {
compile 'com.myDomain.myProject-v1.0'
}
Create a library project. See this.
Push it to github. (Optional).
Publish it to bintray. See this tutorial.
Assuming that Some Other Folder is a gradle project you could add something like the following to your settings.gradle file:
include ':module1'
project(':module1').projectDir = new File(settingsDir, '../Project B/Module 1')
You have to push it in a maven repo, private or public.
You can check for example the bintray repo (jcenter)
You have to make it available in a repository. A very simple one is JitPack.
Host your lib on Github
Add JitPack in repositories
Add the dependency compile 'com.github.User:Repo:Tag'
Sample:
repositories {
...
maven { url 'https://jitpack.io' }
}
...
dependencies {
compile 'com.github.User:Repo:Tag'
}
Full documentation
Please you need to study about how to make library (module) on android studio, what is jcenter, what is maven center and also study about bintray.com.
I have downloaded a lot of libraries from Github. When I want to add it in android studio, there's no .jar file in every library I have. Why is it that it has no jar file ? How do I add those libraries in android studio?
Whenever possible, you should find the correct line to add to the dependencies block in your build.gradle file. For example, look at the README for the Boom Menu library which you mentioned in your comment. Under the heading Gradle & Maven, you see
compile 'com.nightonke:boommenu:2.1.0'
Add this line to the dependencies block in build.gradle, sync Android Studio, and then use the library as you wish.
libraries from GitHub... Example is the Boom Menu library
This one? ... Well, you're just not reading the documentation
Otherwise, if there isn't a BinTray dependency.
This is exactly what JitPack is for
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
Regarding your questions
Why is it that it has no jar file ?
Because GitHub isn't meant for storing (potentially large) binaries of compiled code, and many Android libraries prefer BinTray over GitHub releases.
How do I add those libraries in android studio?
You could clone them directly into your project
app/
build.gradle
library/
build.gradle
settings.gradle
build.gradle
In settings.gradle
include :app, :library
In app/build.gradle
dependencies {
compile project(":library")
}
Whenever I add a android library-project as module to my Android Studio project, the sources get copied to the Android Studio project folder.
Is there a way to solve it like in eclipse, where there is only one copy of library project, any many projects can reference it?
You have different ways to achieve it:
using a local module referring the right path
adding an aar file
using a maven repo
CASE 1:
Using gradle and a local library, inside a project you can refer an external module.
Just use:
Project
|__build.gradle
|__settings.gradle
|__app (application module)
|__build.gradle
In settings.gradle:
include ':app'
include ':myLib'
project(':myLib').projectDir=new File('pathLibrary')
In app/build.gradle:
dependencies {
compile project(':myLib')
}
Pay attention to myLib.
You have to use the path of the library inside the other project, not the root of the project.
CASE 2:
Compile the library module, get the aar file, and then add to the main project:
Add the folder where you put the aar file as repository:
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
Then add the dependency:
dependencies {
compile(name:'nameOfAarFile', ext:'aar')
}
CASE 3:
Another way is to to publish your module into a maven repository.
In this way, just use:
dependencies {
compile ('mypackage:mymodule:X.Y.Z')
}
I would compile your shared code as library project. So you will get an aar file which you can reference.
To create that Android Archive you need to build the project as a release build with this command:
gradlew aR
After that you have a file called <modulename>-release.aar this file is located in <projectroot>/<modulename>/build/outputs/aar. I rename those files to <modulename>.aar then you can put it into your lib directory of your module.
When done you can reference it from the module where you need it like this:
compile(name:'<modulename>', ext:'aar')
This also speeds up the build time since you don't need to compile the project anymore.
First of all, I explain my project setups. I use the words Project/Module as used in Android Studio.
I have a setup of my projects like following:
LibraryProject => a project that just groups my libraries, that I use in other projects, if necessary
BackupLibrary (Module)
DatabseLibrary (Module)
MainUtilityLibrary (Module)
DialogLibrary (Module)
MyProject1
App (Project)
DialogLibrary (Module, referenced from DIRFFERENT project)
My Project1 now looks like following:
1) I reference the module from the other project, that I want to use (done in settings.gradle (Project Settings) file:
include ':app'
include ':dialogLibrary '
project(':dialogLibrary ').projectDir = new File(settingsDir, '../LibraryProject/DialogLibrary ')
2) I add the foreign library module as a dependency to my app's build.gradle:
dependencies {
compile project(':dialogLibrary ')
}
My LibraryProject looks like following:
I add the repository and the dependency directly to the module's `build.gradle' (this is enough to build the module on it's own without a problem):
allprojects {
repositories {
maven { url 'https://dl.bintray.com/drummer-aidan/maven' }
}
}
dependencies {
compile 'com.afollestad:material-dialogs:0.7.5.2'
}
Problem
The setup so far does not work for MyProject1. I have to add maven { url 'https://dl.bintray.com/drummer-aidan/maven' } to MyProject1 as well, the compile project(':dialogLibrary ') is not enough. I have to add the dependency that should somehow be inherited from the LibraryModule to MyProject1 Project build.gradleagain like following:
allprojects {
repositories {
mavenCentral()
maven { url 'https://dl.bintray.com/drummer-aidan/maven' } // com.afollestad:material-dialogs
}
}
Otherwise, i can't compile my project. This way seems like doing something twice that probably can be done automatically. But how? This way, whenever I include a module from my LibraryProject, I have to check if I need an additional maven repo...
I think it has to do with the fact that Gradle has no knowledge of the LibraryProject's settings.gradle file while building MyProject1. So it includes the dialogLibrary as if it is a normal subproject of it's own. This explains the reason why the Maven repo is not know to MyProject; LibraryProject's configuration has not been loaded.
Maybe you can include the dialogLibrary through the LibraryProject? Although I did some testing and could NOT get it to work. It probably has to do with a limitation of Gradle. There is a StackOverflow post about multiple settings.gradle files here.
A work around could be to build the Modules of the LibraryProject and use them instead. For example build the DialogLibrary to a jar, upload it to a Maven repository and than in your App project just include DialogLibrary as normal dependency (don't forget to include the Maven repo).
I'm trying to use the ShowcaseView project in my app but can't get the project to build.
when I run 'gradle clean installDebug' I get the following error:
A problem occurred evaluating root project 'hows-it-going'.
Could not find method compile() for arguments [project ':ShowcaseView'] on root project 'hows-it-going'.
I'm using gradle 1.11 and Android Studio 0.54.
I've downloaded the source, and imported the project using file -> Import module -> ShowcaseView
which makes my project structure like:
-project
--app
--ShowcaseView
my settings.gradle file looks like:
include ':app', 'ShowcaseView'
and in my project level build.gradle I have the following:
dependencies {
compile project (':ShowcaseView')
}
Any help with how to include this properly would be much appreciated. Thanks.
The latest version of ShowcaseView is available as a .AAR dependency. To use it, add:
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
To your build.gradle file and, under the dependencies block, add:
compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT'
I'll get a stable, non-snapshot, version out soon.
It should actually be
compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT#aar'
That way Maven will use .AAR file
I recently just added ShowcaseView to an Android Studio project, and I hope this can push you in the correct direction.
My file structure looks something like this:
project
app
build.gradle
libraries
showcase
build.gradle
settings.gradle
Add the files from the library
folder
of ShowcaseView to the showcase directory in the libraries
directory.
Add the showcase directory as a module to your project.
Change your app's build.gradle file to include:
dependencies {
compile project(':libraries:showcase')
}
Change your settings.gradle to include:
include ':libraries:showcase'
Sync Project with gradle files
This StackOverflow answer goes over how to do this is much more detail if you have any troubles, but this method works for any library.
The compile dependency on ShowcaseView should likely be defined in app/build.gradle, not in the root project's build.gradle. Unless a project explicitly (configurations block) or implicitly (by applying a plugin such as java) defines a compile configuration, it won't have one, and an attempt to add a compile dependency will result in the error you mentioned.
I added this in build.gradle and it worked
compile 'com.github.amlcurran.showcaseview:library:5.4.3'