Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Package folder named 'case' in Android Studio causes hilt error

I found a very strange behavior in Android Studio. When I try to create a package case then Android Studio marks the folder as folder and not as a package:

Screenshot from Android Studio showing package folders and only the folder case does not have a dot on the icon

This is not just a UI problem. When I place a class inside the case folder and I want to use dependency injection to inject an instance of this class into a view model, the class is not found by the hilt compiler and leads to an error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@HiltViewModel annotated class should contain exactly one @Inject annotated constructor.

And the hilt generated java file is missing the class in the case folder from the constructor.

However, I can use the class normally without dependency injection in the app, so kotlin in general seems to be ok with it.

I would have blamed it as a hilt bug, but since Android Studio recognizes the folder differently I kind of curious if somebody knows why.

>Solution :

You cannot use the Java keyword. case is a keyword.

For more keys you can check: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading