提交 d01d974e 编写于 作者: S superq_sky

Fixed bug: the resources.arsc's type ids was error when the plugin has no attrs value.

上级 dca835f0
......@@ -163,19 +163,27 @@ class ResourceCollector {
* Set the packageId specified in the build.gradle file, and reassign type&entry ID
*/
private void reassignPluginResourceId() {
//The value of aar type should be 1
def attrTypeId = 1
//Other types are allocated from 2
def lastTypeId = 2
def resourceIdList = []
pluginResources.keySet().each { String resType ->
List<ResourceEntry> entryList = pluginResources.get(resType)
resourceIdList.add([resType: resType, typeId: entryList.empty ? -100 : parseTypeIdFromResId(entryList.first().resourceId)])
}
resourceIdList.sort { t1, t2 ->
t1.typeId - t2.typeId
}
int lastType = 1
resourceIdList.each {
if (it.typeId < 0) {
return
}
def typeId = 0
def entryId = 0
if (resType == 'attr') {
typeId = attrTypeId
} else {
typeId = lastTypeId++
}
pluginResources.get(resType).each {
typeId = lastType++
pluginResources.get(it.resType).each {
it.setNewResourceId(virtualApk.packageId, typeId, entryId++)
}
}
......@@ -194,6 +202,13 @@ class ResourceCollector {
}
}
/**
* Parse the type part of a android resource id
*/
def parseTypeIdFromResId(int resourceId) {
resourceId >> 16 & 0xFF
}
/**
* Collect all resources the aar project can access
* @param aarDependenceInfo aar dependence info
......
......@@ -192,7 +192,6 @@ class ProcessResourcesHooker extends GradleTaskHooker<ProcessAndroidResources> {
*/
def convertResourcesForAapt(ListMultimap<String, ResourceEntry> pluginResources) {
def retainedTypes = []
retainedTypes.add(0, [name : 'placeholder', id : Aapt.ID_NO_ATTR, entries: []])//attr 占位
pluginResources.keySet().each { resType ->
def firstEntry = pluginResources.get(resType).get(0)
......@@ -210,13 +209,13 @@ class ProcessResourcesHooker extends GradleTaskHooker<ProcessAndroidResources> {
vs: resEntry.hexResourceId, _vs : resEntry.hexNewResourceId])
}
if (resType == 'attr') {
retainedTypes.set(0, typeEntry)
} else {
retainedTypes.add(typeEntry)
}
retainedTypes.add(typeEntry)
}
retainedTypes.sort { t1, t2 ->
t1._id - t2._id
}
return retainedTypes
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册