问题描述
看似随机,Android Studio安装的apk已损坏.它通常以lambda为中心(但每次都不同).我正在使用Jack编译和所有内容的最新版本(最后列出).该问题一直存在,直到我进行干净的构建为止(然后一切都很好).间歇性故障是一种新现象.有了Jack和Java 8功能,事情稳定了一段时间了.不幸的是,我无法确定在片状故障开始之前发生了什么变化.
Seemingly at random, the apk that Android Studio installs is corrupted. It usually centers around lambdas (but it's a different one every time). I'm using Jack compilation and the latest version of everything (listed at the end). The problem persists until I do a clean build (and then everything's fine). The intermittent failures are a new phenomena. Things were stable with Jack and Java 8 features for awhile. Unfortunately, I can't pinpoint what changed before the flaky failures began.
示例代码:
private static final Ordering<Foo> ORDER_BY_FOO =
Ordering.natural().onResultOf(Foo::getId);
实际问题分配(使用番石榴代码):
Actual problem assignment (in Guava code):
ByFunctionOrdering(Function<F, ? extends T> function, Ordering<T> ordering) {
this.function = checkNotNull(function); // <-- Fails
[...]
class ByFunctionOrdering<F, T> extends Ordering<F> {
final Function<F, ? extends T> function;
示例运行时异常:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mypackage, PID: 32222
java.lang.ExceptionInInitializerError
at com.mypackage.MyFragment.myOtherMethod(MyFragment.java)
at com.mypackage.MainActivity.myMethod(MainActivity.java:144)
at com.mypackage.MainActivity.onActivityResult(MainActivity.java:107)
at android.app.Activity.dispatchActivityResult(Activity.java:6932)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4085)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassCastException: com.mypackage.-$Lambda$0 cannot be cast to com.google.common.base.Function
at com.google.common.collect.ByFunctionOrdering.<init>(ByFunctionOrdering.java:39)
at com.google.common.collect.Ordering.onResultOf(Ordering.java:416)
at com.mypackage.MyFragment.<clinit>(MyFragment.java:110)
at com.mypackage.MyFragment.myOtherMethod(MyFragment.java)
at com.mypackage.MainActivity.myMethod(MainActivity.java:144)
at com.mypackage.GamesApiManager.onActivityResult(GamesApiManager.java:205)
at com.mypackage.MainActivity.onActivityResult(MainActivity.java:107)
at android.app.Activity.dispatchActivityResult(Activity.java:6932)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4085)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
- Android Studio/gradle构建工具2.2.2
- 2.14.1级
- buildTools版本25.0.0
- sourceCompatibility/targetCompatibility JavaVersion.VERSION_1_8
- compileSdkVersion/targetSdkVersion 24
- Android Studio/gradle build tools 2.2.2
- Gradle 2.14.1
- buildToolsVersion 25.0.0
- sourceCompatibility/targetCompatibility JavaVersion.VERSION_1_8
- compileSdkVersion/targetSdkVersion 24
推荐答案
我认为这是Build Tools 25.0.0和25.0.1中的错误.恢复到24.0.3可以为我解决此问题.
I assume this is a bug in Build Tools 25.0.0 and 25.0.1. Reverting back to 24.0.3 fixed this issue for me.
更新更新到com.android.tools.build:gradle:2.2.3
之后,我使用了构建工具v25.0.1,整个工作日没有构建错误.
UPDATEAfter updating to com.android.tools.build:gradle:2.2.3
, I had a full work-day without build errors with Build Tools v25.0.1.
这篇关于Jack和Android-Lambda运行时失败,直到全新构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!