我是Android Studio的新手。 我如何在< JDK >文件夹下面的外部库中添加几个jar文件?
当前回答
解析jar的例子…
从项目视图中添加jar到libs文件夹,如果不存在则创建lib文件夹
复制所有的罐子…
向gradle....添加库在构建。Gradle文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:percent:23.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar’)
}
为添加lib文件夹的所有jar…将Parse-*.jar更改为*.jar
其他回答
这就是在Android Studio 2.1.3中添加.jar文件的方法。
复制.jar文件 将文件粘贴到Libs文件夹中,然后右键单击。jar文件并按Add as library 打开build.gradle 在截图中显示的依赖项下添加行 现在按下播放按钮,添加.jar文件就完成了
一个简单的方法添加Jar文件Android Studio步骤:
复制并粘贴jar文件到项目的libs文件夹。 从文件菜单点击文件->项目结构(CTRL + SHIFT + ALT + S在Windows/Linux,⌘+;Mac OS X)。 在左侧面板上选择模块-> Dependencies选项卡。 添加……→项目库→附加Jar。
解析jar的例子…
从项目视图中添加jar到libs文件夹,如果不存在则创建lib文件夹
复制所有的罐子…
向gradle....添加库在构建。Gradle文件:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:percent:23.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar’)
}
为添加lib文件夹的所有jar…将Parse-*.jar更改为*.jar
在你的android项目中添加一个罐子的“官方方式” 外部库,是在jar中添加依赖项{}节 build.gradle。
如果你做了以上所有的事情,但没有一个奏效,那么还有另外两种可能:
If Android Studio or some other IDE doesn't give red underlined errors in editor but runs in error in the Java Compiler, CHECK YOUR JAR. Your jar may not have a proper Manifest included therefore the compiler doesn't know what the jar can provide/don't know it's package name Maybe it's folder structure is messed up. The folder structure doesn't match with its package name. package a.b.c; should be matching to folder a > folder b > folder c. The package name has some conflict. (Trust me, this happened to me and it took hours to figure it out.)
然而,如果你打算用cordova,这里有一些添加外部罐子的技巧。
“build-extras。Gradle”是更好的管理Gradle文件的方法。
下面是在基于cordova的android项目中管理额外设置的步骤:
添加jar到build-extras.gradle: //其他设置在这里,例如:buildscript{…} ext.postBuildExtras = { //你可能有一些其他的设置,例如:android{…} 依赖关系{ 编译文件(“libs / abc.jar”) } }
(更详细的步骤在这里:扩展cordova gradle文件以包括谷歌服务)
在终端,做:
Cordova构建android
将JAR放在app/libs和app/build中。Gradle在依赖项部分添加:
implementation fileTree(dir: 'libs', include: ['*.jar'])
推荐文章
- Android加载JS包失败
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 按钮背景是透明的
- 在Mac OS X上哪里安装Android SDK ?
- 我如何获得图像缩放功能?
- 在Android应用程序中显示当前时间和日期
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)