From 41be8b7cfc62b2460c43b449ea5add7246bcb7d1 Mon Sep 17 00:00:00 2001 From: kezong <379977@qq.com> Date: Fri, 10 Apr 2020 22:05:37 +0800 Subject: [PATCH] fix bug that remote recources can not found in R.class when build with gradle plugin 3.6.0 --- .../com/kezong/fataar/RProcessor.groovy | 31 +++++++++++++++---- .../com/kezong/fataar/VersionAdapter.groovy | 9 ++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy index a89a0c9a..10d9ed13 100644 --- a/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy +++ b/source/src/main/groovy/com/kezong/fataar/RProcessor.groovy @@ -101,7 +101,7 @@ class RProcessor { if (rTxt.exists()) { rTxt.eachLine { line -> def (type, subclass, name, value) = line.tokenize(' ') - if (symbolsMap.containsKey(subclass) && symbolsMap.get(subclass).getAt(name) == type) { + if (symbolsMap.containsKey(subclass) && symbolsMap.get(subclass).containsKey(name)) { rMap[subclass].putAt(name, type) } } @@ -127,17 +127,36 @@ class RProcessor { } private def getSymbolsMap() { - def file = mVersionAdapter.getSymbolFile() + def file = mVersionAdapter.getLocalSymbolFile() if (!file.exists()) { throw IllegalAccessException("{$file.absolutePath} not found") } def map = new ConfigObject() - file.eachLine { line -> - def (type, subclass, name, value) = line.tokenize(' ') - map[subclass].putAt(name, type) - } + if (file.name == "R-def.txt") { + // R-def.txt is a local symbol file that format is different of R.txt + file.eachLine { line -> + List splits = line.tokenize(' ') + if (splits == null || splits.size() < 2) { + return + } + def subclass = splits.get(0) + def name = splits.get(1) + map[subclass].putAt(name, 1) + if (subclass == "styleable" && splits.size() > 2) { + for (int i = 2; i < splits.size(); ++i) { + String subStyle = splits.get(i).replace(':', "_") + map[subclass].putAt("${name}_$subStyle", 1) + } + } + } + } else { + file.eachLine { line -> + def (type, subclass, name, value) = line.tokenize(' ') + map[subclass].putAt(name, type) + } + } return map } diff --git a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy index 2bb6c84e..5dd9bf05 100644 --- a/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy +++ b/source/src/main/groovy/com/kezong/fataar/VersionAdapter.groovy @@ -82,9 +82,14 @@ class VersionAdapter { } } - File getSymbolFile() { + /** + * return symbol file without remote resources + * @return symbol file like R.txt + */ + File getLocalSymbolFile() { + // > 3.6.0, R.txt contains remote resources, so we use R-def.txt if (Utils.compareVersion(mGradlePluginVersion, "3.6.0") >= 0) { - return mProject.file(mProject.buildDir.path + '/intermediates/compile_symbol_list/' + mVariant.name + "/R.txt") + return mProject.file(mProject.buildDir.path + '/intermediates/local_only_symbol_list/' + mVariant.name + "/R-def.txt") } else if (Utils.compareVersion(mGradlePluginVersion, "3.1.0") >= 0) { return mProject.file(mProject.buildDir.path + '/intermediates/symbols/' + mVariant.dirName + "/R.txt") } else {