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 :)
Asked
Active
Viewed 1.2k times
6
-
possible duplicate of [Android Studio: Add jar as library?](http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library) – dev2d May 09 '14 at 23:42
-
3im not trying to add a jar as library im trying to add a project as a library – Ryan95 May 09 '14 at 23:49
-
@user3552701 Mark frederick_c_siu answer correct. – Jared Burrows Mar 18 '15 at 11:39
2 Answers
22
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.

frederick_c_siu
- 540
- 3
- 8
-
If I add this dependency , and then use zxing with intents, will the app still ask us to download barcode scanner from google play? – Aman Grover Aug 29 '15 at 16:21
0
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.

williamj949
- 11,166
- 8
- 37
- 51