From a5851ac47f5ba7ef3e38373fea22feb4885738b1 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 19 Jul 2016 23:35:54 +0000 Subject: Plumb customPackage to RClassGenerator and skip empty R classes Forgot to do this, so we get compiler errors since it can't find the R class imported under the requested custom java package. Also, avoid writing out the top-level R.class file if there are no symbols. There is a test that happens to check for this. -- MOS_MIGRATED_REVID=127888913 --- .../google/devtools/build/android/resources/RClassGenerator.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/tools/android/java/com/google/devtools/build/android/resources') diff --git a/src/tools/android/java/com/google/devtools/build/android/resources/RClassGenerator.java b/src/tools/android/java/com/google/devtools/build/android/resources/RClassGenerator.java index be25c0f6fa..8735e9ba8c 100644 --- a/src/tools/android/java/com/google/devtools/build/android/resources/RClassGenerator.java +++ b/src/tools/android/java/com/google/devtools/build/android/resources/RClassGenerator.java @@ -109,7 +109,14 @@ public class RClassGenerator { packageDir = new File(packageDir, folder); } File rClassFile = new File(packageDir, SdkConstants.FN_COMPILED_RESOURCE_CLASS); + // At least create the outFolder that was requested. However, if there are no symbols, don't + // create the R.class and inner class files (no need to have an empty class). Files.createParentDirs(rClassFile); + Table symbols = getAllSymbols(); + if (symbols.isEmpty()) { + return; + } + String packageWithSlashes = packageName.replaceAll("\\.", "/"); String rClassName = packageWithSlashes + "/R"; ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); @@ -119,9 +126,7 @@ public class RClassGenerator { classWriter.visitSource(SdkConstants.FN_RESOURCE_CLASS, null); writeConstructor(classWriter); - Table symbols = getAllSymbols(); Table values = getSymbols(symbolValues); - Set rowSet = symbols.rowKeySet(); List rowList = new ArrayList<>(rowSet); Collections.sort(rowList); -- cgit v1.2.3