Skip to content

Commit 0da9b7d

Browse files
committed
port Logger to minSdk 1
1 parent 2a1e09e commit 0da9b7d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

logger/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ android {
77
namespace = "de.binarynoise.logger"
88

99
defaultConfig {
10-
minSdk = 19
10+
minSdk = 1
1111
}
1212
}
1313

1414
dependencies {
15-
debugImplementation(libs.androidx.collection.ktx)
16-
debugImplementation(libs.androidx.core.ktx)
15+
debugCompileOnly(libs.androidx.collection.ktx)
16+
debugCompileOnly(libs.androidx.core.ktx)
1717
}

logger/src/debug/java/de/binarynoise/logger/Logger.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ object Logger {
5151
System.out.flush()
5252
}
5353

54+
55+
private val sparseArrayCompatAvailable = try {
56+
SparseArrayCompat::class.qualifiedName != null
57+
} catch (e: NoClassDefFoundError) {
58+
false
59+
}
60+
5461
private fun Any?.dump(name: String, indent: Int, processed: MutableSet<Any>, forceInclude: Set<Any>, forceIncludeClasses: Set<Class<*>>) {
5562
//<editor-fold defaultstate="collapsed" desc="...">
5663

@@ -108,7 +115,7 @@ object Logger {
108115
}
109116
}
110117
}
111-
this is SparseLongArray -> {
118+
Build.VERSION.SDK_INT >= 18 && this is SparseLongArray -> {
112119
if (this.isEmpty()) {
113120
println("[]")
114121
} else {
@@ -128,7 +135,7 @@ object Logger {
128135
}
129136
}
130137
}
131-
this is SparseArrayCompat<*> -> {
138+
sparseArrayCompatAvailable && this is SparseArrayCompat<*> -> {
132139
if (this.size() == 0) {
133140
println("[]")
134141
} else {
@@ -225,17 +232,21 @@ object Logger {
225232
it.isAccessible = true
226233
try {
227234
it.get(this).dump(it.name, nextIndent, processed, forceInclude, forceIncludeClasses)
228-
} catch (e: ReflectiveOperationException) {
229-
e.printStackTrace()
235+
} catch (e: Exception) {
236+
val cause = e.cause
237+
if (cause != null) cause.printStackTrace()
238+
else e.printStackTrace()
230239
}
231240
}
232241

233242
methods.sortedBy { it.name }.forEach {
234243
it.isAccessible = true
235244
try {
236245
it.invoke(this).dump(it.name, nextIndent, processed, forceInclude, forceIncludeClasses)
237-
} catch (e: ReflectiveOperationException) {
238-
e.printStackTrace()
246+
} catch (e: Exception) {
247+
val cause = e.cause
248+
if (cause != null) cause.printStackTrace()
249+
else e.printStackTrace()
239250
}
240251
}
241252
}

0 commit comments

Comments
 (0)