我是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
其他回答
请在build.gradle中提供jar文件位置
implementation fileTree(dir: '<DirName>', include: ['*.jar'])
例子:
implementation fileTree(dir: 'C:\Downloads', include: ['*.jar'])
添加单个jar文件
implementation files('libs/foo.jar')
注意: Compile在最新的gradle中已弃用,因此改用implementation。
在Android Studio 3.0或更高版本中,我使用了如下的波纹:
如果不存在类似的文件夹,则创建应用程序目录的库
在左上角设置项目视图 进入项目 进入应用程序 点击应用->新建->目录 将文件夹命名为libs 将罐子粘贴到libs文件夹中 目录将看起来像一个波纹图像
在构建。Gradle添加这些线条 //如果之前没有添加,则添加此行。 实现文件树(目录:'libs',包括:['*.jar']) 实现文件(“libs / com.ibm.icu_3.4.4.1.jar”)
步骤1:为项目下载任何JAR文件。
第二步:复制。jar文件和过去的libs文件夹。
步骤3:单击文件>项目结构>选择应用程序>依赖
步骤4:
步骤5:
第六步:点击Ok按钮后,我们可以看到依赖项以这样的方式添加:
在你的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
手动:
在项目中添加libs文件夹(Where build。Gradle被定位)。例如,应用程序 移动.jar到lib 在build.gradle中添加实现文件('libs/<name>.jar')。它与UI Add as library do相同
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 碎片中的onCreateOptionsMenu
- 在Jar文件中运行类
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?