-
Notifications
You must be signed in to change notification settings - Fork 10
Changes from all commits
da45a31
3fe400a
1d5eddb
2906cae
a9d663c
f236d85
c0a0bc5
aacb9bf
942a27e
b94fc23
2c0f120
e8c6b6b
c256a60
f19c722
4a4ad58
2fa997d
88a828b
eed9fd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| setupApp(appPackageName, appName) | ||
| setupApp(AppModule.App) | ||
|
|
||
| dependencies { | ||
| implementations( | ||
| // projects | ||
| project(Module.Login.moduleName), | ||
| project(Module.Main.moduleName), | ||
| // project(Module.Map.moduleName), | ||
| project(Module.Web.moduleName) | ||
| project(LibModule.Login.moduleName), | ||
| project(LibModule.Main.moduleName), | ||
| project(LibModule.Web.moduleName) | ||
| ) | ||
| debugImplementations(Libs.leakCanary) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,32 @@ | ||
| @file:Suppress("SpellCheckingInspection") | ||
|
|
||
| enum class Module(val tag: String, val runAlone: Boolean = false) { | ||
| // TODO: Make Module sealed | ||
| interface Module { | ||
| val tag: String | ||
| } | ||
|
Comment on lines
+3
to
+6
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems issues in |
||
|
|
||
| enum class LibModule(override val tag: String) : Module { | ||
| //---------------------base-------------------------------// | ||
| Base("base"), | ||
| Common("common"), | ||
|
|
||
| //---------------------biz-------------------------------// | ||
| Login("login"), | ||
| Main("main"), | ||
| Map("map"), | ||
| Web("web"), | ||
|
|
||
| //---------------------func-------------------------------// | ||
| Adapter("adapter"), | ||
|
|
||
| //---------------------app-------------------------------// | ||
| App("app"), | ||
| Test("test") | ||
| } | ||
|
|
||
| enum class Flavor { | ||
| Daily, | ||
| Online | ||
| Adapter("adapter") | ||
| } | ||
|
|
||
| enum class BuildConfigField(val tag: String) { | ||
| VersionCode("VERSION_CODE"), | ||
| VersionName("VERSION_NAME"), | ||
| CdnPrefix("CDN_PREFIX"), | ||
| ApiHost("API_HOST"), | ||
| DoraemonKitKey("DORAEMON_KIT_KEY") | ||
| enum class AppModule(override val tag: String, val appName: String, val appId: String) : Module { | ||
| App("app", "Demo", "io.goooler.demoapp"), | ||
| Test("app", "Test", "io.goooler.test") | ||
|
Comment on lines
+22
to
+24
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate app modules to new enum classes. |
||
| } | ||
|
|
||
| enum class ApiKey(val key: String) { | ||
| DoraemonKit("4a8c3eef29f029bc197705faad83f43d"), | ||
| AmapDebug("419ff22368500a49f0d894ac80d08725"), | ||
| AmapRelease("ab0ee784fe95f3de2af3db07e11c37ed") | ||
| enum class BuildConfigField(val key: String, val value: Any) { | ||
| VersionCode("VERSION_CODE", appVersionCode), | ||
| VersionName("VERSION_NAME", appVersionName), | ||
| CdnPrefix("CDN_PREFIX", "https://raw.githubusercontent.com/"), | ||
| ApiHost("API_HOST", "https://api.github.com/") | ||
|
Comment on lines
+27
to
+31
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bundle keys and values. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,10 @@ | ||
| @file:Suppress("UnstableApiUsage") | ||
|
|
||
| import com.android.build.api.dsl.CommonExtension | ||
| import com.android.build.api.dsl.VariantDimension | ||
| import com.android.build.gradle.BaseExtension | ||
| import com.android.build.gradle.LibraryExtension | ||
| import com.android.build.gradle.internal.api.ApkVariantOutputImpl | ||
| import com.android.build.gradle.internal.dsl.BaseAppModuleExtension | ||
| import java.io.File | ||
| import java.util.Locale | ||
| import java.util.Properties | ||
| import kotlin.math.pow | ||
| import org.gradle.api.JavaVersion | ||
|
|
@@ -23,15 +20,6 @@ import org.gradle.kotlin.dsl.get | |
| import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions | ||
| import org.jetbrains.kotlin.gradle.plugin.KaptExtension | ||
|
|
||
| const val cdnPrefix = "https://raw.githubusercontent.com/" | ||
| val apiHosts = mapOf( | ||
| Flavor.Daily.name to "https://api.github.com/", | ||
| Flavor.Online.name to "https://api.github.com/" | ||
| ) | ||
|
|
||
| // app | ||
| const val appPackageName = "io.goooler.demoapp" | ||
| const val appName = "Demo" | ||
| const val extraScriptPath = "gradle/extra.gradle.kts" | ||
| val javaVersion = JavaVersion.VERSION_11 | ||
| const val appVersionName = "1.5.0" | ||
|
|
@@ -77,12 +65,12 @@ fun PluginAware.applyPlugins(vararg names: String) { | |
| } | ||
| } | ||
|
|
||
| fun VariantDimension.putBuildConfigStringField(name: String, value: String?) { | ||
| buildConfigField("String", name, "\"$value\"") | ||
| } | ||
|
|
||
| fun VariantDimension.putBuildConfigIntField(name: String, value: Int) { | ||
| buildConfigField("Integer", name, value.toString()) | ||
|
Comment on lines
-80
to
-85
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge two functions to a new one. |
||
| fun VariantDimension.buildConfigField(field: BuildConfigField) { | ||
| if (field.value is Int) { | ||
| buildConfigField("Integer", field.key, field.value.toString()) | ||
| } else if (field.value is String) { | ||
| buildConfigField("String", field.key, "\"${field.value}\"") | ||
| } | ||
| } | ||
|
|
||
| fun BaseExtension.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { | ||
|
|
@@ -92,7 +80,7 @@ fun BaseExtension.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { | |
| fun Project.kapt(block: KaptExtension.() -> Unit) = configure(block) | ||
|
|
||
| inline fun <reified T : BaseExtension> Project.setupBase( | ||
| module: Module? = null, | ||
| module: Module, | ||
| crossinline block: T.() -> Unit = {} | ||
| ) { | ||
| when (T::class) { | ||
|
|
@@ -103,15 +91,13 @@ inline fun <reified T : BaseExtension> Project.setupBase( | |
|
|
||
| applyPlugins(Plugins.kotlinAndroid, Plugins.kotlinKapt) | ||
| extensions.configure<BaseExtension>("android") { | ||
| resourcePrefix = "${module.tag}_" | ||
| compileSdkVersion(32) | ||
| defaultConfig { | ||
| minSdk = 21 | ||
| vectorDrawables.useSupportLibrary = true | ||
| ndk.abiFilters += setOf("arm64-v8a") | ||
| module?.let { | ||
| resourcePrefix = "${it.tag}_" | ||
| versionNameSuffix = "_${it.tag}" | ||
| } | ||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
| sourceSets.configureEach { | ||
| java.srcDirs("src/$name/kotlin") | ||
|
|
@@ -164,21 +150,20 @@ inline fun <reified T : BaseExtension> Project.setupBase( | |
| } | ||
|
|
||
| fun Project.setupLib( | ||
| module: Module? = null, | ||
| module: LibModule, | ||
| block: LibraryExtension.() -> Unit = {} | ||
| ) = setupCommon(module, block) | ||
|
|
||
| fun Project.setupApp( | ||
| appPackageName: String, | ||
| appName: String, | ||
| module: AppModule, | ||
| block: BaseAppModuleExtension.() -> Unit = {} | ||
| ) = setupCommon<BaseAppModuleExtension> { | ||
| ) = setupCommon<BaseAppModuleExtension>(module) { | ||
| defaultConfig { | ||
| applicationId = appPackageName | ||
| applicationId = module.appId | ||
| targetSdk = 32 | ||
| versionCode = appVersionCode | ||
| versionName = appVersionName | ||
| manifestPlaceholders += mapOf("appName" to appName) | ||
| manifestPlaceholders += mapOf("appName" to module.appName) | ||
| resourceConfigurations += setOf("en", "zh-rCN", "xxhdpi") | ||
| } | ||
| signingConfigs.create("release") { | ||
|
|
@@ -191,16 +176,16 @@ fun Project.setupApp( | |
| } | ||
| buildTypes { | ||
| release { | ||
| resValue("string", "app_name", appName) | ||
| resValue("string", "app_name", module.appName) | ||
| signingConfig = signingConfigs["release"] | ||
| isMinifyEnabled = true | ||
| isShrinkResources = true | ||
| proguardFiles("$rootDir/gradle/proguard-rules.pro") | ||
| } | ||
| debug { | ||
| resValue("string", "app_name", "${appName}.debug") | ||
| resValue("string", "app_name", "${module.appName}.debug") | ||
| signingConfig = signingConfigs["release"] | ||
| applicationIdSuffix = ".debug" | ||
| versionNameSuffix = ".debug" | ||
| isJniDebuggable = true | ||
| isRenderscriptDebuggable = true | ||
| isCrunchPngs = false | ||
|
|
@@ -209,22 +194,21 @@ fun Project.setupApp( | |
| dependenciesInfo.includeInApk = false | ||
| applicationVariants.all { | ||
| outputs.all { | ||
| (this as? ApkVariantOutputImpl)?.outputFileName = | ||
| "../../../../${appName}_${versionName}_${versionCode}_" + | ||
| "${flavorName.toLowerCase(Locale.ROOT)}_${buildType.name}.apk" | ||
| (this as? ApkVariantOutputImpl)?.outputFileName = "../../../../" + | ||
| "${module.appName}_${versionName}_${versionCode}_${flavorName}_${buildType.name}.apk" | ||
| } | ||
| } | ||
| block() | ||
| } | ||
|
|
||
| private inline fun <reified T : BaseExtension> Project.setupCommon( | ||
| module: Module? = null, | ||
| module: Module, | ||
| crossinline block: T.() -> Unit = {} | ||
| ) = setupBase<T>(module) { | ||
| flavorDimensions("channel") | ||
| productFlavors { | ||
| create(Flavor.Daily.name) | ||
| create(Flavor.Online.name) | ||
| create("daily") | ||
| create("online") | ||
| } | ||
| kapt { | ||
| arguments { | ||
|
|
@@ -233,30 +217,14 @@ private inline fun <reified T : BaseExtension> Project.setupCommon( | |
| } | ||
| } | ||
| dependencies { | ||
| if (module != Module.Common) { | ||
| implementations(project(Module.Common.moduleName)) | ||
| if (module != LibModule.Common) { | ||
| implementations(project(LibModule.Common.moduleName)) | ||
| } | ||
| implementations( | ||
| project(Module.Base.moduleName), | ||
| project(Module.Adapter.moduleName), | ||
|
|
||
| // router | ||
| Libs.arouter, | ||
|
|
||
| // UI | ||
| Libs.constraintLayout, | ||
| Libs.cardView, | ||
| Libs.material, | ||
| *Libs.smartRefreshLayout, | ||
| Libs.photoView, | ||
|
|
||
| // utils | ||
| *Libs.hilt, | ||
| *Libs.room, | ||
| *Libs.rx, | ||
| *Libs.moshi, | ||
| Libs.collection, | ||
| Libs.utils | ||
|
Comment on lines
-240
to
-259
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move unnecessary deps into |
||
| *Libs.moshi | ||
| ) | ||
| kapts(Libs.arouterCompiler, Libs.moshiCompiler, Libs.roomCompiler, Libs.hiltCompiler) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,30 @@ | ||
| setupLib(Module.Common) { | ||
| setupLib(LibModule.Common) { | ||
| buildFeatures.buildConfig = true | ||
| productFlavors.all { | ||
| putBuildConfigIntField(BuildConfigField.VersionCode.tag, appVersionCode) | ||
| putBuildConfigStringField(BuildConfigField.VersionName.tag, appVersionName) | ||
| putBuildConfigStringField(BuildConfigField.CdnPrefix.tag, cdnPrefix) | ||
| putBuildConfigStringField(BuildConfigField.ApiHost.tag, apiHosts[name]) | ||
| putBuildConfigStringField(BuildConfigField.DoraemonKitKey.tag, ApiKey.DoraemonKit.key) | ||
| buildConfigField(BuildConfigField.VersionCode) | ||
| buildConfigField(BuildConfigField.VersionName) | ||
| buildConfigField(BuildConfigField.CdnPrefix) | ||
| buildConfigField(BuildConfigField.ApiHost) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementations( | ||
| // network | ||
| *Libs.coil | ||
| ) | ||
| debugImplementations( | ||
| Libs.leakCanary, | ||
| Libs.chuckerDebug | ||
| ) | ||
| releaseImplementations( | ||
| Libs.chuckerRelease | ||
| apis( | ||
| // project | ||
| project(LibModule.Base.moduleName), | ||
| project(LibModule.Adapter.moduleName), | ||
| // UI | ||
| Libs.constraintLayout, | ||
| Libs.cardView, | ||
| Libs.material, | ||
| *Libs.smartRefreshLayout, | ||
| Libs.photoView, | ||
| // other | ||
| *Libs.rx, | ||
| Libs.collection, | ||
| Libs.utils | ||
| ) | ||
| implementations(*Libs.coil) | ||
| debugImplementations(Libs.chuckerDebug) | ||
| releaseImplementations(Libs.chuckerRelease) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| setupLib(Module.Login) | ||
| setupLib(LibModule.Login) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| setupLib(Module.Web) { | ||
| setupLib(LibModule.Web) { | ||
| buildFeatures.buildConfig = true | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inject module name now in
setupBase.