diff options
author | 2016-12-03 16:36:18 +0000 | |
---|---|---|
committer | 2016-12-05 10:21:45 +0000 | |
commit | 758f81faf1d9343e1fd1f0da3fb50b772ca758f4 (patch) | |
tree | fd0c19b06f0592785b815bfcd9dc64fcdb505d19 /src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java | |
parent | d3e2d0438b72c5bb2b766330c15ca916c0e1a89c (diff) |
Fix NPE in RClassGenerator when dev has code in unnamed package
Just put the R class in the unnamed package.
If we disable the RClassGenerator and use the
old code path, we would have constructed a cmdline
flag set to "null" for aapt, and aapt would write
"package null;" which also wouldn't work...
This may allow you to build an android_library
but it may be hard to build an android_binary
because ultimately AAPT will reject an empty
"package" attribute in the AndroidManifest.xml
when you try to build the APK, so you'd need
to stamp that differently.
--
PiperOrigin-RevId: 140945125
MOS_MIGRATED_REVID=140945125
Diffstat (limited to 'src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java b/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java index 0b53d86264..deadf2831f 100644 --- a/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java +++ b/src/test/java/com/google/devtools/build/android/resources/RClassGeneratorTest.java @@ -299,6 +299,31 @@ public class RClassGeneratorTest { ); } + @Test + public void emptyPackage() throws Exception { + boolean finalFields = true; + // Make sure we handle an empty package string. + SymbolLoader symbolValues = createSymbolFile("R.txt", "int string some_string 0x7f200000"); + SymbolLoader symbolsInLibrary = symbolValues; + Path out = temp.resolve("classes"); + Files.createDirectories(out); + RClassGenerator writer = + RClassGenerator.fromSymbols( + out, "", symbolValues, ImmutableList.of(symbolsInLibrary), finalFields); + writer.write(); + + Path packageDir = out.resolve(""); + checkFilesInPackage(packageDir, "R.class", "R$string.class"); + Class<?> outerClass = checkTopLevelClass(out, "R", "R$string"); + checkInnerClass( + out, + "R$string", + outerClass, + ImmutableMap.of("some_string", 0x7f200000), + ImmutableMap.<String, List<Integer>>of(), + finalFields); + } + // Test utilities private Path createFile(String name, String... contents) throws IOException { |