Apache的共享codeC与Android:找不到方法找不到、方法、Apache、codeC

2023-09-12 01:58:32 作者:深夜拉仇恨

今天,我想包括apache.commons。codeC包在我的Andr​​oid应用程序,并能得到它运行并非如此。安卓找不到方法ord.apache.commons。codec.binary。*和输出DDMS以下错误

Today I tried including the apache.commons.codec package in my Android application and couldn't get it running. Android could not find method ord.apache.commons.codec.binary.* and output the following errors in DDMS

八月1日至12日:41:48.161:ERROR / dalvikvm(457):找不到方法org.apache.commons codec.binary.Base64.en codeBase64URLSafeString,从方法com.dqminh引用。 .app.util.Util.sendRequest

01-12 08:41:48.161: ERROR/dalvikvm(457): Could not find method org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString, referenced from method com.dqminh.app.util.Util.sendRequest

八月1日至12日:41:48.161:WARN / dalvikvm(457):VFY:无法解析静态方法10146:Lorg /阿帕奇/公/ codeC /二/ Base64的; .EN codeBase64URLSafeString( [B)Ljava /朗/字符串;

01-12 08:41:48.161: WARN/dalvikvm(457): VFY: unable to resolve static method 10146: Lorg/apache/commons/codec/binary/Base64;.encodeBase64URLSafeString ([B)Ljava/lang/String;

八月1日至12日:41:48.161:WARN / dalvikvm(457):VFY:拒绝运code 0x71在×0004

01-12 08:41:48.161: WARN/dalvikvm(457): VFY: rejecting opcode 0x71 at 0x0004

在如何解决这个问题的任何线索?非常感谢。

Any clue on how to solve this problem ? Thanks a lot.

推荐答案

我也有类似的问题,同时采用了android与的OAuth库我发展。

I had a similar problem while using android with an OAuth library I'm developing.

我也从机器人得到了,虽然我已经包括 apache.commons,在类路径中codeC ,一个特定的方法(恩codeBase64String )未找到。

I also got from android that, although I had included apache.commons.codec in the classpath, a particular method (encodeBase64String) was not found.

检查的javadoc,这两种方法声称自己是 1.4,仅大,所以我的猜测是,机器人已经包括公地的旧版本。codeC 其中,这些方法的确是不确定的。

Checking the javadocs, both methods claim to be 1.4 and greater only, so my guess is that android already includes an older version of commons.codec where these methods are indeed undefined.

我的解决办法是使用旧的方法,像这样的:

My solution was to use an older method, like this:

String encodedString = new String(Base64.encodeBase64('string to encode'));

您要使用的方法是不同的,因为它取代+和/ url的安全值 - 和_。所以,你可能会使用这样的:

The method you want to use is different since it replaces + and / with url-safe values - and _. So you probably might use something like:

String encodedString = new String(Base64.encodeBase64('string to encode'));
String safeString = encodedString.replace('+','-').replace('/','_');

希望帮助!