Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional resource inclusion/exclusion for Android apk build

I keep coming back to this problem, since there doesn't seem to be a clean solution. Does anyone have a good strategy to exclude resources from a child project in Android?

I have two scenarios:

1 - Base library project has localization files for en, es, etc.

--Child project 1 uses all localizations, and everything is good

--Child project 2 is only localized to English, but the final .apk would have a partial localization due to the parent resources (although ADT19 or so added Lint rules to warn/prevent you from doing this).

The only solution I have to this right now is to have a separate parent library for the localization, and only include it in child project 1. This is a big pain if you have lots of library projects.

2 - Exclusion of build-specific resources. I have a few images that are only needed for my Nook-specific builds of my apps, which are triggered by a flag. Conditional code works great, but the resources are always included.

I'd prefer not to create yet another child project for EVERY ONE of my apps. Is there any way to set a build/compile flag to prune specific image resources out so they don't get into the final .apk?

The second problem may be specific to me, but I'm surprised that I can't find any good discussion on the first point. Are no other devs localizing only some apps? Or are most folks just ignoring the issue?

like image 915
ProjectJourneyman Avatar asked Jul 02 '12 22:07

ProjectJourneyman


1 Answers

1 - Base library project has localization files for en, es, etc.

You have two projects using this library, and only one of them needs all the translations. Hence, those translations could be in the project using the library and needing the translations, not in the library itself. This is no different than any other project customizing resources of a library (e.g., replacing icons, replacing layouts).

Now, once you start getting into more complicated mixes (e.g., two projects need the translations and a third does not), then you start running into problems.

Exclusion of build-specific resources. I have a few images that are only needed for my Nook-specific builds of my apps, which are triggered by a flag. Conditional code works great, but the resources are always included.

Xav and I chatted a bit about conditional resources in this issue. His focus is on debug vs. production (resource equivalent to BuildConfig.DEBUG), but it sounds like something more flexible is a possibility.

Both of these things could be handled by a custom release build script. In normal debug builds, you'd leave it all alone; in a production build, have an Ant script work off a copy of the project, trimming out directories that are not needed, before compiling, signing, and zipaligning.

like image 153
CommonsWare Avatar answered Nov 14 '22 05:11

CommonsWare