使用Google Guava和Android 1.6

Jon*_*sen 8 java android guava

我在Android应用程序中使用Guava r09库但是当我使用1.6时遇到以下错误.这有点奇怪,因为它在1.5中运行良好.此外,"未找到"的方法非常清楚.我也试过包含jsr305.jar文件,但这仍然无效.

感谢任何帮助,没有番石榴,在Java中进行I/O是如此痛苦.

这是代码:

String timestamp = CharStreams.toString(
    CharStreams.newReaderSupplier(timestampFile, Charset.forName("UTF-8")));
Run Code Online (Sandbox Code Playgroud)

这是例外:

05-08 12:16:41.163: ERROR/dalvikvm(335): Could not find method com.google.common.io.LineReader.<init>, referenced from method com.google.common.io.CharStreams.readFirstLine
05-08 12:16:41.163: WARN/dalvikvm(335): VFY: unable to resolve direct method 6798: Lcom/google/common/io/LineReader;.<init> (Ljava/lang/Readable;)V
05-08 12:16:41.163: WARN/dalvikvm(335): VFY:  rejecting opcode 0x70 at 0x0009
05-08 12:16:41.163: WARN/dalvikvm(335): VFY:  rejected Lcom/google/common/io/CharStreams;.readFirstLine (Lcom/google/common/io/InputSupplier;)Ljava/lang/String;
05-08 12:16:41.163: WARN/dalvikvm(335): Verifier rejected class Lcom/google/common/io/CharStreams;
05-08 12:16:41.163: DEBUG/AndroidRuntime(335): Shutting down VM
05-08 12:16:41.163: WARN/dalvikvm(335): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
05-08 12:16:41.173: ERROR/AndroidRuntime(335): Uncaught handler: thread main exiting due to uncaught exception
05-08 12:16:41.183: ERROR/AndroidRuntime(335): java.lang.VerifyError: com.google.common.io.CharStreams
        at com.triposo.droidguide.rometest.LocationStoreInstaller.install(LocationStoreInstaller.java:33)
        at com.triposo.droidguide.rometest.SplashActivity.onStart(SplashActivity.java:58)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1205)
        at android.app.Activity.performStart(Activity.java:3520)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2373)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
        at android.app.ActivityThread.access$2100(ActivityThread.java:116)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4203)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
        at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

Jon*_*sen 5

我设法最终解决了这个问题.如果我使用jarjar将com.google.common.io.LineReader重命名为另一个软件包名称(例如com.triposo.vendor.com.google.common.io.LineReader),它就可以了!我的猜测是LineReader捆绑在Android中,但版本略有不同(不兼容).