My first Kotlin Symbol Processing Tool for Android

Background of requirements

1. KSP module config


2. SymbolProcessor

fun init(
options: Map<String, String>,
kotlinVersion: KotlinVersion,
codeGenerator: CodeGenerator,
logger: KSPLogger
fun process(resolver: Resolver): List<KSAnnotated>fun finish()fun onError() {}
  1. in init() : Read Gradle script property. Set codeGenerator to member field
  2. in process() : Collect @JsonClass(generateAdapter = true)annotated class
  3. in finish() : Generate Grouped JsonAdapterFactory

3. Init()

4. process()

5. CustomKSVisitor.kt

class KSVisitor<D, R> {
fun visitFile(file: KSFile, data: D): R
fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: D): R
fun visitFunctionDeclaration(function: KSFunctionDeclaration, data: D): R
// and so on.. argument, property getter/setter

6. finish()

val packageName = "com.example"
val outputStream: OutputStream = codeGenerator.createNewFile(
dependencies = Dependencies(
* { it.containingFile!! }
packageName = packageName,
fileName = "GroupJsonAdapterFactory"
|package $packageName
|import com.squareup.moshi.JsonAdapter
|import com.squareup.moshi.Moshi
|import com.squareup.moshi.Types
|// import target classes & target classes json adapter
|class GroupJsonAdapterFactory: JsonAdapter.Factory {
| override fun create(): JsonAdapter<*> {
| // declare logics
| }

7. Resources/


7. Consumer module

8. Wth??? My IDEA isn’t aware of KSP generated file


// consumer build.gradle.kts
ksp {
// SymbolProcessor.kt
private lateinit var projectName: String
fun init(options: Map<String, String>) {
projectName = options["projectName"]
fun finish() { outputStream.write("""
|class ${projectName}JsonAdapterFactory







Android Developer, Google Developers Experts

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Insolar’s Pulsar Protocol

In the aftermath of the French Revolution and the Reign of

One Easy Trick to Understanding Object Relations in Ruby

Why I took a break from coding(and you need to too!)

How to Reset Alcatel Pixi 3 (5.5)

Hard reset Samsung galaxy

Authoring Azure DevOps Task — Overview (1)

How to get RCE on AEM instance without Java knowledge

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SeongUg Steve Jung

SeongUg Steve Jung

Android Developer, Google Developers Experts

More from Medium

A scalable Deep Link approach to navigation in Android


Novice Note: HMS Core Integration to Android Studio in Ubuntu 21.10

Android AES Cipher Encryption/Decryption - compatible with Node.js and Angular