Skip to content

Commit

Permalink
Merge pull request #468 from RedrockMobile/GuoXR/main_single_debug
Browse files Browse the repository at this point in the history
✨ 支持不需要密钥的打包编译
  • Loading branch information
985892345 authored Mar 19, 2024
2 parents 05b25d9 + fe91fed commit 20f3677
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 63 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CyxbsMobile_Android

## 如何编译
- 请先查看必看文档中的多模块教程,熟悉多模块开发规范
-`module_main` 模块进行单模块编译
- ⚠️注:`module_app` 模块只用于打正式包,因为包含密钥等文件,所以只能由副站持有

## 必看文档
- [多模块教程](https://github.com/VegetableChicken-Group/WanAndroid_Multi/blob/framework/doce/%E5%A4%9A%E6%A8%A1%E5%9D%97%E6%8C%87%E5%8D%97.md): 包含 api、lib、module 模块相关问题,还有多模块使用规范、多模块通信、单模块调试等教程
- [Android 开发中的易错点收集(内部文档)](https://redrock.feishu.cn/wiki/wikcnSDEtcCJzyWXSsfQGqWxqGe): 包含 Fragment、ViewModel、协程相关易错点收集
Expand Down
43 changes: 18 additions & 25 deletions build-logic/core/app/src/main/kotlin/AppPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import com.tencent.vasdolly.plugin.extension.ChannelConfigExtension
import org.gradle.api.Project
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.kotlin.dsl.*
import task.CyxbsReleaseTask
Expand Down Expand Up @@ -111,37 +112,29 @@ class AppPlugin : BasePlugin() {
}

private fun dependAllProject() {
Companion.dependAllProject(project)
}

with(project) {
companion object {
fun dependAllProject(
project: Project,
vararg exclude: String,
) {
// 测试使用,设置 module_app 暂时不依赖的模块
val excludeList = mutableListOf<String>(
"lib_single", // lib_single 只跟单模块调试有关
)

// 根 gradle 中包含的所有子模块
val includeProjects = rootProject.allprojects.map { it.name }

dependencies {
//引入所有的module和lib模块
rootDir.listFiles()!!.filter {
// 1.是文件夹
// 2.不是module_app
// 3.以lib_或者module_开头
// 4.去掉暂时排除的模块
// 5.根 gradle 导入了的模块
it.isDirectory
&& it.name != "module_app"
&& "(lib_.+)|(module_.+)|(api_.+)".toRegex().matches(it.name)
&& !it.name.contains("lib_common") // 目前 app 模块已经去掉了对 common 模块的依赖
&& !it.name.contains("lib_debug") // 去除主动依赖 lib_debug 模块
&& it.name !in excludeList
&& includeProjects.contains(it.name)

) + exclude

project.dependencies {
// 根 gradle 中包含的所有子模块
project.rootProject.subprojects.filter {
it.name !in excludeList
&& it != project
&& it.name != "lib_single" // lib_single 只跟单模块调试有关,单模块编译时单独依赖
}.forEach {
"implementation"(project(":${it.name}"))
"implementation"(it)
}
}


}
}
}
3 changes: 3 additions & 0 deletions build-logic/core/module/src/main/kotlin/ModuleDebugPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ class ModuleDebugPlugin : BasePlugin() {
dependencies {
"implementation"(project(":lib_single"))
}

// databind 需要启动模块开启后才能正常运行,所以这里单模块调试作为启动模块需要开启
useDataBinding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import com.mredrock.cyxbs.single.ui.SingleModuleActivity
/**
* 负责单模块调试的入口界面启动
*
* ```
* 使用方式:
* - 实现该接口
* - 添加 @Route 注解,path 请以 /single/模块名 命名
*
* @Route(path = "/single/xxx")
* class XXXSingleModuleEntry : ISingleModuleEntry
* ```
*
* @author 985892345
* @date 2023/9/7 00:08
*/
Expand Down
8 changes: 1 addition & 7 deletions module_app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ plugins {
id ("module-manager")
}


dependLibUtils()

dependApiInit()
dependApiAccount()

dependRxjava()

dependAutoService()

useARouter(false) // module_app 模块不包含实现类,不需要处理注解
useDataBinding()
33 changes: 33 additions & 0 deletions module_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@
tools:replace="android:exported" />
<!--友盟 End-->

<meta-data
android:name="com.amap.api.v2.apikey"
android:value="${amap_apikey}"/>

<activity
android:name=".main.ui.main.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="qa"
android:scheme="cyxbsmobile" />

<!-- <a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> -->
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/main_shortcut" />
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ class HomeCourseViewModel : BaseViewModel() {

/**
* 注意:整个课表采用了观察者模式。数据库对应的数据改变,会自动修改视图内容
*
* 如果后面出现数据
*/
private fun initObserve(isToast: Boolean): Disposable {
// 自己课的观察流
Expand Down
11 changes: 9 additions & 2 deletions module_main/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("module-manager")
id("module-debug")
}


Expand All @@ -20,4 +20,11 @@ dependRxjava()
dependNetwork()
dependCoroutinesRx3()

useARouter()
useARouter()



if (project.plugins.hasPlugin("com.android.application")) {
// 如果 main 模块以单模块的形式编译,则对其他模块进行依赖
AppPlugin.dependAllProject(project, "module_app")
}
26 changes: 2 additions & 24 deletions module_main/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,13 @@
xmlns:tools="http://schemas.android.com/tools">

<application>
<activity android:name=".ui.defaultpage.DefaultPageActivity"/>
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="qa"
android:scheme="cyxbsmobile" />

<!-- <a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> -->
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/main_shortcut" />
</activity>
<activity android:name=".ui.defaultpage.DefaultPageActivity"/>
android:theme="@style/SplashTheme"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mredrock.cyxbs.main.debug

import android.content.Intent
import com.alibaba.android.arouter.facade.annotation.Route
import com.mredrock.cyxbs.main.ui.main.MainActivity
import com.mredrock.cyxbs.single.ISingleModuleEntry
import com.mredrock.cyxbs.single.ui.SingleModuleActivity

/**
* .
*
* @author 985892345
* 2024/3/19 13:19
*/
@Route(path = "/single/main")
class MainDebugActivity : ISingleModuleEntry {
override fun getPage(activity: SingleModuleActivity): ISingleModuleEntry.Page {
return ISingleModuleEntry.ActionPage {
activity.startActivity(Intent(activity, MainActivity::class.java))
}
}
}
7 changes: 4 additions & 3 deletions module_schoolcar/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
android:launchMode="singleTop"/>
<activity android:name="com.mredrock.cyxbs.schoolcar.SchoolDetailActivity"
/>
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="${amap_apikey}"/>

<service android:name="com.amap.api.location.APSService" />

<!--⚠️注:校车需要 amap_apikey,目前是写在 module_app 的注册文件里,
单模块调试时不会加载,但不建议对校车进行单模块调试,防止密钥泄漏-->

</application>

</manifest>

0 comments on commit 20f3677

Please sign in to comment.