0

I am trying to migrate an Android application that I used to develop with Eclipse to Android Studio and I am going bonkers with this migration!

The issue I am facing right now is that my application uses a ResourceBundle (containing a bunch of strings in different languages that are stored in xyz.properties-files). With eclipse I had simply placed those .properties-files in the same directory as a class "Messages" which in its constructor reads the appropriate ResourceBundle depending on the system language and then one can fetch the desired strings from that class using a getString()-method.

Now, when I build this very same project using Android Studio (or rather: using gradle) then these files are obviously missing from the generated .apk file and I get a ClassNotFoundException from the ResourceBundle.getBundle(MSGS_PROPS_NAME)-method.

Apparently - that at least what I learned from reading several threads that I had googled on the subject but of which none suggested a working solution - I need to place these files not under …/app/src/main/java/… but elsewhere in the project's file tree AND I need to add "something" to that darn build.gradle file to teach gradle to include those .properties files into the resulting apk-package so that they can then can be found and read at runtime.

Could some kind soul please describe WHERE to place such files and WHAT ONE NEEDS TO ADD to the app's build.gradle file to get this working again?

mmo
  • 3,897
  • 11
  • 42
  • 63
  • 1
    Try the options at https://stackoverflow.com/q/24724383/115145. Or, consider moving to ordinary Android string resources (`res/values/strings.xml` and kin). – CommonsWare Aug 04 '18 at 23:20
  • Thanks for responding! Following the suggested link I found a working solution by adding sourceSets.main.resources { srcDirs = ["src/main/java"]; exclude "**/*.java" } to the android {...} section of the gradle file. This allows to keep files where they originally were. But then - in an attempt to more cleanly separate such resources from code - I tried to move these files into a new directory app/src/main/resources and correspondingly changed the line to srcDirs = ["src/main/resources"] (without an exclude). That worked, too. So it seems, I have that a bit under control now. Thanks! – mmo Aug 05 '18 at 09:22
  • Re. your comment to move them to ordinary strings: these are strings that are used during program initialization, i.e. when I don't have a "Context" available, yet. Sure I could have re-arranged to do that initialization only later but then I would have to pass around that context all over my program, just to get hold of a few strings, and I hated to do that. – mmo Aug 05 '18 at 09:26

0 Answers0