Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource overlays #728

Merged
merged 3 commits into from
May 25, 2016
Merged

Conversation

jacobmattsson
Copy link
Contributor

This PR fixes #417 and #573. Note: A similar fix (in GenerateSourcesMojo.generateRForApkLibDependency()) could possibly solve #345 as well, but I haven't had time to verify that (and therefore I will not include a fix for #345 in this PR).

I tried to use resourceOverlayDirectory but ran into problems .... I have specified the following configuration in my pom:

<resourceOverlayDirectory>src/env/staging/res</resourceOverlayDirectory>

Without this fix, the project builds fine but when the app starts it (usually) crashes since the resources ids have become messed up.

The problem is the order in which the resource overlay directory and the normal resource directory (src/main/res) ends up being declared in the aapt package command. I observed that the resource overlay directory is declared after the normal resource directory:

aapt 'package' '-m' '-J' '.../target/generated-sources/r' '-f' '--no-crunch' '-M' '.../target/AndroidManifest.xml' '-S' '.../src/main/res' '-S' '.../src/env/staging/res' '-S' '.../target/unpacked-libs/cas_support-v4_23.4.0/res' ...

From the aapt man page, it's fairly obvious that the resource overlay directory must be declared before any resource directories containing resources that should be overridden:

-S  directory in which to find resources.  Multiple directories will be scanned
       and the first match found (left to right) will take precedence.

So ... with this fix, the aapt package command instead becomes:

aapt 'package' '-m' '-J' '.../target/generated-sources/r' '-f' '--no-crunch' '-M' '.../target/AndroidManifest.xml' '-S' '.../src/env/staging/res' '-S' '.../src/main/res' '-S' '.../target/unpacked-libs/cas_support-v4_23.4.0/res' ...

(with the resource overlay directory being declared first of all resources directories) and the app starts app without crashing and without resources ids being messed up.

@mosabua mosabua merged commit 5985814 into simpligility:master May 25, 2016
@jacobmattsson jacobmattsson deleted the resourceOverlays branch May 25, 2016 14:43
@mosabua
Copy link
Member

mosabua commented May 25, 2016

Will be released with 4.4.2

@jacobmattsson
Copy link
Contributor Author

Thanks for the quick response, Manfred!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

resourceOverlayDirectories broken in >= 2.8.2
2 participants