Get the issue with import external library in Android Studio - android

I want to import the library https://github.com/jpardogo/FlabbyListView
First, I download the Zip file, then I extract it then I copy it to the lib folder of my project, then I turn on my project in Android Stduio. I add this line in the build.gradle compile 'com.jpardogo.flabbylistview:library:(latest version)'. But the Android Studio show:
How can I fix it?

You are mixing two concepts. If you use the compile dependency you don't have to put the jar in libs, and if you put the jar, don't put the managed dependency.
What the line compile library:artifact:version does is putting in your classpath in compile time the corresponding library, downloading it for you from a maven repository.
That said, I suggest you to remove the .jar and change your line of compile to:
compile 'com.jpardogo.flabbylistview:library:1.0.0

if you are manually adding the library to android. then you will add it to you project also.
In you settings.gradle file for the project add
include ':nameoflibrary'
or
include 'lib:nameoflibrary'
Where lib is the name of the folder you added the library and nameoflibrary is the actual name of the library.
then in you actual module usually the app-module gradle file add
dependencies {
compile project(':nameoflibrary')
}
or
dependencies {
compile project('lib:nameoflibrary')
}
same analogy too.
But if you are adding it from the repository you only need to add this line of code in your app-module gradle
dependencies {
compile 'com.jpardogo.flabbylistview:library:(latest version)'
}

Related

Does anyone have an example of an android studio project that import Unirest via gradle?

I don't have the exact coding (at the moment since I'm not back in my room) I used in my project but I believe what I did was add all of the libraries necessary to Unirest.io as well as importing the jar file (after putting it into my lib folder) they have available here:
http://oss.sonatype.org/content/repositories/releases/com/mashape/unirest/unirest-java/1.4.5/unirest-java-1.4.5.jar
In the dependencies portion I added something like this:
compile 'org.json:json:20140107'
compile 'org.apache.httpcomponents:httpclient:3.6'
compile 'org.apahe.httpcomponents:httpasyncclient:4.0.2'
compile 'org.apache.httpcomponents:httpmime:4.3.6'
into the dependencies {} portion of the build.gradle file along with the Unirest jar in the lib folder.

Add Caldroid library in Android Studio

I have a problem when adding Caldroid library on Android Studio. I try many different ways to add but it won't work. I use Android Studio 0.8.2.
First off, I created a root folder called libraries.
I created a new folder caldroid in /libraries.
Then, I pasted the downloaded files in /libraries folder.
Then, I changed the following files.
settings.gradle
include ':app'
include 'libraries:caldroid:library'
build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:4.0.30'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libraries:caldroid:library')
}
But I get this error:
Error:Configuration with name 'default' not found.
How to fix this?
I'm late but I faced a similar issue so I thought I'll share how I solved it.
To import an external library to Android Studio, I follow this convention:
Create libs folder inside the app directory. Then copy the required library files to the libs folder. For example, my folder contains actionbarsherlock and caldroid folders.
Caldroid has a library dependency that can be downloaded here, you can see this in the build.gradle file (Also, make sure the gradle files have the correct SDK versions). Download the hirondelle-date4j-1.5.1-sources.jar.
Create libs folder in app/libs/caldroid/. Copy the hirondelle-date4j-1.5.1-sources.jar to app/libs/caldroid/libs/. You may also have to copy android-support-v4.jar from -User_Home-/Android/Sdk/extras/android/support/v4/ to app/libs/caldroid/libs/.
Open app/libs/caldroid/build.gradle and replace compile 'com.darwinsys:hirondelle-date4j:1.5.1' with compile files('libs/hirondelle-date4j-1.5.1-sources.jar').
In Android Studio, open settings.gradle and add this line include ':app:libs:caldroid'. Next, open "build.gradle (Module: app)" and add this line compile project(':app:libs:caldroid') in dependencies.
And that's it, now allow the gradle to "sync" or clean and build your project.
Add this line in your dependencies in build.gradle
compile 'com.roomorama:caldroid:3.0.1'

importing ShowcaseView with gradle

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'

How to Import jar file into an Android project?

I am trying to use the loopj library in my Android project. In the project home page it says "Download the latest .jar file from github and place it in your Android apps libs folder". I did that!
As indicated in the documentation of the loopj I try to import it using the following
import com.loopj.android.http;
and nothing happens. It is not even coming up in intellisense.
Am I doing anything wrong?
in the build.gradle file add your jar such as below then rebuild.
dependencies {
compile files('libs/android-async-http-1.4.4.jar')
}
into the build.gradle file add the following::
dependencies {
// ... other dependencies
compile files('libs/<your jar's name here>')
}
Rebuid your project or Run ./gradlew assemble. This should compile the project with the library.
To let the Android Studio load all of your jar files by itself automatically, just write this line in the dependency section
compile fileTree(dir: 'libs', include: ['*.jar'])
This will help android studio to load all of your jar files available in libs folder.

How to copy or use native libs with Android Studio Gradle build?

I have a native lib in the
/libs/armeabi folder called libparser.so
and an associated jar file.
I changed the gradle build file to include the jar file, which seemsm to be easy (MYNEWJAR):
dependencies {
compile files('libs/android-support-v4.jar', 'libs/MYNEWJAR.jar')
}
But when I run the app, I think it cannot find the native lib:
E/AndroidRuntime(22569): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load parser from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.hybris.mobile.history-1.apk,libraryPath=/data/app-lib/com.hybris.mobile.history-1]: findLibrary returned null
E/AndroidRuntime(22569): at java.lang.Runtime.loadLibrary(Runtime.java:365)
E/AndroidRuntime(22569): at java.lang.System.loadLibrary(System.java:535)
E/AndroidRuntime(22569): at com.senstation.android.pincast.Pincast.<clinit>(Pincast.java:1299)
E/AndroidRuntime(22569): ... 17 more
Can you help me get the build file straight so it will include the native lib? This seems to be happening automatically on Eclipse, but i really want to use android studio.
Thx!
Sven
I found this answer from user Assaf Gamliel very useful.
And just made some changes to make it even more cleaner.
You don't need to rename the .zip file to .jar, just add it with a normal compile file dependency on build.gradle script. So, you would make a foo.zip file with a structure similar to this:
foo.zip ->
|--/lib
|--|--/armeabi
|--|--|--*.so
|--|--/x86
|--|--|--*.so
put it in your libs folder and then add it to gradle using compile files('libs/foo.zip'):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+' //gradle plugin update for Andoid Studio 0.2.+
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/foo.zip') //zip file should be in Module's /libs folder (not the Project's /lib)
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
while gradle does the build it just unzip the file you added preserving its structure.
To use an external jar library
Put the jar into the libs folder/drag the file onto libs from a file explorer
Right click it and select Add as library
Ensure that compile files('libs/your_jar.jar') is in your build.gradle file
To do this, modify build.gradle which is under [projectname]Project -> [projectname] in the project pane on the left.
For me, it was necessary to change
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
to
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files('libs/universal-image-loader-1.8.5.jar')
}
Click Rebuild Project under the Build menu.
I did this today to get the Universal Image Loader library integrated with my project.
Create a directory called 'jniLibs' into 'app/src/main/' and put inside all the .so
app/src/main/jniLibs/
|---- armeabi-v7a/your.so
|---- armeabi/your.so
|---- x86/your.so
Hmm...I was HOPING that someone will provide a clear example, of
how to make a 3rd-party JAR file accessible to Android-Studio, by
showing the exact SYNTAX of what the resulting 'build.gradle' file's
dependency-clause would look like, after they've added their 'foobar.jar'
entry.
You know, something like:
=========
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'org.somedevs.foobar:Foobar.jar'
}
=========
[Otherwise, I don't stand a snowball's chance in hell of
guessing what the answers posted so far really mean. My
INTITAL clause contained the single 'compile' line...so my
GUESS would that one should add another such line!?!?]
EDIT: Yes, many THANKS, rebelious! I now, too, have it working.
[Instead of the 'drag/drop' onto the 'libs' in Studio, I have more
reliable results by just right-clicking on 'libs' in Studio and choose
"add as library...", after copying the JAR into that location, using cmd-line.]
The correct form for the dependencies clause is the form shown below:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile files ('libs/Foobar.jar')
}
Due to security reason, it's not possible to reference a local jar/aar file in an application project with the gradle android plugin.
For the support library, with the Android SDK Manager, you have to install the extra named Android Support Repository which will expose the support library inside a maven repository. Then you can add the support library in your project via :
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
For external libraries, you have 2 possibilities :
Build an aar file and deploy it to your local maven repository, then reference it in your project like you did with the android support library.
Put the library sources beside your application project and create a settings.gradle at root which will define the modules. (see the docs for more info).
On my side I would prefer build aar files because it's more modular.

Categories

Resources