15

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.

Example code:

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;

Example runtime exception:

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 build tools 2.2.2
  • Gradle 2.14.1
  • buildToolsVersion 25.0.0
  • sourceCompatibility/targetCompatibility JavaVersion.VERSION_1_8
  • compileSdkVersion/targetSdkVersion 24
colithium
  • 10,269
  • 5
  • 42
  • 57
  • Did you find any other workaround than going back to 24.0.3? 25.0.1 also does not seem to fix it for me. – Max Hille Nov 24 '16 at 12:39
  • After a couple of weeks of not working with Android Studio, I installed the latest batch of updates and haven't seen any problems for the last two days. That doesn't mean the updates fixed anything... but it's promising. I'll report back if I see a failure again – colithium Nov 26 '16 at 01:05
  • And it appears to be back with a vengeance. Nearly every other change requires a clean build – colithium Nov 30 '16 at 08:54
  • Were you able to fix this problem? – rozina Mar 24 '17 at 08:47
  • 1
    https://code.google.com/p/android/issues/detail?id=229403 Claims it's fixed, but they also announced they're dropping jack/jill. – colithium Mar 25 '17 at 18:31

1 Answers1

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.

UPDATE After 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.

Max Hille
  • 661
  • 7
  • 18
  • I'm already at 2.2.3. Any alternatives? I posted my detais [here](https://stackoverflow.com/questions/51156793/intent-and-lambda-and-need-to-clean-before-every-run). – FirstOne Jul 03 '18 at 14:20
  • My answer was written ~1.5 years ago. You should have more up to date versions of everything by now. – Max Hille Jul 06 '18 at 10:14