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
Related
I want to use this library in my android application which has been developed in android studio IDE. I downloaded the zip file from githup and extracted, then paste the unzip file in a optional folder called 'subProject' in application root.
image.
Next I added this line to setting.gradle:
include ':app', ':subProject:rtree-3d'
and then change my application build.gradle to this as new dependency:
compile project(':subProject:rtree-3d')
But after cleaning and rebuilding my project I have this error:
Error:Configuration with name 'default' not found.
I also change top line to compile fileTree(dir: 'subProject', include: ['rtree-3d'])but there was no succeed.
How can I add this github project to my android application to use? Any help will be appreciated.
This isn't a gradle-project (but Maven (see the pom.xml?)), so the gradle build won't succeed, because it is looking for build.gradle-files.
You could build it with Maven, and add the resulting .jar file to your lib-folder of your project, in order to let gradle pick it up.
Or, even better, just add it as a dependency to your apps build.gradle
// https://mvnrepository.com/artifact/com.github.davidmoten/rtree
compile group: 'com.github.davidmoten', name: 'rtree', version: '0.8-RC10'
latest stable version is
compile group: 'com.github.davidmoten', name: 'rtree', version: '0.7.6'
Edit
Oh! my bad, actually rtree und rtree-3d istn't the same thing! So you would need to fork the rtree-3d project from github, build it with maven (clean install). Depending on your configuration gradle can access your local maven repo and pick the installed artifact from there.
But for builds on different machines you would need something like a shared Sonatype Nexus. This is something to do, so you could just copy the rtree-3d.jar from your local maven repo to the lib-folder of your gradle project and add it to your subversion/git.
Feel like Im going mad here - this must be so simple!
I have an android aar which I have built from gradle assembleRelease and also using the maven-publish plugin. I thought that /libs/ was included by default but evidently not.
Android tools site shows its an optional include
http://tools.android.com/tech-docs/new-build-system/aar-format
but for the life of me I don't see where this is configured.
I have asked a related Q Include folder in Gradle artifact but I dont see this as a duplicate as thats a generic gradle question really whereas this is aar specific and may be solved outside of gradle.
Edit I have also asked on the Gradle forum
The aar packages local libraries in libs/ so you need to have local jar dependencies.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
When the maven plugin runs uploadArchives then it will create a pom file that tells maven or gradle what dependencies your aar needs. Gradle will handle downloading the jar files and placing them in your class path for the build.
I commented on your other question as well
*reference: https://maven.apache.org/pom.html#Dependencies
*=gradle is backed by maven for dependency management so artifacts available to maven are also available to gradle and vice versa
I currently am not using the "libs" folder for my third party dependencies (it seems they are added automatically to build/intermediates/pre-dexed/) but noticed that it may help static code analysis so I would like to add it to the project.
Note: I'm using maven dependencies.
My question: Are people using custom scripts to generate this folder? I hardly think that this is generated once and then manually maintained when there is a newer version available.
Please enlighten me!
With Android Studio AND Gradle, there is no need to use libs folder (except for old .jar library).
In fact you can develop Android app whitout Android Studio as in your build.gradle there is already a apply plugin: 'com.android.application'
Gralde is using Maven or jCenter via gradle dependencies to import libraries. Gradle and Android Gradle plugin will automaticly download the libs as you sayed in a build/ folder. It is not static and can be clean with the Clean projet on Android Studio. Also, Android Studio will add a warning when a new library version is available automaticly in your build.gradle.
Dont miss the old libs folder used to import .jar library
I currently am not using the "libs" folder for my third party dependencies (it seems they are added automatically to build/intermediates/pre-dexed/) but noticed that it may help static code analysis so I would like to add it to the project. Note: I'm using maven dependencies.
Don't confuse the libs folder with build/intermediates/pre-dexed/ folder.
Currently the gradle plugin for Android manages the build process and create these "internal" and intermediates folders.
My question: Are people using custom scripts to generate this folder?
I hardly think that this is generated once
You don't have to create this folder. The Gradle plugin for Android manage it for your. Also it will be deleted and recreated when your run a gradlew clean command.
and then manually maintained when there is a newer version available.
No. Your dependencies are defined in your build.gradle file.
When you define a new version, Gradle downloads the new dependency and updates the intermediate folders.
You can define your dependencies in many ways:
dependencies{
//You can create a folder and put jar files inside. You can use your favorite name, usually it is libs.
compile fileTree(dir: 'libs', include: ['*.jar'])
//The support libraries dependencies are in a local maven managed by SDK
compile 'com.android.support:appcompat-v7:23.0.0'
// A Maven dependency
compile 'com.squareup.picasso:picasso:2.5.2'
//A local library
compile project(':mylibrary')
//An aar file. It requires to define a repository.
//repositories{
// flatDir{
// dirs 'libs'
// }
//}
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
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'
I'm using Square's Wire library for my Android app, using Android Studio with Gradle.
I originally added the wire-runtime-1.2.0.jar into a libs folder in my module, and added the dependency to Gradle like this in my build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
That worked fine.
I'm new to Gradle and Android Studio, but based on the way I'm depending on the Google Support and Play Services libraries, I thought I might be able to remove the wire-runtime-1.2.0.jar library from my repository and just declare a dependency like this (the line is from the Maven repository):
dependencies {
compile 'com.squareup.wire:wire:1.0.0'
}
But if I do that then I hit this error:
Gradle: package com.squareup.wire does not exist
Is there a way to set up this dependency without importing the JAR file directly? Or does that only work for libraries that you can install through the SDK Manager?
Some packages, like com.squareup.wire, have multiple artifacts in Maven Central. You need to choose the right one for your needs. In this case, the equivalent of wire-runtime-1.2.0.jar is the wire-runtime artifact, not the wire artifact.
Here's what your dependencies section should look like:
dependencies {
compile 'com.squareup.wire:wire-runtime:1.2.0'
}