Add ZXing android project as library in android studio - java

I am making an app in android studio that uses a bar code scanner. I am using the Google ZXing lib. I downloaded the zip, opened the project and added the core.jar file as instructed but the tutorial was for eclipse and there is no option to add as library in android studio. so I am stuck on how to add it. any help would be greatly appreciated :)

Simple way with mvn repo:
dependencies {
compile 'com.google.zxing:core:3.0.0'
}
The more work version without mvn repo:
dependencies {
compile files('./libs/zxing/core.jar')
}
So whichever version you pick, look for the dependencies block in your build.gradle, then add in the appropriate compile line. Remember to add it into the build.gradle for your app module, not the root build.gradle.
Sample directory layout:
/approot
/approot/build.gradle
/approot/myfancyapp
/approot/myfancyapp/build.gradle <--- this one!
/approot/myfancyapp/libs/zxing/core.jar <--- put the jar here or any path, just an example.

If you add the compile files('libs/core.jar') to build.gradle, the only other thing you should need to do is click the Sync Project with Gradle Files button in the toolbar.

Related

How to add Maven and ProGuard to android application

I am trying to incorporate the Google Direction Library created by https://github.com/akexorcist/Android-GoogleDirectionLibrary
In the README it shows the following downloads. I know how to add gradle dependencies, but what does adding proguard and maven do and how do I add it?
Maven
Proguard
You can add the dependency either via Maven OR Gradle. So if you're using Gradle, that's 100% fine and just do that.
As for Proguard, there should be a file called "proguard-rules.pro" or something like that in your project. Simply copy the text from the Github page and paste it into that file in your project.
That's it.

Error in adding external Jar libraries in android studio

This is w.r.t Android Studio 1.3.2
So when i try to add the Repo from the Import Module->Import Existing Jar,the library is added as a separate module and included in the settings.gradle.
After this when I try to use the Jar, I get the message
Add Library 'x' to the classpath
Once i add this to the classpath,I am able to access the classes however the project does not build with the following error,
class Xx cannot be found(Xx belongs to the jar)
Is there a work-around to this.
I can add the jar by creatings a libs folder in the app module and clicking on add as library.
However I do not want the jar inside the main module.
When you add any module dependency then it will not automatically added to gradle file.
You have to add that dependancy to gradle file manually..
Now here you are adding module to Android Studio project then, You have to add
compile project(':module_name')
So that you module will be attached to your app module.
Hope It will help.
Thank you.!
Do something like this:
To import your module:
Step-1; Goto File->new->import module. Select and import your module.
Step-2: In your app's build.gradle add compile project(':yourlibrary')
Step-3: Sync your gradle.
Now to add jar in the above module:
Step-1: Copy your jar file into your module's lib folder.
Step-2: In your module's build.gradle file add a dependency like compile files('libs/your_jar_file.jar')
Step-3 Sync your gradle and you are good to go.

How to Add JAR (HTMLCleaner) to Project in Android Studio 1.1?

I've spent countless hours trying to add a simple JAR (HTMLCleaner) to my project in Android Stuio 1.1 to no avail. I imported the JAR as a module through the interface (File > New Module > Import JAR...), added it as a dependency on my app module, and even reference it in my AndroidManifest.xml <uses-library etc...>.
When I try to "import org.htmlcleaner;" in any of my classes I get a "cannot resolve symbol error." I've researched and tried every suggestion in every permutation and combination. Can anyone offer additional direction or a step-by-step tutorial on the proper way to do this?
Remember that Android Studio uses Gradle as a build tool, and part of the build flow is to handle dependencies. That being said, you have to specify to Gradle that includes your external jar files, making the following modifications:
Open build.gradle file of your module project (generally called "app")
Inside "dependencies", add compile fileTree(dir: 'libs', include: ['*.jar'])
Create a folder called libs inside your module app.
Copy your jar file inside of it
Run the build process of Gradle clicking in the "Sync now" link of Android Studio, and now your library should be recognized.
You can add jar file by following Rodrigo Ayala answer. Also Instead of using jar file you can also add the dependency in your project by add the following lines to build.gradle
dependencies {
// your other dependencies
compile 'net.sourceforge.htmlcleaner:htmlcleaner:2.16'
}
Inside your "app" module create a new folder "libs".
Paste your jar file inside libs folder.
Right Click on the jar file and select "Add as library".
DONE.

How to import project - intellij

I am experiencing difficulties to install some project based on a build.gradle file. I was told in a precedent post, that I should use Android Studio but it seems even more difficult (reported conflict for gradle 1.10 and Android Studio). So I am asking if it is possible to import the project directly in my ide, https://github.com/chrisbanes/ActionBar-PullToRefresh. If yes, should I put the library folder below in my libs folder ? Here's a screen of the file hierarchy
Since you are using Android Studio and Gradle, you could import it as suggested by the QuickStart page :
The easiest way to add ActionBar-PullToRefresh to your project is via
Gradle, you just need to add the following dependency to your
build.gradle:
dependencies {
mavenCentral()
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
I believe this is by far the easiest way to include that great library in your project.
If you are using Eclipse, you can still use the library, just download the project and create a create a new library project with the code from "library".
Check the guide http://www.jetbrains.com/idea/webhelp/cloning-a-repository-from-github.html
and other github integration http://www.jetbrains.com/idea/webhelp/using-github-integration.html

How to include cardslib to my Android project?

I want to create a GridView like GooglePlay.
I found this library on Github. I don't exactly know how to include it to my project. I tried to add it in "Build Path", but it doesn't work.
Is it possible to export it as a jar file?
You will have to import library directory as a project in your Eclipse just like #ssantos said in the answer. However you have to do one extra thing to make it work.
All the code is in a sub folder called "java". You have to right click on it and make it as source folder.
For more information you can look at the official guidlines https://github.com/gabrielemariotti/cardslib/blob/master/doc/BUILD.md
It seems you can find the library project here.-
https://github.com/gabrielemariotti/cardslib/tree/master/library/src/main
I'd try importing that as a project in your workspace (and mark it as Android library), and then including it in your project Android libraries (Project properties => Android => Library section)
If you're using Android Studio, just add the following to your build.gradle file.
dependencies {
compile 'com.github.gabrielemariotti.cards:library:1.3.0'
}

Categories