Skip to content

Commit

Permalink
Reserve all the transitive aars for the unstrict aar which specified …
Browse files Browse the repository at this point in the history
…by 'strictSplitResources=false', fix #381 and #367
  • Loading branch information
galenlin committed Jan 4, 2017
1 parent 7719481 commit f39a08c
Showing 1 changed file with 31 additions and 12 deletions.
Expand Up @@ -388,15 +388,15 @@ class AppPlugin extends BundlePlugin {
}

/** Collect the vendor aars (has resources) compiling in current bundle */
protected void collectVendorAars(Set<Map> outFirstLevelAars,
protected void collectVendorAars(Set<ResolvedDependency> outFirstLevelAars,
Set<Map> outTransitiveAars) {
project.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each {
collectVendorAars(it, outFirstLevelAars, outTransitiveAars)
}
}

protected boolean collectVendorAars(ResolvedDependency node,
Set<Map> outFirstLevelAars,
Set<ResolvedDependency> outFirstLevelAars,
Set<Map> outTransitiveAars) {
def group = node.moduleGroup,
name = node.moduleName,
Expand All @@ -420,8 +420,8 @@ class AppPlugin extends BundlePlugin {
def resDir = new File(small.aarDir, "$path/res")
// If the dependency has resources, collect it
if (resDir.exists() && resDir.list().size() > 0) {
if (outFirstLevelAars != null && !outFirstLevelAars.contains(aar)) {
outFirstLevelAars.add(aar)
if (outFirstLevelAars != null && !outFirstLevelAars.contains(node)) {
outFirstLevelAars.add(node)
}
if (!outTransitiveAars.contains(aar)) {
outTransitiveAars.add(aar)
Expand All @@ -439,12 +439,20 @@ class AppPlugin extends BundlePlugin {
}
if (!flag) return false

if (outFirstLevelAars != null && !outFirstLevelAars.contains(aar)) {
outFirstLevelAars.add(aar)
if (outFirstLevelAars != null && !outFirstLevelAars.contains(node)) {
outFirstLevelAars.add(node)
}
return true
}

protected void collectTransitiveAars(ResolvedDependency node,
Set<ResolvedDependency> outAars) {
outAars.add(node)
node.children.each {
collectTransitiveAars(it, outAars)
}
}

/**
* Prepare retained resource types and resource id maps for package slicing
*/
Expand All @@ -453,7 +461,7 @@ class AppPlugin extends BundlePlugin {
if (!idsFile.exists()) return

// Check if has any vendor aars
def firstLevelVendorAars = [] as Set<Map>
def firstLevelVendorAars = [] as Set<ResolvedDependency>
def transitiveVendorAars = [] as Set<Map>
collectVendorAars(firstLevelVendorAars, transitiveVendorAars)
if (firstLevelVendorAars.size() > 0) {
Expand All @@ -469,8 +477,16 @@ class AppPlugin extends BundlePlugin {
err.append(' }')
throw new UnsupportedOperationException(err.toString())
} else {
def aars = firstLevelVendorAars.collect{ it.name }.join('; ')
Log.warn("Using vendor aar(s): $aars")
Set<ResolvedDependency> reservedAars = new HashSet<>()
firstLevelVendorAars.each {
Log.warn("Using vendor aar '$it.name'")

// If we don't split the aar then we should reserved all it's transitive aars.
collectTransitiveAars(it, reservedAars)
}
reservedAars.each {
mUserLibAars.add(group: it.moduleGroup, name: it.moduleName, version: it.moduleVersion)
}
}
}

Expand Down Expand Up @@ -923,7 +939,7 @@ class AppPlugin extends BundlePlugin {
* TODO: filter the native libraries while exploding aar
*/
def hookMergeJniLibs(TransformTask t) {
stripAarFiles(t, { paths ->
stripAarFiles(t, { splitPaths ->
t.streamInputs.each {
def version = it.parentFile
def name = version.parentFile
Expand All @@ -932,9 +948,12 @@ class AppPlugin extends BundlePlugin {
if (root.name != 'exploded-aar') return

def aar = [group: group.name, name: name.name, version: version.name]
if (mUserLibAars.contains(aar)) return
if (mUserLibAars.contains(aar)) {
// keep the user libraries
return
}

paths.add(it)
splitPaths.add(it)
}
})
}
Expand Down

0 comments on commit f39a08c

Please sign in to comment.