0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Arka Prava Basu
  • 2,366
  • 3
  • 18
  • 34
  • http://stackoverflow.com/questions/17614250/convert-existing-project-to-library-project-in-android-studio – IntelliJ Amiya Dec 30 '16 at 08:56
  • 1
    @IntelliJAmiya i have seen the link, it mostly tells us to update the plugin in gradle file. As mentioned I did that and on rebuilding I get those "constant expression required" errors. – Arka Prava Basu Dec 30 '16 at 09:16

1 Answers1

1

you need covert switch into if/else code block。

reference:Non-constant Fields in Case Labels

delta
  • 11
  • 2