chore: 重构项目版本状态逻辑,更改为打包时自动修改
This commit is contained in:
@ -374,7 +374,7 @@ fun test() {
|
||||
|
||||
### Coil
|
||||
|
||||
**Coil **是一个 Android 图片加载库,通过 Kotlin 协程的方式加载图片。特点如下:
|
||||
**Coil** 是一个 Android 图片加载库,通过 Kotlin 协程的方式加载图片。特点如下:
|
||||
|
||||
- **更快**: Coil 在性能上有很多优化,包括内存缓存和磁盘缓存,把缩略图存保存在内存中,循环利用 bitmap,自动暂停和取消图片网络请求等。
|
||||
- **更轻量级**: Coil 只有2000个方法(前提是你的 APP 里面集成了 OkHttp 和 Coroutines),Coil 和 Picasso 的方法数差不多,相比 Glide 和 Fresco 要轻量很多。
|
||||
|
||||
@ -40,35 +40,36 @@ android {
|
||||
// }
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// 对应 ALPHA 版本
|
||||
debug {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.ALPHA}\""
|
||||
// signingConfig signingConfigs.releaseConfig
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
if (outputFileName != null
|
||||
&& outputFileName.endsWith('.apk')
|
||||
&& 'release' == variant.buildType.name) {
|
||||
outputFileName = "${ProjectBuildConfig.applicationId}" +
|
||||
"_${ProjectBuildConfig.versionCode}" +
|
||||
"(${ProjectBuildConfig.versionName}).apk"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
debug {
|
||||
beta {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.BETA}\""
|
||||
// signingConfig signingConfigs.releaseConfig
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
if (outputFileName != null
|
||||
&& outputFileName.endsWith('.apk')
|
||||
&& 'debug' == variant.buildType.name) {
|
||||
outputFileName = "${ProjectBuildConfig.applicationId}" +
|
||||
"_${ProjectBuildConfig.versionCode}" +
|
||||
"(${ProjectBuildConfig.versionName}).apk"
|
||||
}
|
||||
}
|
||||
}
|
||||
release {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.RELEASE}\""
|
||||
// signingConfig signingConfigs.releaseConfig
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义打包apk的文件名
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
if (outputFileName != null && outputFileName.endsWith('.apk')) {
|
||||
outputFileName = "${ProjectBuildConfig.applicationId}" +
|
||||
"_${ProjectBuildConfig.versionCode}" +
|
||||
"(${ProjectBuildConfig.versionName})" +
|
||||
"_${variant.buildType.name}" +
|
||||
".apk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,25 @@ android {
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
// 对应 ALPHA 版本
|
||||
debug {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.ALPHA}\""
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
beta {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.BETA}\""
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
release {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.RELEASE}\""
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kapt {
|
||||
|
||||
@ -56,11 +56,19 @@ android {
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// 对应 ALPHA 版本
|
||||
debug {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.ALPHA}\""
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
debug {
|
||||
beta {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.BETA}\""
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
release {
|
||||
buildConfigField "String", "VERSION_TYPE", "\"${ProjectBuildConfig.Version.RELEASE}\""
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
@ -19,8 +19,14 @@ object ProjectBuildConfig {
|
||||
/**
|
||||
* 项目当前的版本状态
|
||||
* 该状态直接反映当前App是测试版 还是正式版 或者预览版
|
||||
* 打包前记得修改该状态
|
||||
* 正式版:RELEASE、预览版(α)-内部测试版:ALPHA、测试版(β)-公开测试版:BETA
|
||||
*/
|
||||
const val versionStatus = /*"VERSION_STATUS_RELEASE"*/ "VERSION_STATUS_ALPHA" /*"VERSION_STATUS_BETA"*/
|
||||
object Version {
|
||||
|
||||
const val RELEASE = "VERSION_STATUS_RELEASE"
|
||||
|
||||
const val ALPHA = "VERSION_STATUS_ALPHA"
|
||||
|
||||
const val BETA = "VERSION_STATUS_BETA"
|
||||
}
|
||||
}
|
||||
@ -9,8 +9,6 @@ import com.quyunshuo.androidbaseframemvvm.buildsrc.*
|
||||
android {
|
||||
|
||||
defaultConfig {
|
||||
// 相关自定义配置
|
||||
resValue "string", "VERSION_STATUS", ProjectBuildConfig.versionStatus
|
||||
resValue "string", "BUGLY_APP_ID", SDKKeyConfig.BUGLY_APP_ID
|
||||
}
|
||||
|
||||
|
||||
@ -27,11 +27,6 @@ import com.tencent.smtt.sdk.QbSdk.PreInitCallback
|
||||
@AutoService(ApplicationLifecycle::class)
|
||||
class CommonApplication : ApplicationLifecycle {
|
||||
|
||||
/**
|
||||
* 项目当前的版本状态
|
||||
*/
|
||||
val versionStatus: String by lazy { BaseApplication.context.getString(R.string.VERSION_STATUS) }
|
||||
|
||||
companion object {
|
||||
// 全局CommonApplication
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@ -132,7 +127,7 @@ class CommonApplication : ApplicationLifecycle {
|
||||
*/
|
||||
private fun initARouter(): String {
|
||||
// 测试环境下打开ARouter的日志和调试模式 正式环境需要关闭
|
||||
if (versionStatus == VersionStatus.ALPHA || versionStatus == VersionStatus.BETA) {
|
||||
if (BuildConfig.VERSION_TYPE != VersionStatus.RELEASE) {
|
||||
ARouter.openLog() // 打印日志
|
||||
ARouter.openDebug() // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
|
||||
}
|
||||
@ -150,7 +145,7 @@ class CommonApplication : ApplicationLifecycle {
|
||||
CrashReport.initCrashReport(
|
||||
BaseApplication.context,
|
||||
BaseApplication.context.getString(R.string.BUGLY_APP_ID),
|
||||
versionStatus == VersionStatus.ALPHA || versionStatus == VersionStatus.BETA
|
||||
BuildConfig.VERSION_TYPE != VersionStatus.RELEASE
|
||||
)
|
||||
return "Bugly -->> init complete"
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.di
|
||||
|
||||
import com.quyunshuo.androidbaseframemvvm.base.BuildConfig
|
||||
import com.quyunshuo.androidbaseframemvvm.base.constant.VersionStatus
|
||||
import com.quyunshuo.androidbaseframemvvm.common.constant.NetBaseUrlConstant
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
@ -34,7 +35,7 @@ class DINetworkModule {
|
||||
@Provides
|
||||
fun provideOkHttpClient(): OkHttpClient {
|
||||
// 日志拦截器部分
|
||||
val level = if (BuildConfig.DEBUG) BODY else NONE
|
||||
val level = if (BuildConfig.VERSION_TYPE != VersionStatus.RELEASE) BODY else NONE
|
||||
val logInterceptor = HttpLoggingInterceptor().setLevel(level)
|
||||
|
||||
return OkHttpClient.Builder()
|
||||
|
||||
Reference in New Issue
Block a user