From 3d6e550cf61a883c2731ee3f47f57c29802c5787 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:05:59 -0700 Subject: [PATCH 1/2] Use a new method to pass if debug to fix debug logging in library Currently debug logging doesn't work at all, because it never works to know if its compiled with the debug flag, that would be easy to fix, however, that causes some conflict with build and configuration cache. Additionally, libraries should not directly depend on a compile flavor. We instead set a variable in the library from the `Application.onCreate()` method in order for the *app* to tell the *library* whether it is debug or not. This also adds a new annotation, `InternalAPI` that is used for `AppDebug` since only the app should ever set that. If this part is not wanted, I can remove it, but it seems to be more standard also in other libraries to use an annotation like this for internal-only stuff. We could also replace some permanently/unstable API usages with this annotation, such as the ones in `PluginManager`, which is a better usage than `@Deprecated`. Either way whether deprecated or this annotation is used, extensions could suppress it, but using this annotation like this would prevent us internally having to add suppressions, and make it overall easier to manage. At least in my opinion. --- app/build.gradle.kts | 16 +++++----------- .../com/lagradost/cloudstream3/CloudStreamApp.kt | 4 ++++ library/build.gradle.kts | 16 +++++++--------- .../kotlin/com/lagradost/cloudstream3/MainAPI.kt | 9 +++++++++ .../cloudstream3/mvvm/ArchComponentExt.kt | 12 ++++++------ .../com/lagradost/cloudstream3/utils/AppDebug.kt | 9 +++++++++ 6 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4e58c7ea03d..eb3db51954f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -232,16 +232,7 @@ dependencies { implementation(libs.work.runtime.ktx) implementation(libs.nicehttp) // HTTP Lib - implementation(project(":library") { - // There does not seem to be a good way of getting the android flavor. - val isDebug = gradle.startParameter.taskRequests.any { task -> - task.args.any { arg -> - arg.contains("debug", true) - } - } - - this.extra.set("isDebug", isDebug) - }) + implementation(project(":library")) } tasks.register("androidSourcesJar") { @@ -278,8 +269,11 @@ tasks.withType { compilerOptions { jvmTarget.set(javaTarget) jvmDefault.set(JvmDefaultMode.ENABLE) - optIn.add("com.lagradost.cloudstream3.Prerelease") freeCompilerArgs.add("-Xannotation-default-target=param-property") + optIn.addAll( + "com.lagradost.cloudstream3.InternalAPI", + "com.lagradost.cloudstream3.Prerelease", + ) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/CloudStreamApp.kt b/app/src/main/java/com/lagradost/cloudstream3/CloudStreamApp.kt index b7832799884..ffd5ea81283 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/CloudStreamApp.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/CloudStreamApp.kt @@ -13,6 +13,7 @@ import coil3.ImageLoader import coil3.PlatformContext import coil3.SingletonImageLoader import com.lagradost.api.setContext +import com.lagradost.cloudstream3.BuildConfig import com.lagradost.cloudstream3.mvvm.safe import com.lagradost.cloudstream3.mvvm.safeAsync import com.lagradost.cloudstream3.plugins.PluginManager @@ -20,6 +21,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.utils.AppContextUtils.openBrowser +import com.lagradost.cloudstream3.utils.AppDebug import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKeys @@ -81,6 +83,8 @@ class CloudStreamApp : Application(), SingletonImageLoader.Factory { exceptionHandler = it Thread.setDefaultUncaughtExceptionHandler(it) } + + AppDebug.isDebug = BuildConfig.DEBUG } override fun attachBaseContext(base: Context?) { diff --git a/library/build.gradle.kts b/library/build.gradle.kts index a418efaab0a..cc606dd4072 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -29,7 +29,10 @@ kotlin { sourceSets { all { - languageSettings.optIn("com.lagradost.cloudstream3.Prerelease") + languageSettings { + optIn("com.lagradost.cloudstream3.InternalAPI") + optIn("com.lagradost.cloudstream3.Prerelease") + } } commonMain.dependencies { @@ -56,20 +59,15 @@ buildkonfig { exposeObjectWithName = "BuildConfig" defaultConfigs { - val isDebug = kotlin.runCatching { extra.get("isDebug") }.getOrNull() == true - if (isDebug) { - logger.quiet("Compiling library with debug flag") - } else { - logger.quiet("Compiling library with release flag") - } - buildConfigField(FieldSpec.Type.BOOLEAN, "DEBUG", isDebug.toString()) + logger.quiet("Compiling library") // Reads local.properties val localProperties = gradleLocalProperties(rootDir, project.providers) buildConfigField( FieldSpec.Type.STRING, - "MDL_API_KEY", (System.getenv("MDL_API_KEY") ?: localProperties["mdl.key"]).toString() + "MDL_API_KEY", + (System.getenv("MDL_API_KEY") ?: localProperties["mdl.key"]).toString() ) } } diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt index cce42da19c0..ab48e4f422a 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt @@ -46,6 +46,15 @@ import kotlin.math.roundToInt ) annotation class Prerelease +@Retention(AnnotationRetention.BINARY) // This is only an IDE hint, and will not be used in the runtime +@RequiresOptIn( + message = "This API is marked as internal and should not be used by extensions. " + + "Using it could cause catastrophic build or runtime errors and may " + + "be changed or removed at any time.", + level = RequiresOptIn.Level.ERROR +) +annotation class InternalAPI + /** * Defines the constant for the all languages preference, if this is set then it is * the equivalent of all languages being set diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt index 97aaf357da0..e13bcf5ec65 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/mvvm/ArchComponentExt.kt @@ -1,8 +1,8 @@ package com.lagradost.cloudstream3.mvvm -import com.lagradost.api.BuildConfig import com.lagradost.api.Log import com.lagradost.cloudstream3.ErrorLoadingException +import com.lagradost.cloudstream3.utils.AppDebug import kotlinx.coroutines.* import java.io.InterruptedIOException import java.net.SocketTimeoutException @@ -18,31 +18,31 @@ const val DEBUG_PRINT = "DEBUG PRINT" class DebugException(message: String) : Exception("$DEBUG_EXCEPTION\n$message") inline fun debugException(message: () -> String) { - if (BuildConfig.DEBUG) { + if (AppDebug.isDebug) { throw DebugException(message.invoke()) } } inline fun debugPrint(tag: String = DEBUG_PRINT, message: () -> String) { - if (BuildConfig.DEBUG) { + if (AppDebug.isDebug) { Log.d(tag, message.invoke()) } } inline fun debugWarning(message: () -> String) { - if (BuildConfig.DEBUG) { + if (AppDebug.isDebug) { logError(DebugException(message.invoke())) } } inline fun debugAssert(assert: () -> Boolean, message: () -> String) { - if (BuildConfig.DEBUG && assert.invoke()) { + if (AppDebug.isDebug && assert.invoke()) { throw DebugException(message.invoke()) } } inline fun debugWarning(assert: () -> Boolean, message: () -> String) { - if (BuildConfig.DEBUG && assert.invoke()) { + if (AppDebug.isDebug && assert.invoke()) { logError(DebugException(message.invoke())) } } diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt new file mode 100644 index 00000000000..e07f32c0a4a --- /dev/null +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt @@ -0,0 +1,9 @@ +package com.lagradost.cloudstream3.utils + +import com.lagradost.cloudstream3.InternalAPI + +@InternalAPI +object AppDebug { + @Volatile + var isDebug: Boolean = false +} From 446e19931b43a33a88f4d3c0d67d0c6e47db3eee Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 13 Dec 2025 14:42:02 -0700 Subject: [PATCH 2/2] Remove logger entirely --- library/build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/build.gradle.kts b/library/build.gradle.kts index cc606dd4072..55779a21dc8 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -59,8 +59,6 @@ buildkonfig { exposeObjectWithName = "BuildConfig" defaultConfigs { - logger.quiet("Compiling library") - // Reads local.properties val localProperties = gradleLocalProperties(rootDir, project.providers)