Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android project not recognizing enums in library

I'm consuming a Java library that contains numerous classes and a few enums. I am using this library in an Android project in Android Studio. The classes work just fine, but Android Studio does not recognize the enums. I can't import them or use them in Java or Kotlin files. I've used these enums in a pure Java project in IntelliJ before.

When I look at the "External Dependencies" in Android Studio and find this library, the classes show as just the class name (e.g. MyClass), but these enums include .class (e.g. MyEnum.class). Not sure if that's a clue. When I click in, I see the enum file contents just fine.

Some of my Android project settings:

  • compile SDK = 33
  • min SDK = 21
  • source/target compatibility Java 1.8

Update

I found INFO level log messages corresponding to these enum classes in the Android Studio logs.

I obfuscated the package name, but this is the error I'm seeing:

INFO - #c.i.p.i.c.ClassFileStubBuilder - /Users/justin/.gradle/caches/modules-2/files-2.1/com.group/library-name/1.0.2/c5afbe59580f0678d1133deafc1d3d786e039b4b/library-name-1.0.2.jar!/com/group/library-name/FlagValueType.class: /Users/justin/.gradle/caches/modules-2/files-2.1/com.group/library-name/1.0.2/c5afbe59580f0678d1133deafc1d3d786e039b4b/library-name-1.0.2.jar!/com/group/FlagValueType.class: Cannot invoke "String.length()" because "text" is null

The error at the end is:

Cannot invoke "String.length()" because "text" is null

This error must be preventing Android Studio from parsing this file correctly.

like image 501
leros Avatar asked Mar 03 '26 08:03

leros


1 Answers

This ended up being a bug in Android Studio. Upgrading to the current release candidate resolved the issue.

like image 159
leros Avatar answered Mar 04 '26 22:03

leros



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!