
Enables virtual reflection for specified packages and classes, allowing construction of objects via annotated constructors. Supports configuration through build scripts for flexible usage.
Virtual reflection of Kotlin all target
Step 1.Your app dir, build.gradle.kts add:
plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this, The left 1.7.10 corresponds to your the Kotlin version,more version: https://github.com/google/ksp/releases
}
//The fourth step of configuring ksp to generate directory reference links: https://github.com/ltttttttttttt/Buff/blob/main/README.md
dependencies {
...
implementation("io.github.ltttttttttttt:VirtualReflection-lib:$version")//this, such as 1.2.1
ksp("io.github.ltttttttttttt:VirtualReflection:$version")//this, such as 1.2.1
}plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"
}
...
val commonMain by getting {
//Configure the ksp generation directory
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
dependencies {
...
api("io.github.ltttttttttttt:VirtualReflection-lib:$version")//this, such as 1.2.1
}
}
...
dependencies {
add("kspCommonMainMetadata", "io.github.ltttttttttttt:VirtualReflection:$version")//this, such as 1.2.1
}Step 2.Use VirtualReflection
Configure packages that require virtual reflection, Your app dir, build.gradle.kts -> android(or kotlin) add:
ksp {
//Configure multiple paths separated by spaces
arg("packageListWithVirtualReflection", "com.lt.virtual_reflection.bean/*your package*/")
//Configure the generated function name, which defaults to newInstance
//arg("functionNameWithVirtualReflection", xxx)
//Configure the generated class name, which defaults to VirtualReflectionUtil
//arg("classNameWithVirtualReflection", xxx)
}use
//Constructing Objects Using Non parametric Constructors
KClass.newInstance()
//Constructing Objects Using Parametric Constructors
KClass.newInstance(parameters...)
//By string method
VirtualReflectionUtil.newInstance("MainActivity")
//Additional configuration of classes or files that can be virtually reflected
@ReflectionObject
//Configure the constructor within the path to not support virtual reflection
@NotReflectionObjectConstructorVirtual reflection of Kotlin all target
Step 1.Your app dir, build.gradle.kts add:
plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this, The left 1.7.10 corresponds to your the Kotlin version,more version: https://github.com/google/ksp/releases
}
//The fourth step of configuring ksp to generate directory reference links: https://github.com/ltttttttttttt/Buff/blob/main/README.md
dependencies {
...
implementation("io.github.ltttttttttttt:VirtualReflection-lib:$version")//this, such as 1.2.1
ksp("io.github.ltttttttttttt:VirtualReflection:$version")//this, such as 1.2.1
}plugins {
...
id("com.google.devtools.ksp") version "1.7.10-1.0.6"
}
...
val commonMain by getting {
//Configure the ksp generation directory
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
dependencies {
...
api("io.github.ltttttttttttt:VirtualReflection-lib:$version")//this, such as 1.2.1
}
}
...
dependencies {
add("kspCommonMainMetadata", "io.github.ltttttttttttt:VirtualReflection:$version")//this, such as 1.2.1
}Step 2.Use VirtualReflection
Configure packages that require virtual reflection, Your app dir, build.gradle.kts -> android(or kotlin) add:
ksp {
//Configure multiple paths separated by spaces
arg("packageListWithVirtualReflection", "com.lt.virtual_reflection.bean/*your package*/")
//Configure the generated function name, which defaults to newInstance
//arg("functionNameWithVirtualReflection", xxx)
//Configure the generated class name, which defaults to VirtualReflectionUtil
//arg("classNameWithVirtualReflection", xxx)
}use
//Constructing Objects Using Non parametric Constructors
KClass.newInstance()
//Constructing Objects Using Parametric Constructors
KClass.newInstance(parameters...)
//By string method
VirtualReflectionUtil.newInstance("MainActivity")
//Additional configuration of classes or files that can be virtually reflected
@ReflectionObject
//Configure the constructor within the path to not support virtual reflection
@NotReflectionObjectConstructor