Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Build Failure: Couldn't find outer class

When trying to build, I get this stacktrace:

Exception in thread "main" java.lang.NullPointerException: Couldn't find outer class com/xxx/CheckListPresenter$onAttached$1$5 of com/xxx/CheckListPresenter$onAttached$1$5$1
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:1079)
    at com.google.devtools.build.android.desugar.ClassVsInterface.isOuterInterface(ClassVsInterface.java:56)
    at com.google.devtools.build.android.desugar.InterfaceDesugaring.visitOuterClass(InterfaceDesugaring.java:246)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:638)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
    at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
    at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
    at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
    at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)

I checked the CheckListPresenter class and there doesn't appear to have any issues. I tried deleting the class just to see if it would build, but the error just moved on to another class stating the same issue.

The last time I touched this code was a good few months ago, so I am not sure what triggered the change.

Things that may matter: This is an Android project. This is written in Kotlin. This fails on the transformClassesWithDesugarForDebug gradle task


Edits

These are all just stabs in the dark I tried:

  • Creating a new project and moving in only my source code and gradle files.

  • Dropping from java 8 to 7.

  • Different version of JDK. I have tried 1.8.0_151 and 1.8.0_152.

  • Adding javaMaxHeapSize "4g" to build.gradle.

  • Upgrading everything: gradle wrapper and every dependency.

  • Removed Dagger in favor of Koin

  • Removed Kapt

  • Used both Preview and Stable releases of Android Studio

Here is my build scan for what good it will do

New discovery:

This is the snippet of code that is killing me:

view?.let { v ->
    v.getCancelClicks()
        .doOnSubscribe({ disposables.add(it) })
        .subscribe({
           v.showExitDialog()
              .filter { it }
              .subscribe({
                 cancel()
            }, this::onError)
           
         }, this::onError)
    }

What is strange, is neither one of these alone will give me issues

view?.let { v ->
    v.getCancelClicks()
        .doOnSubscribe({ disposables.add(it) })
        .subscribe({
            //removed 
         }, this::onError)
    }
}

or

view?.let { v ->
    v.showExitDialog()
        .filter { it }
        .subscribe({
           cancel()
        }, this::onError)
 }

But together they are a problem.

Something else of note, view is defined in the base class and is a generic.

Currently, my work around is to remove view?.let{ and just use view!!. This is obviously a bug, but I am not sure who to report it to. Gradle, Kotlin, JetBrains, God?

like image 264
Chad Bingham Avatar asked Apr 16 '18 21:04

Chad Bingham


3 Answers

The problem resolved itself when I added android.enableD8.desugaring = true to gradle.properties

like image 54
Adrian Blanco Avatar answered Oct 28 '22 09:10

Adrian Blanco


I have a way to work around this error: java.lang.NullPointerException: Couldn't find outer class com/iconfitness/iconaudit/common/fragments/SettingsFragment$onCreate$1$1 of com/iconfitness/iconaudit/common/fragments/SettingsFragment$onCreate$1$1$1.

Just move this block code

v.showExitDialog()
              .filter { it }
              .subscribe({
                 cancel()

oo other method. I don't meet this problem anymore. I hope this will help you.

like image 1
beokh Avatar answered Oct 28 '22 07:10

beokh


The issue is filed here https://issuetracker.google.com/issues/72750890. Both solutions mentioned there worked for me: adding classpath 'com.android.tools.build:gradle:3.0.1' to build.gradle or adding android.enableD8.desugaring=true to gradle.properties

like image 1
yunik Avatar answered Oct 28 '22 07:10

yunik