I don't have any experience in MAVEN, gradle or anyother build system. I'm working in Android Studio basically and I want to add few jars (and also their source). But the jars are hosted in maven repo. I can download the jars and directly add to the lib/ folder. But then, I don't know how to attach the sources. So what is the correct way to find add those jars via gradle in Android Studio? Thanks!
Configure maven repo:
repositories {
mavenLocal()
mavenCentral()
}
Then add appropriate dependencies in:
dependencies {
compile 'com.google.guava:guava:17.0-rc2'//e.g.
}
Related
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")
}
I wanted to create react-native wrapper around android sdk of zoom.us (they provide video conference feature through that), I have created a git repo using their sdk https://github.com/manjeets12/ZoomApiWrapper, but problem is that they only provide .aar sdk and it is giving me error project with path ":sdkName" could not be found in project ':react-native-zoom-api-wrapper'
I tried to use many solutions liking putting .aar files within libs folder and compiling from there or using flatDir options, as they don't provide any maven repo alternative, I am not sure how should I proceed in using this
So I've found a solution:
My aar-name is: 'my_name.aar'. You need to add this file to the libs folder in the root of your android folder (same level as your build.gradle).
Your build.gradle file has to contain this:
dependencies {
compile(name:'my_name', ext:'aar')
}
repositories {
flatDir {
dirs 'libs'
}
}
Your android project should compile then. Next step is to integrate the library to react-native.
npm install --save your_project
react-native link your_project
And finally add this to your android/app/build.gradle
repositories {
flatDir {
dirs "../../node_modules/your_project/android/libs"
}
}
For a working project see this git: https://github.com/transistorsoft/react-native-background-geolocation/blob/master/docs/INSTALL-ANDROID-RNPM.md
I have a legacy eclipse Android project. The classic old way without gradle.
Suppose I found a library I want to integrate with, for example 'commons-codec', than quoting from gradle manual https://docs.gradle.org/current/userguide/organizing_build_logic.html#sec:external_dependencies, I need to paste the below in my gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
}
}
Now my eclipse project does not use gradle.
The Question: Is there a way to get the binary lib & integrate with it in eclipse (something similar to download the library's jar and add it)? I know this question is bizarre since I need the jar to be in the repository, but I want to be sure I'm not overlooking anything.
Many Thanks!
If you're just using a jar, you can include it in the libs folder of the Eclipse project. But that's code only. If there's resources in the library, you'd need to build an Android Library project out of it and include that in your project. Which I'm not sure how you'd do without code.
If you are having .jar file the simply right click on your project then
Properties-->Java Build Path-->Libraries-->Add Jar/ Add External Jar--> Apply
And if you are having library in your workspace then
Properties-->Android-->Add-->locate your library-->Apply
How can I add library project on my new project which is made by Android Studio ?
I want to test open source project(HoloGraphLibrary) so made new Project on Android Studio.
here is the project structure(Project name is Test44Project and Module name is Test44)
Test44Project
- .idea
- gradle
- Test44
- build.gradle
- Test44Project.iml
- else
download HoloGraphLibrary, copy and paste into Test44Project Folder.
finally i got project structure like this.
Test44Project
- .idea
- gradle
- HoloGraphLibrary
- Test44
- elses
and modified .iml, build.gradle and Etc. for build and run.(finally it can build and run on my device)
This is correct??
When I want to add library project to my project, always copy and paste library on my project folder?
I don't understand...
Can i get example project(using library project) which is following gradle project structure?
Ya you are correct( No need to update .iml files only build.gradle and settings.gradle) but this not only the way for adding dependencies in gradle. The method you are following should only be used, if the library you want to use don't have maven dependency.
For example actionbarsherlock library has its maven dependency, In such cases no need to download the whole library and add it as as module in your project, instead add the maven gradle dependency in your module's build.gradle file like
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock-i18n:4.4.0#aar'
}
That's it.
Gradle supports both Local and Maven repository, The above example is of maven repository. Where adding support libraries are the example of Local repository, In which you don't need to add Jars in your libs folder and add them in to Build Path instead you can use
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
This is not in maven central repository. It is located in your sdk directory. You can find it in SDK/extras/android/m2repository or if you can download it from SDK Manager> Extras > Support Repository.
Here is a sample project you can have a look for the same. https://github.com/pyus-13/TesstApp
You can add maven dependency from File > Project Structure > Dependencies add green "+" button and choose Maven Dependency
I am trying to use this library [1] in an Android project either with Android Studio or with ADT. But it doesn't work at all. In ADT I don't know how to handle gradle stuff and in Android Studio, when I try to "Import Project", I get the error "Could not find com.google.android.gms:play-services:3.1.36.
(don't have enough reputation to post picture, it's on imgur with xswZ3.jpg)
I am not familiar with gradle and I only have a vague idea of what it does but all I want is to use something like BubbleIconFactory f = new BubbleIconFactory(this) in my own project.
Any help is appreciated!
[1] https://github.com/googlemaps/android-maps-utils
Perhaps your problem is needing the repositories outside of the buildscript block.
The repositories internal to the buildscript is for managing the gradle dependency itself, I believe. Here's how I resolved my problem with google-maps-utils as a library dependency. Hopefully this helps. I included my maps and support-v4 libs too.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Add the following dependency to your Gradle build file:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.2+'
}
You'll need to install the "Google Repository" from the Android SDK manager.
See demo/build.gradle for an example.
You can, of course, copy the library directory and use it like any other Android library project.
Let me know if this helps!
Chris
Steps:
First File>Project Structure>Click Plus Button >Import Graddle Project>Select the file(library folder) from the location where downloaded>CLick Ok.
Add this code to dependencies to that app module build.gradle file(remember there are two build.gradle files) :
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Copy gradle.properties file contents of that Android-maps-util Library project app(found inside that project library folder) TO
gradle.properties file of your project(Simple copy and paste of content to the editor).
Click Sync Project with gradle files button. And you must be fine!