fix(logger): use logback-core from logback-android

This change is required because the bytecode transformations performed by AndroidIDE's Desugar Plugin does not work on androidTest classes for some reason. As a result, we use a patched version of logback-core and replace the dependency of logback-classic to use our own.
This commit is contained in:
Akash Yadav
2024-05-26 01:39:01 +05:30
parent 4370a194eb
commit 5e83554404
11 changed files with 78 additions and 51 deletions
+6
View File
@@ -56,6 +56,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
@@ -109,6 +110,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
@@ -144,6 +146,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
@@ -189,6 +192,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
@@ -236,6 +240,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
@@ -292,6 +297,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
+3
View File
@@ -0,0 +1,3 @@
[submodule "composite-builds/external/logback-android"]
path = composite-builds/external/logback-android
url = https://github.com/AndroidIDEOfficial/logback-android
-12
View File
@@ -1,11 +1,8 @@
@file:Suppress("UnstableApiUsage")
import ch.qos.logback.core.util.EnvUtil
import com.itsaky.androidide.build.config.BuildConfig
import com.itsaky.androidide.desugaring.ch.qos.logback.core.util.DesugarEnvUtil
import com.itsaky.androidide.desugaring.utils.JavaIOReplacements.applyJavaIOReplacements
import com.itsaky.androidide.plugins.AndroidIDEAssetsPlugin
import kotlin.reflect.jvm.javaMethod
plugins {
id("com.android.application")
@@ -62,18 +59,9 @@ desugaring {
replacements {
includePackage(
"org.eclipse.jgit",
"ch.qos.logback.classic.util",
)
applyJavaIOReplacements()
// EnvUtil.logbackVersion() uses newer Java APIs like Class.getModule() which is not available
// on Android. We replace the method usage with DesugarEnvUtil.logbackVersion() which
// always returns null
replaceMethod(
EnvUtil::logbackVersion.javaMethod!!,
DesugarEnvUtil::logbackVersion.javaMethod!!
)
}
}
@@ -1,36 +0,0 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.desugaring.ch.qos.logback.core.util;
/**
* @author Akash Yadav
*/
public class DesugarEnvUtil {
/**
* <p>Returns the current version of logback, or null if data is not
* available.
* </p>
*
* @since 1.3.0
* @return current version or null if missing version data
*/
static public String logbackVersion() {
return null;
}
}
@@ -0,0 +1 @@
/build
@@ -0,0 +1,49 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
//noinspection JavaPluginLanguageLevel
id("java-library")
}
java {
sourceSets.getByName("main") {
val srcDir =
rootProject.projectDir.resolve("../external/logback-android/logback-core/src/main/java")
java.srcDirs(srcDir)
val modInfo = srcDir.resolve("module-info.java")
if (modInfo.exists() && modInfo.isFile) {
modInfo.renameTo(srcDir.resolve("module-info.java.exclude"))
}
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
//noinspection UseTomlInstead GradleDynamicVersion
dependencies {
compileOnly("org.codehaus.janino:janino:+")
compileOnly("org.codehaus.janino:commons-compiler:+")
compileOnly("org.fusesource.jansi:jansi:+")
compileOnly("jakarta.mail:jakarta.mail-api:+")
compileOnly("jakarta.servlet:jakarta.servlet-api:+")
testCompileOnly("org.eclipse.angus:angus-mail:+")
testCompileOnly("org.mockito:mockito-core:+")
}
@@ -54,6 +54,7 @@ include(
":jdk-jdeps",
":jdt",
":layoutlib-api",
":logback-core",
)
rootProject.name = "build-deps"
@@ -44,7 +44,8 @@ class DesugarGradlePlugin : Plugin<Project> {
variant.instrumentation.apply {
transformClassesWith(
DesugarClassVisitorFactory::class.java, ALL) { params ->
DesugarClassVisitorFactory::class.java, ALL
) { params ->
params.setFrom(extension)
}
+8
View File
@@ -0,0 +1,8 @@
# External dependencies
This directory contains external, non-Gradle dependencies that are required to build AndroidIDE.
## Projects
- [logback-android](https://github.com/AndroidIDEOfficial/logback-android) - [Logback](https://github.com/qos-ch/logback),
but with modifications for the Android platform.
+3 -1
View File
@@ -121,7 +121,9 @@ aapt2-annotations = { module = "com.android.tools:annotations", version = "31.2.
aapt2-jb-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
aapt2-proto = { module = "com.android.tools.build:aapt2-proto", version = "8.3.0-10880808" }
logging-logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }
# use logback-core from logback-android instead
#logging-logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }
logging-logback-core = { module = "com.itsaky.androidide.build:logback-core" }
logging-logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
# XML
+5 -1
View File
@@ -27,7 +27,11 @@ dependencies {
compileOnly(projects.subprojects.frameworkStubs)
api(libs.logging.logback.core)
api(libs.logging.logback.classic)
api(libs.logging.logback.classic) {
// logback classic depends on upstream logback-core
// we exclude it and use our own from logback-android
exclude(group = "ch.qos.logback", module = "logback-core")
}
implementation(projects.buildInfo)