Skip to content

Commit 882a467

Browse files
Googlercopybara-github
authored andcommitted
Support RPackage class generation in RClassGenerator.
RPackage class used to generate R.class fields in a way allowing updating packageId in runtime. PiperOrigin-RevId: 638359608 Change-Id: I8c047eecf7acf06436e091ca81f188ce12efba8f
1 parent b48a319 commit 882a467

File tree

10 files changed

+493
-50
lines changed

10 files changed

+493
-50
lines changed

src/test/java/com/google/devtools/build/android/RClassGeneratorActionTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,55 @@ public void noSymbolsNoRClass() throws Exception {
471471
}
472472
}
473473

474+
@Test
475+
public void withRPackage() throws Exception {
476+
Path binaryManifest =
477+
ManifestBuilder.of(tempDir.resolve("binary"))
478+
.createManifest("AndroidManifest.xml", "com.google.app", "");
479+
Path libFooManifest =
480+
ManifestBuilder.of(tempDir.resolve("libFoo"))
481+
.createManifest("AndroidManifest.xml", "com.google.foo", "");
482+
483+
Path binarySymbols =
484+
createFile("R.txt", "int attr attrName 0x7f010000", "int id idName 0x7f080000");
485+
Path libFooSymbols = createFile("libFoo.R.txt", "int id idName 0x1");
486+
487+
Path jarPath = tempDir.resolve("app_resources.jar");
488+
489+
RClassGeneratorAction.main(
490+
ImmutableList.<String>of(
491+
"--primaryRTxt",
492+
binarySymbols.toString(),
493+
"--primaryManifest",
494+
binaryManifest.toString(),
495+
"--library",
496+
libFooSymbols + "," + libFooManifest,
497+
"--classJarOutput",
498+
jarPath.toString(),
499+
"--useRPackage=true",
500+
"--targetLabel",
501+
"//foo:foo")
502+
.toArray(new String[0]));
503+
504+
assertThat(Files.exists(jarPath)).isTrue();
505+
506+
try (ZipFile zip = new ZipFile(jarPath.toFile())) {
507+
List<? extends ZipEntry> zipEntries = Collections.list(zip.entries());
508+
Iterable<String> entries = getZipFilenames(zipEntries);
509+
assertThat(entries)
510+
.containsExactly(
511+
"com/google/foo/R$id.class",
512+
"com/google/foo/R.class",
513+
"com/google/app/R$attr.class",
514+
"com/google/app/R$id.class",
515+
"com/google/app/R.class",
516+
"com/google/app/RPackage.class",
517+
"META-INF/",
518+
"META-INF/MANIFEST.MF");
519+
ZipMtimeAsserter.assertEntries(zipEntries);
520+
}
521+
}
522+
474523
private Path createFile(String name, String... contents) throws IOException {
475524
Path path = tempDir.resolve(name);
476525
Files.createDirectories(path.getParent());

0 commit comments

Comments
 (0)