Coder Social home page Coder Social logo

smallsohosolo / mcimage Goto Github PK

View Code? Open in Web Editor NEW
1.2K 19.0 144.0 949 KB

Android Gradle Plugin -- Auto Check big image and compress image in building.

License: Apache License 2.0

Java 14.68% Kotlin 85.32%
compress android android-gradle-plugin pngquant gradle

mcimage's Introduction

McImage

Gitter

I will continue to update, please rest assured to use

中文文档

Android优雅的打包时自动化获取全部res资源

McImage is a Non-invasive plugin for compress all res in your project.

Include

  • The img in Jar
  • The img in AAR
  • The img in Module

Used algorithm

Release Success!

The version 1.0.1 now support all build.gradle version! Already support mavenCentral.

Feature

  • Compress all png and jpg, every img can save %70 size.
  • As far as possible to convert img to webp (after v0.0.3 support)
  • Auto match the system which you build your project.Include Linux,Mac OS X and Windows (after v0.0.4 support)
  • Use this plugin only need one line code.

Update Log

The user use v0.0.2 update plugin need update your mctools dir together.

  • 1.5.1 : Fix windows support
  • 1.5.0 : Update gradle plugin to 3.5.0 , change the get android resources way,fix not support abbreviation(such as assembleDebug use aD) bug.
  • 1.4.0 : Feature, Support for selecting different optimization types,"ConvertWebp" or "Compress" can be chosen.Default "Compress". "CompressWebp" is a better compression ratio but it don't support api < 18
  • 1.3.0 : Feature, Support multi-thread processing
  • 1.2.0 : Feature, get compress command from system environment prior to local file
  • 1.0.1 : Bug fix, fix maxSize float error
  • 1.0.0 : Support AAPT2 , now don't need to close aapt2 with "android.enableAapt2=false", you can delete this line in gradle.properties.
  • 0.1.4 : Bug fix, add the white list feature, add the img width and height check feature.
  • 0.1.2 : Bug fix(Fix the problem that check image size not work)
  • 0.1.1 : Bug fix(Fix the problem not work for module and fix the problem of enableWhenDebug not work)
  • 0.0.4 : Add auto choose system future.Remove webpQuality config (Set inappropriate will result the img lossless)
  • 0.0.3 : Add webp ! It will auto convert your png (without alpha in min API < 18 and not work in min API < 14) and jpg to webp if it will become more small.
  • 0.0.2 : Improve the log.

Who is using

I can put your icon with one link at here if you use McImage. My email [email protected]

Use

The first, add the plugin in your project root build.gradle.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.smallsoho.mobcase:McImage:1.5.1'
    }
}

Then, apply the plugin in your every module.PS: If you have one more Module, you need apply it in every one.

apply plugin: 'McImage'

Last, put the mctools dir in your project root dir.Download it here

mctools

Config

You can set the config in build.gradle.If you not set this,all config will use default.

McImageConfig {
    isCheckSize true //Whether to detect image size,default true
    optimizeType "Compress" //Optimize Type,"ConvertWebp" or "Compress",default "Compress", "CompressWebp" is a better compression ratio but it don't support api < 18
    maxSize 1*1024*1024 //big image size threshold,default 1MB
    enableWhenDebug false //switch in debug build,default true
    isCheckPixels true // Whether to detect image pixels of width and height,default true
    maxWidth 1000 //default 1000
    maxHeight 1000 //default 1000
    whiteList = [ //do not do any optimization for the images who in the list 
              "icon_launcher.png"
    ]
    mctoolsDir "$rootDir"
    isSupportAlphaWebp false  //Whether support convert the Image with Alpha chanel to Webp,default false, the images with alpha chanels will be compressed.if config true, its need api level >=18 or do some compatible measures 
    multiThread true  //Whether open multi-thread processing,default true
    bigImageWhiteList = [] //do not detect big size or large pixels for the images who in the list
}

Thanks

pngquant

guetzli

cwebp

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

mcimage's People

Contributors

fenglei01 avatar forsail avatar jingyeoh avatar smallsohosolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mcimage's Issues

修改源文件 优化点

博主, 我跑了个demo试了下, 确实会将图片压缩为8bit并覆盖原文件, 现在有几个问题:

  1. 图片压缩到8bit后对图片的质量的压缩大吗, (特别是现在屏幕素质越来越高), 设计师会看出图片显示与提供的原图差别吗?
  2. 现在是每构建一次就进行一次压缩, 但是感觉定时压缩(比如提测前)也够了, 这方面可以自定义或者改源码实现吗?

Gradle 版本

支持的 Gradle 最低版本 4.4 么,3.3 的 Gradle 是不是用不了?

报了一个异常

McImage: optimizeImage have some Exception!!!
对于module下所有的PNG图片都是报这个错误。
配置信息:
McImageConfig {
isCheckSize true //是否检测图片大小,默认为true
optimizeType "ConvertWebp" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认Compress,使用ConvertWep需要min sdk >= 18.但是压缩效果更好
enableWhenDebug true //debug下是否可用,default true
isCheckPixels true // 是否检测大像素图片,default true
maxWidth 1000 //default 1000 如果开启图片宽高检查,默认的最大宽度
maxHeight 1000 //default 1000 如果开启图片宽高检查,默认的最大高度
whiteList = [ //默认为空,如果添加,对图片不进行任何处理

]
mctoolsDir "$rootDir"
isSupportAlphaWebp true  //是否支持带有透明度的webp,default false,带有透明图的图片会进行压缩
multiThread true  //是否开启多线程处理图片,default true
bigImageWhiteList = ['ic_mi_tv.png','ic_mi_tv_state.png','home_ad_1.png','top_tv_bg.png'] //默认为空,如果添加,大图检测将跳过这些图片

}

看了代码是没有转成功?

temp file pack into package

use debug mode,i have some picture format is jpg, your gradle plugin born some (source image name)_temp.jpg into the source same directory, and pack to the apk , so the last apk maybe larger than before use cimage

编译错误

Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with type class com.android.build.gradle.AppPlugin has not been used.
at org.gradle.api.internal.plugins.DefaultPluginContainer.getPlugin(DefaultPluginContainer.java:119)
at org.gradle.api.plugins.PluginContainer$getPlugin$0.call(Unknown Source)
at com.smallsoho.mcplugin.image.utils.AndroidUtil.getAndroidExtension(AndroidUtil.groovy:10)
at com.smallsoho.mcplugin.image.utils.AndroidUtil$getAndroidExtension$0.callStatic(Unknown Source)
at com.smallsoho.mcplugin.image.utils.AndroidUtil.getMinSdkVersion(AndroidUtil.groovy:16)
at com.smallsoho.mcplugin.image.utils.AndroidUtil$getMinSdkVersion.call(Unknown Source)
at com.smallsoho.mcplugin.image.webp.WebpUtils.isPNGConvertSupported(WebpUtils.groovy:17)
at com.smallsoho.mcplugin.image.webp.WebpUtils$isPNGConvertSupported$0.callStatic(Unknown Source)
at com.smallsoho.mcplugin.image.webp.WebpUtils.securityFormatWebp(WebpUtils.groovy:52)
at com.smallsoho.mcplugin.image.webp.WebpUtils$securityFormatWebp.call(Unknown Source)
at com.smallsoho.mcplugin.image.ImagePlugin$_apply_closure1$_closure2$_closure3$_closure4$_closure5$_closure6$_closure7.doCall(ImagePlugin.groovy:99)
at com.smallsoho.mcplugin.image.ImagePlugin$_apply_closure1$_closure2$_closure3$_closure4$_closure5$_closure6.doCall(ImagePlugin.groovy:90)
at com.smallsoho.mcplugin.image.ImagePlugin$_apply_closure1$_closure2$_closure3$_closure4$_closure5.doCall(ImagePlugin.groovy:87)
at com.smallsoho.mcplugin.image.ImagePlugin$_apply_closure1$_closure2$_closure3$_closure4.doCall(ImagePlugin.groovy:86)
at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:656)
at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(AbstractTask.java:637)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:115)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.execute(ExecuteActionsTaskExecuter.java:109)
at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:109)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:90)
... 20 more

能否根据操作系统更改指令名称?

def command = "${rootDir.getParentFile().getPath() + '/mctools/'}pngquant .......

例如:
String os = System.getProperty("os.name");
if (os != null && os.startsWith("Windows"))
{
command = "${rootDir.getParentFile().getPath() + '/mctools/'}pngquant_win .....
}

Cannot change dependencies of configuration ‘XXX’ after it has been included in dependency resolution.

错误截图提示如下:
image

image

看上去是插件内调用getDependencies出现异常,希望作者帮忙看看。(工程不引入mcImage模块时可以正常编译)


Cannot change dependencies of configuration ':platform_service:common_widget:debugApi' after it has been included in dependency resolution.


Caused by: org.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':platform_service:social_lib:mergeDebugResources'.
at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(CachingTaskDependencyResolveContext.java:66)
at org.gradle.api.internal.tasks.AbstractTaskDependency.getDependencies(AbstractTaskDependency.java:42)
at com.smallsoho.mcplugin.image.ImagePlugin$apply$1$1.execute(ImagePlugin.kt:115)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:158)
at com.smallsoho.mcplugin.image.ImagePlugin$apply$1.execute(ImagePlugin.kt:61)
at com.smallsoho.mcplugin.image.ImagePlugin$apply$1.execute(ImagePlugin.kt:16)

McImageDebug

1: Task failed with an exception.

  • What went wrong:
    Execution failed for task ':cardealertong:McImageDebug'.

sourceImg must not be null

config them into bigImageWhiteList to fix this Exception!!!

这些大图片也需要做压宿、如果都加到bigImageWhiteList里面,是否就跳过不压缩这些图片了? 要如何处理呢? 谢谢
You have big Imgages with big size or large pixels,please confirm whether they are necessary or whether they can to be compressed. If so, you can config them into bigImageWhiteList to fix this Exception!!!
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/3ef5721092263fff59a97625e14540bd/jetified-facebook-login-5.15.3/res/drawable-mdpi-v4/com_facebook_profile_picture_blank_portrait.png
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/3ef5721092263fff59a97625e14540bd/jetified-facebook-login-5.15.3/res/drawable-mdpi-v4/com_facebook_profile_picture_blank_square.png
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/e6eabd2f19b43a5b354321aca5181adc/jetified-facebook-common-5.15.3/res/drawable-xxhdpi-v4/com_facebook_close.png
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/e6eabd2f19b43a5b354321aca5181adc/jetified-facebook-common-5.15.3/res/drawable-xhdpi-v4/com_facebook_close.png
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/e6eabd2f19b43a5b354321aca5181adc/jetified-facebook-common-5.15.3/res/drawable-mdpi-v4/com_facebook_close.png
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/e6eabd2f19b43a5b354321aca5181adc/jetified-facebook-common-5.15.3/res/drawable-hdpi-v4/com_facebook_close.png
/Users/xuanwenchao/.gradle/caches/transforms-2/files-2.1/a87b407744fc773eacf256800a420224/jetified-pinpad-1.0.4/res/drawable-xxhdpi-v4/ps_backspace.png

接入过程中异常

Failed to apply plugin [id 'McImage']

java.util.LinkedHashMap cannot be cast to com.android.build.gradle.LibraryExtension

sourceImg must not be null 出现了这个问题,无法定位

Task :app:McImageRelease FAILED
---- McImage Plugin Start ----
<<<<<<<<<<<<<>>>>>>>>>>>
maxSize :1048576.0
isCheckSize: true
optimizeType: ConvertWebp
enableWhenDebug: false
isCheckPixels: true
maxWidth: 1000, maxHeight: 1000
mctoolsDir: /Users/xxx/Workspace/android/dev/xxx
isSupportAlphaWebp: false
multiThread: true
whiteList :
bigImageWhiteList:
<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:McImageRelease'.

sourceImg must not be null

请教些问题

像素检测isCheckPixels 和大图检测isCheckSize 是用来做什么的呢。
optimizeType "ConvertWebp" PNG转webp这个配置好像打包的时候并没有生效~,我的配置如下:
McImageConfig {
isCheckSize true //是否检测图片大小,默认为true
optimizeType "ConvertWebp" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认Compress,使用ConvertWep需要min sdk >= 18.但是压缩效果更好
maxSize 110241024 //大图片阈值,default 1MB
enableWhenDebug true //debug下是否可用,default true
isCheckPixels true // 是否检测大像素图片,default true
maxWidth 1000 //default 1000 如果开启图片宽高检查,默认的最大宽度
maxHeight 1000 //default 1000 如果开启图片宽高检查,默认的最大高度
whiteList = [ //默认为空,如果添加,对图片不进行任何处理
"icon_launcher.png"
]
mctoolsDir "$rootDir"
isSupportAlphaWebp false //是否支持带有透明度的webp,default false,带有透明图的图片会进行压缩
multiThread true //是否开启多线程处理图片,default true
bigImageWhiteList = [] //默认为空,如果添加,大图检测将跳过这些图片
}

不知道是哪里没有配置好~
@smallSohoSolo

为什么要下载McTool

为什么要下载McTool文件夹,直接拉webp的源码或者用libwebp.so来转码不好吗?

重复压缩可能会导致图片失真

多次执行打包命令如gradlew assembleRelease貌似会对png等多次进行压缩,这样很可能会失真。

我看代码中似乎并没有记录已经处理过的文件、并且生成的输入的文件和输出的文件都是在同一个目录(如果选择压缩那文件名也一样,如果是转webp那就是后缀不一样)。

build failed

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':app'.

Failed to notify project evaluation listener.
com.android.build.gradle.internal.api.BaseVariantImpl.getMergeResourcesProvider()Lorg/gradle/api/tasks/TaskProvider;

写了个最简单的demo

写了个最简单的demo,然后把plugin加进去,然后拷了几十张图片进去drawable-xxhdpi,然后跑起来,到mergeDebugResource这一步报错,很多张图片Duplicate resources,到目录下看,在drawable-xxhdpi有重复名字的,但是格式不同的,所以我们这个插件是生成在原有目录下的?要我们手工去删除原来的图片?
看源码好像是有比较大小删除,但是没有成功?

McImageConfig {
isCheckSize false //是否检测图片大小,默认为true
optimizeType "ConvertWebp" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认Compress,使用ConvertWep需要min sdk >= 18.但是压缩效果更好
isSupportAlphaWebp true
whiteList = [
"ic_launcher.png",
"ic_launcher_round.png",
]
maxWidth 5000 //default 1000
maxHeight 5000 //default 1000
}

gradle插件版本问题

我这边用的是4.4版的gradle,采用您提供的插件试图对png进行压缩,在打release包的时候报错
Cannot get property 'taskDependencies' on null object,是不是因为插件版本的问题

需要每个module都apply plugin吗

是不是只要最后打apk的合并资源task之前做压缩,application模块依赖就可以了?
另外压缩结果文件可以输出吗?

写了个demo,好像不能处理mipmap下的东西,直接报错跑不起来

Task :app:mergeDebugResources FAILED
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-hdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher.png"}},{"file":{"description":"mipmap-hdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-hdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher_round.png"}},{"file":{"description":"mipmap-hdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher_round.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-mdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher.png"}},{"file":{"description":"mipmap-mdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-mdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher_round.png"}},{"file":{"description":"mipmap-mdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher_round.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-xhdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher.png"}},{"file":{"description":"mipmap-xhdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-xhdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher_round.png"}},{"file":{"description":"mipmap-xhdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher_round.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-xxhdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher.png"}},{"file":{"description":"mipmap-xxhdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-xxhdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher_round.png"}},{"file":{"description":"mipmap-xxhdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher_round.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-xxxhdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png"}},{"file":{"description":"mipmap-xxxhdpi-v4/ic_launcher","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher.webp"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"mipmap-xxxhdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher_round.png"}},{"file":{"description":"mipmap-xxxhdpi-v4/ic_launcher_round","path":"D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher_round.webp"}}],"tool":"Resource and asset merger"}

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:mergeDebugResources'.

[mipmap-hdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher.png [mipmap-hdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher.webp: Error: Duplicate resources
[mipmap-hdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher_round.png [mipmap-hdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-hdpi\ic_launcher_round.webp: Error: Duplicate resources
[mipmap-mdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher.png [mipmap-mdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher.webp: Error: Duplicate resources
[mipmap-mdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher_round.png [mipmap-mdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-mdpi\ic_launcher_round.webp: Error: Duplicate resources
[mipmap-xhdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher.png [mipmap-xhdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher.webp: Error: Duplicate resources
[mipmap-xhdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher_round.png [mipmap-xhdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xhdpi\ic_launcher_round.webp: Error: Duplicate resources
[mipmap-xxhdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher.png [mipmap-xxhdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher.webp: Error: Duplicate resources
[mipmap-xxhdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher_round.png [mipmap-xxhdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxhdpi\ic_launcher_round.webp: Error: Duplicate resources
[mipmap-xxxhdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png [mipmap-xxxhdpi-v4/ic_launcher] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher.webp: Error: Duplicate resources
[mipmap-xxxhdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher_round.png [mipmap-xxxhdpi-v4/ic_launcher_round] D:\AndroidStudioProjects\McImageDemo\app\src\main\res\mipmap-xxxhdpi\ic_launcher_round.webp: Error: Duplicate resources

windows cwebp error

使用mctools/windows中的cwebp压缩png,报错:
cmd: cwebp xxx.png -o xxx.webp -m 6
CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL, CLSCTX_INPROC_SERV
ER, MAKE_REFGUID(IID_IWICImagingFactory), (LPVOID*)&factory) failed 80040154
Couldn't access Windows Imaging Component (are you running Windows XP SP3 or new
er?). Most formats not available. Use -s for the available YUV input.
报错后根据 webpFile.length() < imgFile.length(),会将原png图片删除,而webp图片未成功生成,打包时造成资源缺失

使用 libwebp-1.1.0-windows-x64-no-wic.zip 带no-wic的库后压缩成功。

操作源文件

hello,你好,这样操作的文件是不是还是项目源文件的资源图片?如果想不修改源文件的图片,仅仅是在apk中是压缩后的图片,aapt2的方式是不是不行?

不支持多module吗?

多module是并行打包的,现在会出现打包失败,资源重复或者资源找不到。

判断操作系统出错了

image
System.getProperty("os.name") 在我的机器上会返回Windows 7 以致不走任何case 直接return了。可以考虑用startWith或contain来判断

控制台输出大图监测问题

You have big Imgages with big size or large pixels,please confirm whether they are necessary or whether they can to be compressed. If so, you can config them into bigImageWhiteList to fix this Exception!!!
这些图片是需要压缩的,不添加进bigImageWhiteList,如何解决?

gradle版本兼容问题

在v1.5.0版本里面没有见有做过gradle版本兼容处理,岂不是在低版本里面会出现问题,比如'com.android.tools.build:gradle:3.1.4'

兼容问题:

  • What went wrong:
    A problem occurred configuring project ':app'.

Could not find method getMergeResourcesProvider() for arguments [] on object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.

关于插件配置问题

enableWhenDebug false //default true 是否在debug的时候启用插件

你好上面我设置了在debug下不启用插件,为啥gradle还会执行一下操作
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/follow_play_icon.png][oldInfo: 601][newInfo: 601]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/follow_time_icon.png][oldInfo: 612][newInfo: 612]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/front_photo_eg.png][oldInfo: 61624][newInfo: 61624]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/game_dice_close_black.png][oldInfo: 275][newInfo: 275]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/game_dice_img_result.png][oldInfo: 23137][newInfo: 23137]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/game_h5_help.png][oldInfo: 2559][newInfo: 2344]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/game_rank_record_dimond.png][oldInfo: 1980][newInfo: 1980]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/gift_default.png][oldInfo: 1890][newInfo: 1890]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/gift_default_chat.png][oldInfo: 2625][newInfo: 2625]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/gift_foreground_streamer.png][oldInfo: 9923][newInfo: 9546]
[Compress][/Users/zhangwei/MonkeyKingTV/build/intermediates/res/merged/appgame/debug/drawable-xxhdpi/gift_ic_lian.png][oldInfo: 747][newInfo: 747]
[Compress]

混淆问题

你好,我使用了mcImage,当我开启混淆minifyEnabled true的时候,打release包出现问题
但我关闭混淆的时候,却可以正常打包.
这是什么原因?

apply plugin存在报错

A problem occurred configuring project ':home'.
Could not determine the dependencies of task ':home:mergeDebugResources'.
Could not resolve all dependencies for configuration ':home:debugRuntimeClasspath'.
> A problem occurred configuring project ':home-api'.
> Circular referencing during evaluation for project ':home'.

问一下大佬有可能是啥原因?

javax.imageio.IIOException: Unsupported JPEG process: SOF type 0xcd

哈喽,碰到了个问题,我使用McImage,升级到最新的1.5.1,提示的是跟jpeg图片相关的问题,有点纳闷。配置么,用的就是你给的默认的配置

isCheckSize true //是否检测图片大小,默认为true
optimizeType "Compress" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认Compress,使用ConvertWep需要min sdk >= 18.但是压缩效果更好
maxSize 110241024 //大图片阈值,default 1MB
enableWhenDebug false //debug下是否可用,default true
isCheckPixels true // 是否检测大像素图片,default true
maxWidth 1000 //default 1000 如果开启图片宽高检查,默认的最大宽度
maxHeight 1000 //default 1000 如果开启图片宽高检查,默认的最大高度
whiteList = [ //默认为空,如果添加,对图片不进行任何处理
]
isSupportAlphaWebp false //是否支持带有透明度的webp,default false,带有透明图的图片会进行压缩
multiThread false //是否开启多线程处理图片,default true
bigImageWhiteList = [] //默认为空,如果添加,大图检测将跳过这些图片

报的错误如下:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':bdsm:McImageRelease'.

javax.imageio.IIOException: Unsupported JPEG process: SOF type 0xcd

  • Try:
    Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':bdsm:McImageRelease'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)

后面改成了如下形式:目前看是没有报错了
// isCheckSize false
// optimizeType "Compress"
// isCheckPixels false
// isSupportAlphaWebp false
// enableWhenDebug false
// multiThread false
// whiteList = [ //do not do any optimization for the images who in the list
// "yw_1222_baichuan.jpg", "post.jpg"
// ]

对于这种情况,也有问题,whiteList里面添加的几个jpg图片,如果我不放到白名单里面,我的app就会crash,很奇怪,对于post.jpg, 可以理解为Glide加载的时候的placeHolder占位图,我从反编译的R文件里面,都找不到post这个资源id,很是邪门。。

对于这两个问题,想听听龙博大佬的分析。

大图已加忽略,依然提醒

已给您发邮件

代码中已经添加
McImageConfig {
isCheckSize true //是否检测图片大小,默认为true
optimizeType "Compress" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认Compress,使用ConvertWep需要min sdk >= 18.但是压缩效果更好
maxSize 110241024 //大图片阈值,default 1MB
enableWhenDebug false //debug下是否可用,default true
isCheckPixels true // 是否检测大像素图片,default true
maxWidth 1000 //default 1000 如果开启图片宽高检查,默认的最大宽度
maxHeight 1000 //default 1000 如果开启图片宽高检查,默认的最大高度
whiteList = [ //默认为空,如果添加,对图片不进行任何处理
"icon_launcher.png"
]
mctoolsDir "$rootDir"
isSupportAlphaWebp false //是否支持带有透明度的webp,default false,带有透明图的图片会进行压缩
multiThread true //是否开启多线程处理图片,default true
bigImageWhiteList = [
"lib_guide_1.png",
"lib_guide_2.png",
"lib_guide_3.png",
"lib_splash.png"
] //默认为空,如果添加,大图检测将跳过这些图片
}

依然提醒

  • What went wrong:
    Execution failed for task ':app:McImageRelease'.

You have big Imgages with big size or large pixels,please confirm whether they are necessary or whether they can to be compressed. If so, you can config them into bigImageWhiteList to fix this Exception!!!
C:\Users\86189\AndroidStudioProjects\Car99\library\build\intermediates\packaged_res\release\mipmap-xhdpi-v4\lib_guide_1.png
C:\Users\86189\AndroidStudioProjects\Car99\library\build\intermediates\packaged_res\release\mipmap-xhdpi-v4\lib_guide_2.png
C:\Users\86189\AndroidStudioProjects\Car99\library\build\intermediates\packaged_res\release\mipmap-xhdpi-v4\lib_guide_3.png
C:\Users\86189\AndroidStudioProjects\Car99\library\build\intermediates\packaged_res\release\mipmap-xhdpi-v4\lib_splash.png

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.