Skip to content

Commit

Permalink
Merge branch 'dev_v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
2BAB committed Oct 10, 2018
2 parents 06e777a + ed3b90f commit 21f19c0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Only place important and recommended versions here.

## 2.3.1

- Fixed issue #3 Didn't work on icons that placed on library modules.

## 2.3.0

- Supported adaptive-icon
Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'me.2bab:scratch-paper:2.3.0'
classpath 'me.2bab:scratch-paper:2.3.1'
}
}
```
Expand All @@ -46,15 +46,7 @@ buildscript {
apply plugin: 'me.2bab.scratchpaper'
```


**0x03. Build your App and Enjoy!**

![](./images/ic_launcher.png)![](./images/ic_launcher_round.png)

![](./images/scratch-paper-json.jpg)


**0x04. Advanced Configurations**
**0x03. Advanced Configurations**

``` gradle
scratchPaper {
Expand All @@ -72,6 +64,12 @@ scratchPaper {
}
```

**0x04. Build your App and Enjoy!**

![](./images/ic_launcher.png)![](./images/ic_launcher_round.png)

![](./images/scratch-paper-json.jpg)

## Compatible

ScratchPaper only tests in Latest TWO Minor versions of Android Gradle Plugin.
Expand Down
19 changes: 9 additions & 10 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'me.2bab:scratch-paper:2.3.0'
classpath 'me.2bab:scratch-paper:2.3.1'
}
}
```
Expand All @@ -47,14 +47,7 @@ apply plugin: 'me.2bab.scratchpaper'
```


**0x03. Build your App and Enjoy!**

![](./images/ic_launcher.png)![](./images/ic_launcher_round.png)

![](./images/scratch-paper-json.jpg)


**0x04. Advanced Configurations**
**0x03. Advanced Configurations**

``` gradle
scratchPaper {
Expand All @@ -65,13 +58,19 @@ scratchPaper {
extraInfo = new Date().format("MM-dd,HH:mm")
enableGenerateIconOverlay = true
enableGenerateBuildInfo = true
// Experimental field
// @see IconOverlayGenerator#removeXmlIconFiles
enableXmlIconRemove = false
}
```

**0x04. Build your App and Enjoy!**

![](./images/ic_launcher.png)![](./images/ic_launcher_round.png)

![](./images/scratch-paper-json.jpg)

## 兼容性

ScratchPaper 只会支持最新两个 Minor 版本的 Android Gradle Plugin:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ if (project.extensions.findByName("buildScan") != null) {

// publish
group 'me.2bab'
version '2.3.0'
version '2.3.1'
apply from: 'bintray.gradle'
apply from: 'mavenlocal.gradle'
47 changes: 41 additions & 6 deletions src/main/kotlin/me/xx2bab/scratchpaper/IconOverlayGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ class IconOverlayGenerator(private val params: GeneratorParams) {
fun process() {
setAwtEnv()
params.variant.outputs.forEach { output ->
val processManifestTask: MergeManifests = output.processManifest as MergeManifests

val processManifestTask = output.processManifest as MergeManifests
val mergeResourcesTask = params.variant.mergeResources as MergeResources
if (params.config.alwaysUpdateIconInfo) {
output.processResources.outputs.upToDateWhen { false }
}
output.processResources.doFirst("process${params.dimension}IconsByScratchPaper") {
val processedIcons = arrayListOf<File>()
val mergedManifestFile = File(processManifestTask.manifestOutputDirectory,
"AndroidManifest.xml")
val resDirs = params.variant.sourceSets[0].resDirectories
val version = "@" + params.variant.mergedFlavor.versionName
val iconNames = getIconName(mergedManifestFile)
val resDirs = mergeResourcesTask.computeResourceSetList0()
findIcons(resDirs, iconNames).forEach { icon ->
val icons = addTextToIcon(params.project, params.dimension,
icon, params.config, params.dimension, version, params.config.extraInfo)
Expand Down Expand Up @@ -98,10 +101,10 @@ class IconOverlayGenerator(private val params: GeneratorParams) {
/**
* Finds all icon files matching the icon specified in the given manifest.
*/
private fun findIcons(where: Collection<File>, iconNames: Array<String>): Collection<File> {
private fun findIcons(where: List<File>?, iconNames: Array<String>): Collection<File> {
val result: MutableSet<File> = hashSetOf()
where.forEach {
it.walk()
where?.forEach {
it.walk().maxDepth(3)
.filter { dir ->
dir.name.contains("mipmap") || dir.name.contains("drawable")
}
Expand Down Expand Up @@ -162,5 +165,37 @@ class IconOverlayGenerator(private val params: GeneratorParams) {
return file.isFile && file.nameWithoutExtension == namePrefix
}

/**
* To get all original resources including libraries
*
* @link github.com/Mobcase/McImage/blob/master/src/main/java/com/smallsoho/mcplugin/image/utils/HookUtil.kt
* @author smallSohoSolo
*/
private fun MergeResources.computeResourceSetList0(): List<File>? {
val computeResourceSetListMethod = MergeResources::class.java.declaredMethods
.firstOrNull { it.name == "computeResourceSetList" && it.parameterCount == 0 }
?: return null

val oldIsAccessible = computeResourceSetListMethod.isAccessible
try {
computeResourceSetListMethod.isAccessible = true

val resourceSets = computeResourceSetListMethod.invoke(this) as? Iterable<*>

return resourceSets
?.mapNotNull { resourceSet ->
val getSourceFiles = resourceSet?.javaClass?.methods?.find {
it.name == "getSourceFiles" && it.parameterCount == 0
}
val files = getSourceFiles?.invoke(resourceSet)
@Suppress("UNCHECKED_CAST")
files as? Iterable<File>
}
?.flatten()

} finally {
computeResourceSetListMethod.isAccessible = oldIsAccessible
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ open class ScratchPaperExtension {

var extraInfo = ""

var alwaysUpdateIconInfo = true

// Experimental field
// @see IconOverlayGenerator#removeXmlIconFiles
var enableXmlIconRemove = false
Expand Down

0 comments on commit 21f19c0

Please sign in to comment.