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?
you need covert
switch
intoif/else
code block。reference:Non-constant Fields in Case Labels