嘿,今天的你過的還好嗎
我想搭建一個公開的自用的kotlin框架...說搞就搞.
首先貼上gitee地址 https://gitee.com/ryanliushixun/KotlinBaseModel.git
因?yàn)橛邪嘁?所以不定時更新
首先創(chuàng)建個kotlin的項(xiàng)目嗷.這是必須的.過程不必多說了.
然后開始.先搞個base.build.gradle 這個存在就是關(guān)聯(lián)基類的.我這邊的代碼可以先貼出來
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")
//沉浸式狀態(tài)欄
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'
}
說到底這就是一個通用類了.
然后我創(chuàng)建了個model.build.gradle
作用是單獨(dú)的添加一些頁面會需要的
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')
}
我創(chuàng)建了兩個公共類.一個是basic基類和common公共類
這兩個的build.gradle因?yàn)槲乙昧薭ase.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")
//動態(tài)權(quán)限
api("com.github.getActivity:XXPermissions:16.2")
//xpopup
api("com.github.li-xiaojun:XPopup:2.9.19")
//具體版本請看頂部jitpack標(biāo)識汹碱,如0.5.8,僅支持androidx DateTimePicker
api("com.github.loperSeven:DateTimePicker:0.5.8")
//依賴base庫
implementation(project(mapOf("path" to ":basic")))
}
都引入了 所以省了很多亂七八糟的東西 這里強(qiáng)調(diào)一下.basic是誰也不依賴的那種但是誰都依賴.common是誰都需要依賴的那種.他只依賴basic