28

After upgrading Android Studio 3.0 Beta 1 getting the following error. When I downgraded the error disappeared.

Studio Build: Android Studio 3.0 Beta 1 Version of Gradle Plugin: 'com.android.tools.build:gradle:3.0.0-beta1' Version of Gradle:.0.0-beta1 Version of Java: 8 OS: MacOSX

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:364)
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:113)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.ClassNotFoundException: 
Didn't find class "com.google.devtools.build.android.desugar.runtime.ThrowableExtension" on path: DexPathList[[zip file "/data/app/sark.savvy.Debug-1/base.apk",
 zip file "/data/app/sark.savvy.Debug-1/split_lib_dependencies_apk.apk", zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_0_apk.apk",
  zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_1_apk.apk", zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_2_apk.apk",
   zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_3_apk.apk", zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_4_apk.apk", 
   zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_5_apk.apk", zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_6_apk.apk",
    zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_7_apk.apk", zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_8_apk.apk",
     zip file "/data/app/sark.savvy.Debug-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/sark.savvy.Debug-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:364) 
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:113) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:154) 
Bulu
  • 1,351
  • 3
  • 16
  • 37

3 Answers3

23

Update (still working in Gradle plugin 3.0.0-beta5, confirmed by @ TmTron)

classpath 'com.android.tools.build:gradle:3.0.0-beta5'

Update (fix in Gradle plugin 3.0.0-beta4)

Issue fixed again in Gradle plugin 3.0.0-beta4. Expected to be included in next AS 3.0 Beta 4, but can be already used in current AS 3.0 Beta 3 by updating top level build.gradle:

classpath 'com.android.tools.build:gradle:3.0.0-beta4'

Update (regression in AS 3.0 Beta 3)

The issue is back on beta 3. Google is already aware of the issue and has reopened it. See https://issuetracker.google.com/issues/64527520

Fixed in future beta 4, pending to be released.

Thanks @yvolk for reporting it and @ghui-zhang for the confirmation.


Final Update (fix in AS 3.0 Beta 2)

As Jordan Bondo says in his comment, AS 3.0 Beta 2 is already released containing the plugin 3.0.0-beta2 that fixes the issue.

So, the solution is to upgrade the plugin from 3.0.0-beta1 to at least 3.0.0-beta2.


History

Google is handling this issue with priority P0 (this is TOP priority) in this issue: https://issuetracker.google.com/issues/64527520

In the meantime, @edgars workaround made it for me. Thanks!

Update 2: Fixed, scheduled for next beta "Fix will land in plugin 3.0.0-beta2"

Update: additional workaround shared by a Googler:

Temporary workaround is to set min sdk version below 19. Issue is that Desugar will process try-with-resources for API 19+, although platform supports it, but we will not package those classes.

Update 3: if not using Java 8 features in Java code, disable it (this can also be useful for Kotlin codebases). See this comment.

Xavier Rubio Jansana
  • 6,388
  • 1
  • 27
  • 50
  • 1
    The temporary workaround mentioned in this ticket is to use minSdk < 19. @edgars solution did work for building the app, but not for instrumentationTests (for me) – Jan Weitz Aug 10 '17 at 13:32
  • Thanks, I've just seen the additional workaround in Google's issue tracker and updated. @edgars workaround works for me in both app and tests, but apparently people is seeing mixed results. I've added it to the app code, not just to the tests. You've done the same? – Xavier Rubio Jansana Aug 10 '17 at 13:35
  • 1
    I just put it in `src/main`. Now I have deleted @edgars solution and use minSdk < 19 only, which works – Jan Weitz Aug 10 '17 at 13:38
  • Thanks. For me lowering minSdk is not an option, I need 4.4 features. – Xavier Rubio Jansana Aug 10 '17 at 13:49
  • 1
    This seems to be fixed in AS 3.0 Beta 2 – Jordan Aug 14 '17 at 19:55
  • Yes, they released plugin first, and then as you say AS 3.0 Beta 2. This was quick! – Xavier Rubio Jansana Aug 14 '17 at 20:12
  • 1
    As I see, AndroidStudio 3.0 Beta 3 still has this bug. As @Jan Weitz suggested, I lowered minSdk to 18 and this error have gone from instrumentation tests – yvolk Aug 25 '17 at 05:42
  • AndroidStudio 3.0 Beta 3 still has this bug – Seth Aug 25 '17 at 06:49
  • @yvolk Have you updated Gradle plugin? The fix is not in AS itself, but in Gradle plugin, which is included by default in AS 3.0 beta 2. As an additional step, have you done a Clean of the project before building? – Xavier Rubio Jansana Aug 25 '17 at 08:36
  • Update: you're absolutely right, I've updated to beta 3 and the error is back. Beta 2 seems fine @yvolk I've seen that you've already reported it in the original issue. Thanks! – Xavier Rubio Jansana Aug 25 '17 at 08:52
  • 1
    Works for me now in AS3.0-beta5 (and `com.android.tools.build:gradle:3.0.0-beta5`) – TmTron Sep 12 '17 at 13:01
  • @TmTron Thanks. I saw yesterday the new plugin but couldn't test it yet. – Xavier Rubio Jansana Sep 12 '17 at 13:13
  • @XavierRubioJansana not working in 'com.android.tools.build:gradle:3.0.1' – click_whir Feb 22 '18 at 19:45
  • @click_whir What do you mean by "not working"? Same error again? Could you provide more details? – Xavier Rubio Jansana Feb 22 '18 at 21:45
  • @XavierRubioJansana Proguard error. Disabling Java 1.8 features unblocks me again. ```Warning: rx.exceptions.CompositeException: can't find referenced method 'void printStackTrace(java.lang.Throwable,java.io.PrintStream)' in program class com.google.devtools.build.android.desugar.runtime.ThrowableExtension Warning: timber.log.Timber$Tree: can't find referenced method 'void printStackTrace(java.lang.Throwable,java.io.PrintWriter)' in program class com.google.devtools.build.android.desugar.runtime.ThrowableExtension``` – click_whir Feb 22 '18 at 22:12
  • @click_whir Probably is because Proguard is removing this method, not because of the bug. Try to enable Java 1.8 again and disable Proguard. – Xavier Rubio Jansana Feb 23 '18 at 19:39
20

I also encountered the same error after upgrading to AS 3.0 Beta 1 and found a workaround: I made a copy of the ThrowableExtension.java file from Google's sources and put it in app\src\main\java\com\google\devtools\build\android\desugar\runtime (you have to create those folders).

Edgars
  • 304
  • 3
  • 9
1

This issue is back on Android Studio 3.0.1. New Google thread is https://issuetracker.google.com/issues/77591528.

Please star the thread if you are still having this issue and post what you are running into.

Marline
  • 269
  • 3
  • 10
  • Thanks Marline. Looks like it's fixed in 3.1.1 (from the issue you opened), I'm adding this comment here to let know the solution to other people running into the same issue. :) – Xavier Rubio Jansana May 31 '18 at 09:09