BUG! exception in phase 'semantic analysis'

Solution 1:

I had this BUG! exception in phase 'semantic analysis' in source unit '...' issue today and upgrading gradle (as mentioned in a comment) didn't work.

What worked for me was cleaning the gradle cache:

rm -rf $HOME/.gradle/caches/

and project gradle directory

rm -rf $PROJECT/.gradle/caches/ && rm -rf $PROJECT/build/

Related How can I force gradle to redownload dependencies?

Solution 2:

I'm seeing the same error only when I use the Java 11 JVM:

$ gradle -v

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11 (Oracle Corporation 11+28)
OS:           Mac OS X 10.14.3 x86_64

The error goes away when I drop back to Java 1.8 (I changed JAVA_HOME):

$ gradle -v

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_191 (Oracle Corporation 25.191-b12)
OS:           Mac OS X 10.14.3 x86_64

Solution 3:

My issue was that I used Java 16 and Gradle 6.5. But Gradle 6.5 does not support Java 16. I needed to upgrade to 7.0. I did this by changing gradle/wrapper/gradle-wrapper.properties in this line:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip

Solution 4:

Encountered the same problem while migrating SAP hybris from version 6.6 (java 8) to 2005 (java 11). The problem was encountered while ant clean all and recipe installation.

Error:

hybris/bin/modules/text-field-configurator-template/textfieldconfiguratortemplateocctests/testsrc/de/hybris/platform/textfieldconfiguratortemplateocctests/controllers/ProductTextfieldConfiguratorControllerTest.groovy' null

Resolution: Solved the problem by commenting/removing below property from config/local.properties

build.parallel=true

Solution 5:

I think this is cause by java version is high, or we can say gradle version is too low.

so I just use higher version Gradle. I think it's better than change JDK version to 1.8.

My config(I already have gradle 6.5, and I think maybe 6.x will satisfy):

just change the gradle version to 6.5 in android\gradle\wrapper\gradle-wrapper.properties