Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.