在 Android 1.6 中使用 Google Guava
我在 Android 应用程序中使用 Guava r09 库,但在 1.6 版本中使用它时出现以下错误。这有点奇怪,因为它在 1.5 中工作得很好。另外,“未找到”的方法也很清楚。我还尝试包含 jsr305.jar 文件,但这仍然不起作用。
感谢任何帮助,如果没有 Guava,用 Java 进行 I/O 是非常痛苦的。
这是代码:
String timestamp = CharStreams.toString(
CharStreams.newReaderSupplier(timestampFile, Charset.forName("UTF-8")));
这是例外:
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终设法解决了这个问题。如果我使用 jarjar 将 com.google.common.io.LineReader 重命名为另一个包名称(例如 com.triposo.vendor.com.google.common.io.LineReader),它就可以工作!我的猜测是 LineReader 捆绑在 Android 中,但版本略有不同(不兼容)。
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.
这就是为什么使用未记录的 Android API 调用是不好的。 CharStreams 从来都不是 Android API 的一部分(您没有看到 1.6 变更日志)。
未记录的类或方法可能会在没有任何操作系统修订通知的情况下消失,就像这里发生的那样。
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.