8

I'm using the Guava r09 library in an Android app but I'm getting the following error when I use it with 1.6. It's a bit strange because it works fine in 1.5. Also, the method that is "not found" is very clearly there. I also tried including the jsr305.jar file but this still doesn't work.

Appreciate any help, doing I/O in Java is so painful without Guava.

This is the code:

String timestamp = CharStreams.toString(
    CharStreams.newReaderSupplier(timestampFile, Charset.forName("UTF-8")));

This is the exception:

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)
Jon Tirsen
  • 4,750
  • 4
  • 29
  • 27

2 Answers2

5

I managed to solve this in the end. If I use jarjar to rename com.google.common.io.LineReader to another package name (e.g. com.triposo.vendor.com.google.common.io.LineReader) it works! My guess is that LineReader is bundled in Android but with a slightly different (incompatible) version.

Jon Tirsen
  • 4,750
  • 4
  • 29
  • 27
1

This is why using undocumented Android API calls is bad. CharStreams was never part of the Android API (you don't see its removal being mentioned in the 1.6 changelog).

Undocumented classes or methods could disappear without notice from any OS revision, like it happened here.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • CharStreams is part of Guava which is the third library that I'm trying to use. This is what the question is about. It works on 1.5 and on 2.x so there's something going on in 1.6 that I suspect is a bug. – Jon Tirsen May 20 '11 at 04:21
  • Okay, it's looking for `com.google.common.io.LineReader`, which is part of Guava (I see it now in the source code). So I retract my original statement - it seems like a problem with the class loader/verifier. How do you import them into your project? Is the whole thing just one .jar? Mulitple .jars? Or are you taking the raw source code? – EboMike May 20 '11 at 06:04
  • Ok, I worked this out. If I use jarjar to rename com.google.common.io.LineReader to another package it all works! My guess is that LineReader is included with a slightly different version in Android. – Jon Tirsen Jun 20 '11 at 11:29