Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.chenenyu:img-optimizer-gradle-plugin:1.2.0'
}
dependencies {
implementation("com.github.chenenyu:img-optimizer-gradle-plugin:1.2.0")
}
<dependency>
<groupId>com.github.chenenyu</groupId>
<artifactId>img-optimizer-gradle-plugin</artifactId>
<version>1.2.0</version>
</dependency>
libraryDependencies += "com.github.chenenyu" % "img-optimizer-gradle-plugin" % "1.2.0"
:dependencies [[com.github.chenenyu/img-optimizer-gradle-plugin "1.2.0"]]
A gradle plugin for optimizing PNGs, effectively reducing APK size. Both extreme compression and lossless compression are available.
Tested on macOS
、windows10
、Ubuntu16.04LTS(amd64)
. If you have any questions, plz open issues.
Add the following Gradle configuration to your build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
...
classpath 'com.chenenyu:img-optimizer:latestVersion'
}
}
Then in your moudle's build.gradle:
apply plugin: 'img-optimizer'
Now you can see the tasks in task tree:
Double click to execute the task.
You can add the following options to custom the task:
optimizerOptions {
triggerSize 5
type "lossy"
suffix "_opt"
}
triggerSize
Used for filtering pictures. Picture whose size is less than this option will be ignored. Defaults to 0.type
Now supports"lossy"
and "lossless"
。"lossy"
means extreme compression(recommend, default, fast, effective),"lossless"
means loseless compression(slow, inefficient)。suffix
The suffix of the picture which has been optimized. If "_opt"
,the optimizer will generate a new picture orignal_opt.png
for original.png
. Defaults to null.|Original png|Extreme compression(lossy)|Loseless compression(lossless)|
|:---:|:---:|:---:|
|526K|195K(reduce 63%)|473K(reduce 10%)|
||
|
|
If there are multiple modules in your project, please add the optimizer in where you want to execute optimization since each module is independent. The optimizer will generate log file in the root directory of current module.