Converting Android application to android library gives Error: constant expression required

322 views Asked by At

I have an Android application which I wish to convert to a library to use in another application. I have changed com.android.application to com.android.library in the apply plugin section in gradle file. Removed application id. Removed the Launcher intent in the Launcher application of library. But when I build this project I get several errors which require constant expression like in R.id.imageButton .

Some other posts indicate that ids are used inside switch cases which require 'constants'. So a workaround may be replacing switch cases with if-else constructs. But is the only way? Also, if yes, why are ids not treated as constants now that I am switching my project to a library instead of application?

1

There are 1 answers

0
delta On

you need covert switch into if/else code block。

reference:Non-constant Fields in Case Labels