我需要使用Apache提供的commons-codec-1.9库中的commons-codec-1.9.jar。我在NetBeans的另一个项目中使用它作为库,所以我已经有了我需要导入的所需.jar文件。我从NetBeans项目中复制了jar文件并将其放入我的应用程序项目(app:libs文件夹)并右键单击并选择" Add as library ..."选项。我通过File>将它添加到我的项目依赖项中。项目结构>依赖。我在我编写的使用该库的类中创建了库的导入,我没有得到错误并且代码构建。但是,当我运行应用程序时,它会中断并抛出NoSuchMethod异常......即使它存在。
以下是build.gradle的内容
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.example.<path_stuff>"
minSdkVersion 17
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/commons-codec-1.9.jar')
}
这是我的settings.gradle
include ':app'
我从libs文件夹中删除了commons-codec的东西并尝试重新添加后,最近也遇到了构建错误。这个错误说的是&#34; Build失败:无法找到任务&#39;汇编&#39;在项目&#34;好像Android Studio认为这是另一个项目。有人可以帮我理解这里发生了什么以及我哪里出错了吗?
没有此类方法错误详情:
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String
编辑:已实现我包含了错误的build.gradle文件。更新了settings.gradle以删除include语句。包含正确的build.gradle和NoSuchMethod错误。
答案 0 :(得分:0)
从include ':libs:commons-codec-1.9:
删除settings.gradle
。
将compile fileTree(dir: 'libs', include: '*.jar')
添加到模块的build.gradle
文件中的依赖项块。
android {
...
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
这会自动将.jar
文件夹中的libs
个文件编译到您的项目中。