From 6a5bed626a6f3d4b5e860c70d7ea042041bf78d6 Mon Sep 17 00:00:00 2001 From: yimiao Date: Tue, 20 Jul 2021 17:36:05 +0800 Subject: [PATCH] =?UTF-8?q?author:wangyimiao=20desc:=E6=B7=BB=E5=8A=A0glid?= =?UTF-8?q?e=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commonLib/build.gradle | 7 ++++++ commonLib/proguard-rules.pro | 4 ++++ commonLib/src/main/AndroidManifest.xml | 2 ++ .../commonlib/image/OkHttpLibGlideModule.kt | 22 +++++++++++++++++++ commonLibConfig.gradle | 3 ++- 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 commonLib/src/main/java/com/common/commonlib/image/OkHttpLibGlideModule.kt diff --git a/commonLib/build.gradle b/commonLib/build.gradle index 6477d38..bace06a 100644 --- a/commonLib/build.gradle +++ b/commonLib/build.gradle @@ -69,4 +69,11 @@ dependencies { //luban图片压缩 implementation rootProject.ext.dependencies.luban + + // glide + implementation rootProject.ext.dependencies.glide + // glide替换为OkHttp3代理请求 + implementation rootProject.ext.dependencies.gilde_integration + // glide注解 + kapt rootProject.ext.dependencies.annotationProcessor } \ No newline at end of file diff --git a/commonLib/proguard-rules.pro b/commonLib/proguard-rules.pro index 7f95977..049a104 100644 --- a/commonLib/proguard-rules.pro +++ b/commonLib/proguard-rules.pro @@ -129,3 +129,7 @@ public; public; } + +# 保留glide的配置类 +-keep public class * extends com.bumptech.glide.module.AppGlideModule +-keep class com.bumptech.glide.GeneratedAppGlideModuleImpl diff --git a/commonLib/src/main/AndroidManifest.xml b/commonLib/src/main/AndroidManifest.xml index 8b98006..8c78a06 100644 --- a/commonLib/src/main/AndroidManifest.xml +++ b/commonLib/src/main/AndroidManifest.xml @@ -3,4 +3,6 @@ package="com.common.commonlib"> + + \ No newline at end of file diff --git a/commonLib/src/main/java/com/common/commonlib/image/OkHttpLibGlideModule.kt b/commonLib/src/main/java/com/common/commonlib/image/OkHttpLibGlideModule.kt new file mode 100644 index 0000000..cb1ec7b --- /dev/null +++ b/commonLib/src/main/java/com/common/commonlib/image/OkHttpLibGlideModule.kt @@ -0,0 +1,22 @@ +package com.common.commonlib.image + +import android.content.Context +import com.bumptech.glide.Glide +import com.bumptech.glide.Registry +import com.bumptech.glide.annotation.GlideModule +import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader +import com.bumptech.glide.load.model.GlideUrl +import com.bumptech.glide.module.LibraryGlideModule +import java.io.InputStream + +@GlideModule +class OkHttpLibGlideModule : LibraryGlideModule() { + override fun registerComponents(context: Context, glide: Glide, registry: Registry) { + registry.replace( + GlideUrl::class.java, + InputStream::class.java, + OkHttpUrlLoader.Factory() + ) + super.registerComponents(context, glide, registry) + } +} \ No newline at end of file diff --git a/commonLibConfig.gradle b/commonLibConfig.gradle index e98bfc8..8a23e6f 100644 --- a/commonLibConfig.gradle +++ b/commonLibConfig.gradle @@ -33,7 +33,7 @@ ext { jxl : "2.6.12", navigation_fragment_ktx: "2.3.0", navigation_ui_ktx : "2.3.0", - glide : "4.11.0", + glide : "4.12.0", photo_view : "2.3.0", luban : "1.1.8", kotlin_android : "1.4.1" @@ -57,6 +57,7 @@ ext { navigation_ui_ktx : "androidx.navigation:navigation-ui-ktx:${versions.navigation_ui_ktx}", navigation_arg : "androidx.navigation:navigation-safe-args-gradle-plugin:${versions.navigation_ui_ktx}", glide : "com.github.bumptech.glide:glide:${versions.glide}", + gilde_integration : "com.github.bumptech.glide:okhttp3-integration:${versions.glide}", annotationProcessor : "com.github.bumptech.glide:compiler:${versions.glide}", photo_view : "com.github.chrisbanes:PhotoView:${versions.photo_view}", luban : "top.zibin:Luban:${versions.luban}"