importing ShowcaseView with gradle - android

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'

Related

Android Studio Gradle dependency doesn't show up in External Libraries

I'm using Android Studio 3.0.1 and I'm trying to add an online dependency and while Gradle initially syncs without a problem it doesn't show my dependency in External Libraries and my code that references the dependency doesn't work.
Here's a snippet of what my build.gradle file looks like:
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/groups/public/' }
}
dependencies {
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
}
I'm pretty new to android development (took over an existing project from a dev who quit without leaving any documentation) so I'm not sure if this is a mistake with how to add a project dependency or if there is a problem with the dependency that I'm trying to add. Any help would be greatly appreciated!
I was able to get this to work by changing the dependency declaration to:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT', classifier: 'jar-with-dependencies'
The library artifacts up on the repository include an apklib and a JAR with a special classifier. The apklib format is not supported by Android Studio, and unfortunately the classifier on the JAR means that it's not accessible simply using the group-name-version format when declaring dependencies.
Your build.gradle file seems fine. If you want to keep the library specified as an external library, you can try and define the dependency using the alternative notation, replace:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
with:
compile 'com.fortysevendeg.android:swipelistview:1.0-SNAPSHOT'
The alternative approach is to download the jar file yourself and use it as a local dependency. If you navigate to the maven repository you can inspect the package which is included as a dependency and download the jar directly. Place the jar file in the libs folder of your project and add the following to your build.gradle file:
compile fileTree(dir: 'libs', include: ['*.jar'])
For further details on how to configure the dependencies of your gradle project, check out the Android Studio documentation here.
Based on the information you have provided, this should fix your issues. If this does not solve the error then there may be other issues with the project.
Your dependencies should not placed in the top-level build.gradle file where the repositories are defined. There is even a comment in that file that says so, by default.
You app dependencies should be the module's build.gradle along with the others like android-support
Additionally, that library is very old, and is a SNAPSHOT build, meaning it isn't meant to be generally used in a release environment. You should find an alternative... And there are plenty of other ListView swiping ones

Third Party Android Library Format

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")
}

Reuse modules in Android Studio

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.

Sync Gradle Android Studio Failed on SlideDateTimePicker

I want to create an EditText that could pick date and time at the same time. I found this library but I failed build this library. It says
Error:(31, 0) Project with path ':slideDateTimePicker' could not be found in project ':app'
According to the grade.build file, it looks like we should have this library as a project first. Here is the dependencies that I should add
compile project(':slideDateTimePicker')
How should I add this library into my project? Thank you.
Use this on your gradle:
compile 'com.github.jjobes:slideDateTimePicker:1.0.2'
You need to add library files to your project directory as well. Also add
this line to settings.gradle:
include 'your-library-directory'
There are two approaches. First approach, if you want to use the library out-of-the-box without source code changes. Second, if you want to modify the source code later on.
As dependency on app level; add the following line in your build.gradle file:
compile 'com.github.jjobes:slideDateTimePicker:1.+'
Add as a sub-project to your existing project; add the slideDateTimePicker folder to your projects root folder:
under dependencies on app level build.gradle file add:
compile project(path: ':slideDateTimePicker')
and in your settings.gradle file add:
include ':slideDateTimePicker'
file-> input modle>SlideDateTimePicker, and then: project settings-> add modle->choice SlideDateTimePicker.
or
copy SlideDateTimePicker to you project root path. and add compile project(':slideDateTimePicker') in your build.gradle, add include ':slideDateTimePicker' in settings.gradle
Hope this can help you.

Use android-maps-utils in Android Studio

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!

Categories

Resources