Skip to content

Commit

Permalink
fix bug that remote recources can not found in R.class when build wit…
Browse files Browse the repository at this point in the history
…h gradle plugin 3.6.0
  • Loading branch information
kezong committed Apr 10, 2020
1 parent 708c763 commit 41be8b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
31 changes: 25 additions & 6 deletions source/src/main/groovy/com/kezong/fataar/RProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 41be8b7

Please sign in to comment.