Skip to content

Commit 8923c3b

Browse files
committed
Apply subset of bazelbuild#273
That PR includes a flag to use the original behavior, which we don't care about. From [the originating issue](bazelbuild#272): > Our large project include duplicated android resources. We recently > hit a bug when our developers introduced a dependency to a new third > party library, which contains an android resource with the same name > as one used in our top-level target. This is due to the fact the old > APPT1 behavior is currently preserved, and the defined resources in > the list provided to Aapt2ResourcePackagingAction 'wins'. > The expectation is that the closest value defined from the app wins. > > The project below exemplify this (bogus) behavior: app defines > resource app_name and app_name2 (with same value), depends directly (or transitively) on library lib, which defines also app_name. > In the final APK, app_name has the value from lib. > > This is problematic for projects tolerating duplicated resource, as, > even with warnings, breaks can easily be introduced as any code change > or third party library bump could possibly overwrite the value defined > in top level target. > > The workaround we're using is to reverse the input order in Aapt2ResourcePackagingAction.
1 parent 8138082 commit 8923c3b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/tools/java/com/google/devtools/build/android/Aapt2ResourcePackagingAction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.IOException;
4242
import java.nio.file.Files;
4343
import java.nio.file.Path;
44+
import java.util.Collections;
4445
import java.util.List;
4546
import java.util.Optional;
4647

@@ -354,9 +355,10 @@ public static void main(String[] args) throws Exception {
354355
List<CompiledResources> compiledResourceDeps =
355356
// Last defined dependencies will overwrite previous one, so always place direct
356357
// after transitive.
357-
concat(options.transitiveData.stream(), options.directData.stream())
358-
.map(DependencyAndroidData::getCompiledSymbols)
359-
.collect(toList());
358+
concat(options.directData.stream(), options.transitiveData.stream())
359+
.map(DependencyAndroidData::getCompiledSymbols)
360+
.collect(toList());
361+
Collections.reverse(compiledResourceDeps);
360362

361363
// NB: "-A" options are in *decreasing* precedence, while "-R" options are in *increasing*
362364
// precedence. While this is internally inconsistent, it matches AAPTv1's treatment of "-A".

0 commit comments

Comments
 (0)