glide's kotlin annotation processor,use kotlin symbol processor(ksp)
library | version |
---|---|
kotlin | >= 1.6.21 |
ksp | 1.6.21-1.0.5 |
- add mavenCentral repository to repositories
//in root build.gradle
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
- declare kotlin symbol processor plugin and it's version without applying it if u have any other usages of ksp
// in root build.gradle
plugins {
id 'com.google.devtools.ksp' version "1.6.21-1.0.5" apply false
}
- apply kotlin symbol processor plugin in your modules which needs glide's annotation processor
// for example,my demo's application module uses glide's annotation processor
plugins {
//...
//add version if u haven't specified the version
id 'com.google.devtools.ksp' version "1.6.21-1.0.5"
}
//add ksp generated class path into sourceSets
android {
//...
sourceSets {
main {
java.srcDirs += ['build/generated/ksp']
}
}
}
//add `glide-ksp` using ksp
dependencies {
ksp "io.github.mistletoe5215:glide-ksp:1.0.0"
}
- find classes with
@GlideModule
/@GlideExtension
in previous uploaded open source library module
use ksp
options
to mark the custom LibraryGlideModules; in java annotation processor/kapt
these classes can be found usingRoundEnvironment
to find class with@GlideModule
annotation; but now in ksp ,we can't find these classes with using ksp'sResolver
orSymbolProcessorEnvironment
.see issue in ksp therefore,i can only put these class qualifiedNames into ksp compile args to solve it(so stupid ( :(,any one can help me plz push request) they're splited by "|" separator,use key namedGlideModule
the custom LibraryGlideExtensions,as well,use key namedGlideExtension
//in application's build.gradle convention scope
ksp {
arg( "GlideModule","com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule")
}
- find classes with
@GlideModule
/@GlideExtension
in new library module which has createdcom.bumptech.glide.ksp
directory
put the module's LibraryGlideModule Impl class under
com.bumptech.glide.ksp
directory ,it can be found and registered automatically
- make sure the necessary classes are generated ,they are
GeneratedAppGlideModuleImpl
,GeneratedRequestManagerFactory
,GlideApp
,GlideOption
,GlideRequest
,GlideRequests
-
then,call Glide's init in Application,set break points in
GeneratedAppGlideModuleImpl
,run app as debug mode to see whether it will block in these break points -
finally,see whether it keeps functioning properly,load image successfully as usual