Skip to content

Commit

Permalink
optimize R file merge rules, check whether the resource is exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
kezong committed Jul 21, 2019
1 parent 56cec29 commit 22e2a04
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion source/src/main/groovy/com/kezong/fataar/RProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class RProcessor {
if (rTxt.exists()) {
rTxt.eachLine { line ->
def (type, subclass, name, value) = line.tokenize(' ')
rMap[subclass].putAt(name, type)
if (checkValid(subclass, name)) {
rMap[subclass].putAt(name, type)
}
}
}

Expand All @@ -124,6 +126,24 @@ class RProcessor {
outputStream.close()
}

private boolean checkValid(def resourceClass, def resourceName) {
def file = mVersionAdapter.getSymbolFile()
if (!file.exists()) {
throw IllegalAccessException("{$file.absolutePath} not found")
}

def result = false
file.eachLine { line ->
def (type, subclass, name, value) = line.tokenize(' ')
if (resourceName == name && resourceClass == subclass) {
result = true
return
}
}

return result
}

private Task createRFileTask(final def destFolder) {
def task = mProject.tasks.create(name: 'createRsFile' + mVariant.name)
task.doLast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ class VersionAdapter {
return mVariant.getMergeAssets()
}
}

File getSymbolFile() {
if (Utils.compareVersion(mGradlePluginVersion, "3.1.0") >= 0) {
return mProject.file(mProject.buildDir.path + '/intermediates/symbols/' + mVariant.dirName + "/R.txt")
} else {
return mProject.file(mProject.buildDir.path + '/intermediates/bundles/' + mVariant.name + "/R.txt")
}
}
}

0 comments on commit 22e2a04

Please sign in to comment.