Java 在android studio中添加ZXing android项目作为库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23575559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add ZXing android project as library in android studio
提问by Ryan95
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 :)
我正在 android studio 中制作一个使用条形码扫描仪的应用程序。我正在使用 Google ZXing 库。我下载了 zip,打开了项目并按照说明添加了 core.jar 文件,但是教程是针对 eclipse 的,并且没有选项可以在 android studio 中添加为库。所以我被困在如何添加它。任何帮助将不胜感激 :)
回答by frederick_c_siu
Simple way with mvn repo:
使用 mvn repo 的简单方法:
dependencies {
compile 'com.google.zxing:core:3.0.0'
}
The more work version without mvn repo:
没有 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.
因此,无论您选择哪个版本,请在 build.gradle 中查找依赖项块,然后添加适当的编译行。请记住将它添加到您的应用程序模块的 build.gradle 中,而不是根 build.gradle。
Sample directory layout: /approot
示例目录布局:/approot
/approot/build.gradle
/approot/build.gradle
/approot/myfancyapp
/approot/myfancyapp
/approot/myfancyapp/build.gradle <--- this one!
/approot/myfancyapp/build.gradle <--- 这个!
/approot/myfancyapp/libs/zxing/core.jar <--- put the jar here or any path, just an example.
/approot/myfancyapp/libs/zxing/core.jar <--- 把jar放在这里或任何路径,只是一个例子。
回答by goonerDroid
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.
如果您将编译文件('libs/core.jar')添加到 build.gradle,您唯一需要做的就是单击工具栏中的 Sync Project with Gradle Files 按钮。