https://github.com/ltttttttttttt/virtualreflection
Virtual reflection of KMP
https://github.com/ltttttttttttt/virtualreflection
ios jvm kmm kmp kotlin kotlin-js kotlin-jvm kotlin-native reflection virtual-reflection web
Last synced: 3 months ago
JSON representation
Virtual reflection of KMP
- Host: GitHub
- URL: https://github.com/ltttttttttttt/virtualreflection
- Owner: ltttttttttttt
- License: apache-2.0
- Created: 2023-03-02T04:34:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-29T14:57:47.000Z (3 months ago)
- Last Synced: 2025-06-29T15:37:04.789Z (3 months ago)
- Topics: ios, jvm, kmm, kmp, kotlin, kotlin-js, kotlin-jvm, kotlin-native, reflection, virtual-reflection, web
- Language: Kotlin
- Homepage:
- Size: 585 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
VirtualReflection
Virtual reflection of Kotlin all target
![]()
![]()
us English | cn 简体中文## ability
1. Set all classes in certain packages to support virtual reflection
2. Mark certain classes that can or cannot be virtually reflected through annotations## How to use
Step 1.Your app dir, build.gradle.kts add:
version
= [](https://repo1.maven.org/maven2/io/github/ltttttttttttt/VirtualReflection/)* If it is a single platform, add it to build.gradle.kts in the app module directory
```kotlin
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
}
```* If it is multi-platform, add it to build.gradle.kts in the common module directory
```kotlin
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:
```kotlin
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)
}
```use
```kotlin
//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
```