Base 模块是整个 Android 框架的核心基础模块,提供了应用的基础配置管理、日志接口定义、统计接口以及基础框架抽象类。所有其他 frame 模块都依赖于此模块。
interface IAppBase {
val debugLog: Boolean
val isRelease: Boolean
val platform: String
val deeplinkScheme: String
val deeplinkHost: String
val isProdEnv: Boolean
val appName: String
val log: ILog
}
open class BaseFrame<L : IListener> : IBaseFrame<L>, CoroutineScope {
fun dispatch(c: (l: L) -> Unit)
fun addListener(l: L)
fun removeListener(l: L)
fun clearListeners()
fun runOnSerialHandler(runnable: Runnable, delay: Long = 0L)
}
interface ILog {
fun d(tag: String, msg: String)
fun i(tag: String, msg: String)
fun e(tag: String, msg: String, e: Exception? = null)
}
// 在 Application 中初始化
AppBase.init(object : IAppBase {
override val debugLog: Boolean = BuildConfig.DEBUG
override val isRelease: Boolean = !BuildConfig.DEBUG
override val platform: String = "android"
// ... 其他配置
})
class MyManager : BaseFrame<MyListener>() {
fun notifyListeners() {
dispatch { listener ->
listener.onEvent()
}
}
fun doSomethingAsync() {
runOnSerialHandler({
// 异步操作
})
}
}
val log = AppBase.log
log.d("TAG", "Debug message")
log.i("TAG", "Info message")
log.e("TAG", "Error message", exception)
frame:zero - 零依赖模块frame:coroutine - 协程工具模块androidx.annotation - Android 注解支持kotlin-stdlib - Kotlin 标准库Base 模块是所有其他 frame 模块的基础依赖,提供了:
implementation "com.wenext.android:frame-base:6.0.2"