Android Studio开源项目转依赖及CompressHelper依赖问题咨询
我有一个Android Studio项目,使用了com.github.nanchen2251:CompressHelper:1.0.6库,已在build.gradle的dependencies中添加implementation依赖。但同步Gradle时该依赖失败,网关返回bad request,不过我能找到其GitHub主分支。请问能否下载源码转为jar或aar直接引入项目?另外能否推荐该库的优质替代方案?
按照建议更新依赖后,构建仍失败,报错信息如下:
FAILURE: Build completed with 4 failures.
1: Task failed with an exception.
What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find compresshelper-1.0.6.jar (com.github.nanchen2251:compresshelper:1.0.6).
Searched in the following locations:
https://jitpack.io/com/github/nanchen2251/compresshelper/1.0.6/compresshelper-1.0.6.jar
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.2: Task failed with an exception.
What went wrong:
Execution failed for task ':app:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find compresshelper-1.0.6.jar (com.github.nanchen2251:compresshelper:1.0.6).
Searched in the following locations:
https://jitpack.io/com/github/nanchen2251/compresshelper/1.0.6/compresshelper-1.0.6.jar
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.3: Task failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find compresshelper-1.0.6.jar (com.github.nanchen2251:compresshelper:1.0.6).
Searched in the following locations:
https://jitpack.io/com/github/nanchen2251/compresshelper/1.0.6/compresshelper-1.0.6.jar
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.4: Task failed with an exception.
What went wrong:
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
Could not resolve all files for configuration ':app:debugCompileClasspath'.
Could not find compresshelper-1.0.6.jar (com.github.nanchen2251:compresshelper:1.0.6).
Searched in the following locations:
https://jitpack.io/com/github/nanchen2251/compresshelper/1.0.6/compresshelper-1.0.6.jar
Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 6s
49 actionable tasks: 44 executed, 5 up-to-date
一、手动将源码转为Jar/AAR引入项目
完全可以手动下载源码打包后引入,步骤如下:
- 下载源码:从该库的GitHub仓库下载完整源码,解压到本地。
- 打包为Jar:
- 打开Android Studio,将解压后的源码作为module导入项目(选择
File > New > Import Module,指向源码目录)。 - 等待同步完成后,选中该module,执行
Build > Make Module 'xxx'(xxx为module名称)。 - 编译完成后,在
module/build/libs/目录下会生成对应的jar文件。
- 打开Android Studio,将解压后的源码作为module导入项目(选择
- 引入Jar到项目:
- 将jar文件复制到项目的
app/libs/目录。 - 在
app/build.gradle的dependencies中添加:implementation files('libs/xxx.jar'),同步即可。
- 将jar文件复制到项目的
- 打包为AAR(可选):
- 同样将源码作为module导入,执行
Build > Generate Signed Bundle/APK,选择AAR并按照提示完成打包。 - 生成的AAR文件可复制到
app/libs/,然后在app/build.gradle中添加:implementation files('libs/xxx.aar')。
- 同样将源码作为module导入,执行
二、推荐的图片压缩库替代方案
- Luban:轻量级图片压缩库,基于鲁班压缩算法,支持自定义压缩参数,适配Android全版本。使用简单,只需传入图片路径即可完成压缩,输出质量和体积平衡较好。
- Compressor:支持Kotlin协程和Java调用,提供多种压缩策略(如按质量、按尺寸),可自定义压缩格式(JPEG/PNG/WebP)。内置图片旋转纠正、EXIF信息保留等功能,适合需要灵活配置的场景。
- Android Image Compressor:谷歌官方推荐的图片压缩工具类,支持批量压缩,兼容Android 10+的存储权限。提供低、中、高三种预设压缩级别,也可自定义压缩参数,稳定性强。
- TinyPng Compressor:基于TinyPNG的在线压缩API,压缩率极高,但需要网络请求,适合对图片体积要求严格且允许联网的场景。
内容的提问来源于stack exchange,提问作者Midhun Kumar

