Andorid Studio 模块化开发相关配置

Andorid Studio 模块化开发相关配置

下面以宿主APP模块和Uer_Module模块为例:

第一步:在项目根目录gradle.properties配置文件中添加如下代码

isNeedUserModule=true
#isNeedUserModule=false

第二步 在user_module中的build.gradle文件中加入了如下代码来控制此库是library还是APP:

if (!isNeedUserModule.toBoolean()) {
apply plugin: 'com.android.application'
} else {
apply plugin: 'com.android.library'
}

第三步 在user_module中的build.gradle文件中加入了如下代码来指定AndroidManifest.xml文件路径:

android{
 sourceSets {
    main {
        if (!isNeedUserModule.toBoolean()) {
            manifest.srcFile 'src/main/app/AndroidManifest.xml'
        } else {
            manifest.srcFile 'src/main/module/AndroidManifest.xml'
        }
    }
 
}
}

其中 app中的AndroidManifest 内容如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.finddreams.module_user">
 
<application>
    <activity
        android:name=".LoginActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
 
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

module目录下的AndroidManifest 如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.finddreams.module_user" >
<application>
    <activity android:name=".LoginActivity"></activity>
</application>
 
</manifest>

第四步 在user_module中的build.gradle文件中加入了如下代码来为该模块的下的资源自动添加前缀 避免模块之间资源命名重复:

resourcePrefix "module_user"

第五步 在宿主app中的build.gradle文件中加入了如下代码来动态引入user_module模块

  if (isNeedUserModule.toBoolean()) {
compile project(':user_module')
}

第六步 配置页面跳转路由

目前成熟的开源路由框架有:

美团的WMRouter

阿里的ARouter

可参考:《阿里路由框架ARouter的使用步骤》

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lmr廖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值