嘿,今天的你过的还好吗
我想搭建一个公开的自用的kotlin框架...说搞就搞.
首先贴上gitee地址 https://gitee.com/ryanliushixun/KotlinBaseModel.git
因为有班要上 所以不定时更新
首先创建个kotlin的项目嗷.这是必须的.过程不必多说了.
然后开始.先搞个base.build.gradle 这个存在就是关联基类的.我这边的代码可以先贴出来
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-kapt'
android {
compileSdk = 33
defaultConfig {
minSdk = 21
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildFeatures {
dataBinding = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.8.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
//沉浸式状态栏
implementation("com.geyifeng.immersionbar:immersionbar:3.2.2")
//android utilCode
implementation("com.blankj:utilcodex:1.31.1")
//lifecycle
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
}
说到底这就是一个通用类了.
然后我创建了个model.build.gradle
作用是单独的添加一些页面会需要的
apply from: "../base.build.gradle"
android {
buildFeatures {
viewBinding true
}
}
dependencies {
// No virtual method getBindingAdapterPosition()I in class Lcom/chad/library/adapter/base/viewholder/BaseViewHolder;
implementation project(path: ':basic')
implementation project(path: ':common')
}
我创建了两个公共类.一个是basic基类和common公共类
这两个的build.gradle因为我引用了base.build.gradle所以代码比较精简
basic的build.gradle
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
apply("../base.build.gradle")
android {
namespace = "com.example.basic"
}
dependencies {
api("com.github.li-xiaojun:XPopup:2.9.19")
}
common的build.gradle
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}
apply("../base.build.gradle")
android {
namespace = "com.example.common"
}
dependencies {
//retorfit2 + rxjava
api("com.squareup.retrofit2:retrofit:2.9.0")
api("com.squareup.retrofit2:converter-scalars:2.9.0")
api("com.squareup.retrofit2:converter-gson:2.9.0")
api("com.squareup.retrofit2:adapter-rxjava2:2.9.0")
api("com.squareup.okhttp3:okhttp:5.0.0-alpha.8")
api("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.8")
api("io.reactivex.rxjava2:rxjava:2.2.18")
api("io.reactivex.rxjava2:rxandroid:2.1.1")
api("io.reactivex.rxjava2:rxkotlin:2.2.0")
api("io.reactivex.rxjava3:rxjava:3.0.4")
//MMKV
api("com.tencent:mmkv:1.3.1")
//glide
api("com.github.bumptech.glide:glide:4.16.0")
//BaseRecyclerViewAdapterHelper
api("io.github.cymchad:BaseRecyclerViewAdapterHelper:4.0.1")
//eventbus
api("org.greenrobot:eventbus:3.3.1")
//android utilCode
api("com.blankj:utilcodex:1.31.1")
//multidex分包
api("androidx.multidex:multidex:2.0.1")
//动态权限
api("com.github.getActivity:XXPermissions:16.2")
//xpopup
api("com.github.li-xiaojun:XPopup:2.9.19")
//具体版本请看顶部jitpack标识,如0.5.8,仅支持androidx DateTimePicker
api("com.github.loperSeven:DateTimePicker:0.5.8")
//依赖base库
implementation(project(mapOf("path" to ":basic")))
}
都引入了 所以省了很多乱七八糟的东西 这里强调一下.basic是谁也不依赖的那种但是谁都依赖.common是谁都需要依赖的那种.他只依赖basic
网友评论