gradle编译遇到 org/apache/commons/codec/binary/Base64错误解决
android studio升级到gradle 版本升级到2.14.1, android build tools升级到 2.2.2后出现 org/apache/commons/codec/binary/Base64
错误。
错误信息是
14:47:26.213 [ERROR] [org.gradle.BuildExceptionReporter]
14:47:26.213 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
14:47:26.213 [ERROR] [org.gradle.BuildExceptionReporter]
14:47:26.214 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
14:47:26.214 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':app:packageDebug'.
14:47:26.214 [ERROR] [org.gradle.BuildExceptionReporter] > org/apache/commons/codec/binary/Base64
14:47:26.214 [ERROR] [org.gradle.BuildExceptionReporter]
14:47:26.214 [ERROR] [org.gradle.BuildExceptionReporter] * Try:
14:47:26.214 [ERROR] [org.gradle.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
14:47:26.215 [LIFECYCLE] [org.gradle.BuildResultL
gradle编译时候加上 --stacktrace,显示log信息为:
10:01:36.708 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
10:01:36.708 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.builder.internal.packaging.sign.SignatureExtension.setDigestForEntry(SignatureExtension.java:499)
10:01:36.708 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.builder.internal.packaging.sign.SignatureExtension.added(SignatureExtension.java:486)
10:01:36.709 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.builder.internal.packaging.sign.SignatureExtension.access$100(SignatureExtension.java:100)
10:01:36.709 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.builder.internal.packaging.sign.SignatureExtension$1.lambda$added$1(SignatureExtension.java:314)
10:01:36.709 [ERROR] [org.gradle.BuildExceptionReporter] at
标示build时候没有找到 org.apache.commons.codec.binary.Base64
, google搜索这个类,知道这个类属于commons-codec
包。需要在buildscript的classspath下,加上这个依赖。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'commons-codec:commons-codec:1.9'//加上commmons-codec依赖
}
}
这样就可以正常使用。
时间: 2024-10-02 08:07:02