我一直在开发一个使用 AES 加密的应用程序,它需要一个用于 Base 64 编码和解码的 JAR。
我遵循了本教程 this关于导入 JAR(可能是我的问题,因为似乎他们不知道自己在做什么)。逐行编译很顺利,但在手机上运行时我收到错误消息
Could not find method org.apache.commons.codec.binary.Base64.decodeBase64, referenced from method com.login.tools.Encoder.decrypt
我的应用程序 gradle 脚本确实引用了 JAR
compile project(':commons-codec-1.10')
应该调用 commons-codec-1.10 gradle 脚本
configurations.create("default")
artifacts.add("default", file('commons-codec-1.10.jar'))
调用类本身看起来有点像
import org.apache.commons.codec.binary.Base64;
.
.
.
public static String decrypt(String strToDecrypt)
setDecryptedString(new String(cipher.doFinal(Base64.decodeBase64(strToDecrypt))));
最佳答案
使用 Gradle 依赖项,而不是 .jar
:
dependencies {
compile 'commons-codec:commons-codec:1.10'
}
参见:http://mvnrepository.com/artifact/commons-codec/commons-codec/1.10
此外,我发现您正在尝试使用org.apache.commons.codec.binary.Base64.decodeBase6
。 Android 有自己的 Base64 库:
http://developer.android.com/reference/android/util/Base64.html
关于java - Android 在运行时无法从 JAR 中找到方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29131316/