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.
Related
I'm trying to use a third party library in AndroidStudio and am having some problems, it is the JSch library.
What I did was download the ".jar file
On my app within Module Settings I added it
And then selecting the app module again I added it within the dependencies
Yet when I try to code it into my files through "import com." it does not show.
I am too new at this to know if I added it incorrectly or if it has a problem within the ".jar" file.
Does this ring a bell with anyone who might know what I am doing wrong?
Just follow this steps:
1.- Put the jar into the libs folder
2.- Right click it and select "Add as library"
3.- Check that your build.gradle file contains:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
You'll provably need to do a clean build
Add library to yours app dependencies:
dependencies {
// Other libraries...
compile group: 'jsch', name: 'jsch', version: '0.1.29'
}
And synchronize your gradle.
I first tried using "Project Settings" and importing .jar -- however then only the .jar file is visible in the left pane.
And I in "Project Settings" try to import as a project I get Gradle sync errors.
Is it possible to install in a way, so I can browse the source code files while also using them in my android project?
Add Repository and dependency like this:
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
//format for including lib jar files for all flavors
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':baselibrary')
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
}
You can use the library via gradle or maven. If you are having problems, I suggest you read tutorials in that direction.
If you want to browse the source code, you should clone the git repo of the library and reference the library project in your android studio project:
How do I add a library project to Android Studio?
So there seems to be a few threads that attempt to explain how to add .zip files to android studio but I am making no progress. I am migrating from eclipse so perhaps that is why I am so incompetent in figuring out how to perform this task. Can someone please explain how to add external libraries to Android Studio v1.0.1? In eclipse it was simply importing jar/zip and done.
I was in the same situation, trying to integrate Parse 1.8 with Android Studio 1.0.2.
On Parse's instruction page, it simply tells you to import the library into Android studio, which isn't too detailed. Here is how I solved this problem.
Choose to import from a "Non Android Studio Project", right when Android Studio starts.
When it asks you to choose the project, give the path, on Windows e.g.C:/path/to/parsesdk/. On *nix systems, it should be to where you have extracted to it, /home/user/path/to/parsesdk.
After you choose the path, Android Studio will import the project accordingly.
Click on the Application root folder (the top most folder in the folder hierarchy to the left), right click > New > Package > and add it under the src folder, name is libs.
Copy paste the jar to the libs folder (I only copied the jar file, as I didn't need the other extra material)
Right click on the jar, there should be an option labeled as "Add as library" towards the bottom, click on that.
Android Studio will automatically add the following to the build.gradle file.
compile files('src/libs/Parse-1.8.0.jar')
Once the above step is completed, click on File > Project Structure.
On the left, there should be a section called "Modules", click on the "Dependencies" tab on the top.
Click the green "+" sign > Module Dependency
Select the module from the list.
Last thing, in the build.gradle file for the "ParseStarterProject" module, if there is a red line under the classpath, change it to the following
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
After completing this step, I was able to successfully build the app.
Hope this helps :)
If you are using gradle with android studio (which is the preferred way now) you can include jars in a folder using this code snipet from my build.gradle.
buildscript {
repositories {
flatDir { dirs 'c:\\path\\to\\folder' }
mavenCentral()
}
}
Or by including a single file in depencies like below.
dependencies {
compile fileTree(dir: 'a-folder-in-root-of-project', include: 'a_jar.jar')
}
This is the only way it worked for me :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//Parse
compile 'com.parse.bolts:bolts-android:1.+'
compile files('libs/Parse-1.9.2/Parse-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseCrashReporting-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseFacebookUtilsV3-1.9.2.jar')
compile files('libs/Parse-1.9.2/ParseFacebookUtilsV4-1.9.2.jar')
compile files('libs/Parse-1.9.2/bolts-android-1.2.0-javadoc.jar')
compile files('libs/Parse-1.9.2/bolts-android-1.2.0.jar')
}
OR
//Parse
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs/Parse-1.9.2', include: 'Parse-*.jar')
compile fileTree(dir: 'libs/Parse-1.9.2', include: 'ParseCrashReporting-*.jar')
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'
I am trying to add a jar to a project on Android. I did a test with the maps.jar library. Which has a class named com.google.android.maps.MapView when i do the import of that class. I get the error package com.google.android.maps does not exist
import com.google.android.maps.MapView;
I try to include this jar file in several ways into my gradle.build:
dependencies {
runtime files('/Users/user/Documents/workspace/MyAndroidApp/libs/maps.jar')
//runtime fileTree(dir: '/Users/user/Documents/workspace/MyAndroidApp/libs', include: '*.jar')
//classpath fileTree(dir: '/Users/user/Documents/workspace/MyAndroidApp/libs', include: 'maps.jar')
}
Not luck so far.
Any idea?
Thanks!
Here is how i got it going:
Drag your jar file into the libs folder.
Right click on the jar file and select "Add Library" now the jar
file is a library.
open the build.gradle file (note there are two build.gradle files at least, dont use the root one use the one in your project scope).
find the dependencies section (for me i was trying to the admob
-GoogleAdMobAdsSdk jar file)
dependencies {
compile files('libs/android-support-v4.jar','libs/GoogleAdMobAdsSdk-6.3.1.jar')
}
last go into settings.gradle and ensure it looks something like
this:
include ':yourproject', ':yourproject:libs:GoogleAdMobAdsSdk-6.3.1'
Finally, Go to Build--->Rebuild Project
Compile dependencies have to be added to the compile configuration (not runtime or class path).