user316117
user316117

Reputation: 8271

Build-time resource/layout selection in Eclipse for Android?

My company ships Android devices to control industrial equipment we make. We only ship one specific device running Android 2.36 that we buy in quantity and load our own app on, so we don't have to worry about accommodating different layouts, resolutions, etc.

We have a customer in Israel who would like us to have the legends on our buttons in Hebrew. Android 2.36 doesn't have good support for Hebrew (or RTL languages in general) so what we thought we would do is replace the text for these buttons with an image of the Hebrew text.

Since Hebrew is not a supported language on these devices I can't just put the whole device in Hebrew and have Android select the layout XML files with the images instead of text to use at runtime, so I think I might have to do it at build time, in other words have some kind of switch or setting that says use THESE layout resources instead of THOSE layout resources when building a Hebrew version of our product.

My Question: What's a good way to do that? Is there a simple way to force it to use a particular set of layout XML files at build time or am I thinking about this wrong?

Upvotes: 1

Views: 102

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006869

If you're using Gradle for Android with Android Studio, this would be a fine place to use product flavors:

  • Have the bulk of your code and resources be in the main sourceset as normal
  • Define standard and hebrew product flavors in your build.gradle file
  • Have the normal (non-Hebrew) resources be in a standard sourceset
  • Have the Hebrew resources be in a hebrew sourceset

Then, a hebrew build will use the Hebrew layouts, while a standard build would use the normal layouts.

If Gradle for Android is not an option, since you control the hardware, you could drop some file in some special spot on the device, and check that when your process starts to determine if you should be in Hebrew-compatibility mode or not. This presumes that the users of the Android device do not have arbitrary access to it (so external storage would be safe) or that you inject the file into internal storage after installing your app (adb shell run-as should handle this, though I have only ever used it for read operations, not write operations).

Upvotes: 1

akadouri
akadouri

Reputation: 128

I was going to say you could use the layout-LANG to specify region based layouts, but I don't think you can do that if the language isn't supported there. https://developer.android.com/guide/topics/resources/localization.html

Does your app have a settings screen? You could simply have a setting to change all the layouts in run time.

Do you use Android Studio? Android studio allows different build profiles for debug, release, etc. You could set one up for Israel.

Upvotes: 0

Related Questions