介绍
- 本文基于上述doc进行一次体验记录
- 当前时间2018年4月11曰,版本号4.7
建测试项目以及引入
坑:
Failed to resolve: com.github.bumptech.glide:glide:4.7.0
Show in File
Show in Project Structure dialog
查询文档:
Android SDK 要求:
Min Sdk Version - 使用 Glide 需要 min SDK 版本 API 14 (Ice Cream Sandwich) 或更高。
Compile Sdk Version - Glide 必须使用 API 27 (Oreo MR1) 或更高版本的 SDK 来编译。
Support Library Version - Glide 使用的支持库版本为 27。
如果你需要使用不同的支持库版本
你需要在你的 build.gradle 文件里去从 Glide 的依赖中去除 “com.android.support”。例如,假如你想使用 v26 的支持库:
dependencies {
implementation ("com.github.bumptech.glide:glide:4.6.1") {
exclude group: "com.android.support"
}
implementation "com.android.support:support-fragment:26.1.0"
}
使用与 Glide 依赖的支持库不同的版本可能会导致一些运行时异常 ,例如:
java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat'
at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
也可能造成 Glide 的 API 生成器失败,从而不能正确地生成 GlideApp 类.
请参阅 https://github.com/bumptech/glide/issues/2730 获取这方面的更多信息。
修改:
App Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "pdm.zj.com.playglide4"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
compile 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}
Project Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
使用
官方
Glide.with(fragment)
.load(url)
.into(imageView);
代码地址:
https://github.com/zj614android/picsLink/blob/master/playglide4.rar