2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 09:58:08 +00:00

Replace classindex with my own implementation that uses KSP instead of KAPT

This commit is contained in:
Albert Vaca Cintora 2024-12-04 11:52:20 +01:00
parent ecb38f2518
commit c3af9b03f6
4 changed files with 15 additions and 16 deletions

View File

@ -21,7 +21,7 @@ buildscript {
plugins { plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.kapt) alias(libs.plugins.ksp)
alias(libs.plugins.dependencyLicenseReport) alias(libs.plugins.dependencyLicenseReport)
alias(libs.plugins.compose.compiler) alias(libs.plugins.compose.compiler)
} }
@ -254,6 +254,10 @@ abstract class FixCollectionsClassVisitorFactory :
interface Params : InstrumentationParameters interface Params : InstrumentationParameters
} }
ksp {
arg("com.albertvaka.classindexksp.annotations", "org.kde.kdeconnect.Plugins.PluginFactory.LoadablePlugin")
}
androidComponents { androidComponents {
onVariants { variant -> onVariants { variant ->
variant.instrumentation.transformClassesWith( variant.instrumentation.transformClassesWith(
@ -307,8 +311,7 @@ dependencies {
//implementation("com.github.bright:slf4android:0.1.6") { transitive = true } // For org.apache.sshd debugging //implementation("com.github.bright:slf4android:0.1.6") { transitive = true } // For org.apache.sshd debugging
implementation(libs.bcpkix.jdk15on) //For SSL certificate generation implementation(libs.bcpkix.jdk15on) //For SSL certificate generation
implementation(libs.classindex) ksp(libs.classindexksp)
kapt(libs.classindex)
// The android-smsmms library is the only way I know to handle MMS in Android // The android-smsmms library is the only way I know to handle MMS in Android
// (Shouldn't a phone OS make phone things easy?) // (Shouldn't a phone OS make phone things easy?)

View File

@ -5,7 +5,7 @@ androidGradlePlugin = "8.7.3"
androidSmsmms = "kdeconnect-1-21-0" androidSmsmms = "kdeconnect-1-21-0"
appcompat = "1.7.0" appcompat = "1.7.0"
bcpkixJdk15on = "1.70" bcpkixJdk15on = "1.70"
classindex = "3.13" classindexksp = "1.1"
commonsCollections4 = "4.4" commonsCollections4 = "4.4"
commonsIo = "2.17.0" commonsIo = "2.17.0"
commonsLang3 = "3.17.0" commonsLang3 = "3.17.0"
@ -18,6 +18,7 @@ gridlayout = "1.0.0"
jsonassert = "1.5.3" jsonassert = "1.5.3"
junit = "4.13.2" junit = "4.13.2"
kotlin = "2.0.21" kotlin = "2.0.21"
kspPlugin = "2.0.21-1.0.28"
kotlinxCoroutinesCore = "1.9.0" kotlinxCoroutinesCore = "1.9.0"
lifecycleExtensions = "2.2.0" lifecycleExtensions = "2.2.0"
lifecycleRuntimeKtx = "2.8.7" lifecycleRuntimeKtx = "2.8.7"
@ -58,7 +59,7 @@ androidx-preference-ktx = { module = "androidx.preference:preference-ktx", versi
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerview" } androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerview" }
androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swiperefreshlayout" } androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swiperefreshlayout" }
bcpkix-jdk15on = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = "bcpkixJdk15on" } bcpkix-jdk15on = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = "bcpkixJdk15on" }
classindex = { module = "org.atteo.classindex:classindex", version.ref = "classindex" } classindexksp = { module = "com.github.albertvaka:classindexksp", version.ref = "classindexksp" }
commons-collections4 = { module = "org.apache.commons:commons-collections4", version.ref = "commonsCollections4" } commons-collections4 = { module = "org.apache.commons:commons-collections4", version.ref = "commonsCollections4" }
commons-io = { module = "commons-io:commons-io", version.ref = "commonsIo" } commons-io = { module = "commons-io:commons-io", version.ref = "commonsIo" }
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commonsLang3" } commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commonsLang3" }
@ -87,5 +88,5 @@ slf4j-handroid = { group = "com.gitlab.mvysny.slf4j", name = "slf4j-handroid", v
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "kspPlugin" }
dependencyLicenseReport = { id = "com.github.jk1.dependency-license-report", version.ref = "dependencyLicenseReport" } dependencyLicenseReport = { id = "com.github.jk1.dependency-license-report", version.ref = "dependencyLicenseReport" }

View File

@ -3,11 +3,9 @@ pluginManagement {
gradlePluginPortal() gradlePluginPortal()
google() google()
mavenCentral() mavenCentral()
/* Needed for org.apache.sshd debugging
maven { maven {
url = uri("https://jitpack.io") url = uri("https://jitpack.io")
} }
*/
} }
} }
dependencyResolutionManagement { dependencyResolutionManagement {

View File

@ -8,17 +8,17 @@ package org.kde.kdeconnect.Plugins
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import org.atteo.classindex.ClassIndex
import org.atteo.classindex.IndexAnnotated
import org.kde.kdeconnect.Device import org.kde.kdeconnect.Device
object PluginFactory { object PluginFactory {
annotation class LoadablePlugin //Annotate plugins with this so PluginFactory finds them
private var pluginInfo: Map<String, PluginInfo> = mapOf() private var pluginInfo: Map<String, PluginInfo> = mapOf()
fun initPluginInfo(context: Context) { fun initPluginInfo(context: Context) {
try { try {
val plugins = ClassIndex.getAnnotated(LoadablePlugin::class.java) val plugins = com.albertvaka.classindexksp.LoadablePlugin
.map { it.newInstance() as Plugin } .map { it.java.getDeclaredConstructor().newInstance() as Plugin }
.map { plugin -> plugin.apply { setContext(context, null) } } .map { plugin -> plugin.apply { setContext(context, null) } }
pluginInfo = plugins.associate { plugin -> Pair(plugin.pluginKey, PluginInfo(plugin)) } pluginInfo = plugins.associate { plugin -> Pair(plugin.pluginKey, PluginInfo(plugin)) }
@ -45,7 +45,7 @@ object PluginFactory {
fun instantiatePluginForDevice(context: Context, pluginKey: String, device: Device): Plugin? { fun instantiatePluginForDevice(context: Context, pluginKey: String, device: Device): Plugin? {
try { try {
val plugin = pluginInfo[pluginKey]?.instantiableClass?.newInstance()?.apply { setContext(context, device) } val plugin = pluginInfo[pluginKey]?.instantiableClass?.getDeclaredConstructor()?.newInstance()?.apply { setContext(context, device) }
return plugin return plugin
} catch (e: Exception) { } catch (e: Exception) {
Log.e("PluginFactory", "Could not instantiate plugin: $pluginKey", e) Log.e("PluginFactory", "Could not instantiate plugin: $pluginKey", e)
@ -67,9 +67,6 @@ object PluginFactory {
return used.map { it.key }.toSet() return used.map { it.key }.toSet()
} }
@IndexAnnotated
annotation class LoadablePlugin //Annotate plugins with this so PluginFactory finds them
class PluginInfo private constructor( class PluginInfo private constructor(
val displayName: String, val displayName: String,
val description: String, val description: String,