Android简单的模块化开发

Android简单的模块开发
1.为什么要模块开发
1.解耦性强:随着业务的增多,代码变的越来越复杂,每个模块之间的代码耦合变得越来越严重,解耦问题急需解决。
2. 编译时间⼤⼤减少:以为业务场景对,代码越来越⼤,同时编译时间也会越来越长。
3.提⾼团队协同开发:  团队协同开发存在较多的冲突.不得不花费更多的时间去沟通和协调,影响开发效率 。
模块化的定义:
注塑机联网Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
英⽂好的同学⾃⼰就⾃⼰看英⽂了,具体意思就是,模块化就是将⼀个程序按照其功能做拆分,分成相互独⽴的模块,以便于每个模块只包含与其功能相关的内容。⽐如登录功能可以是⼀个模块。
主要的思想:(从⽹上的)
android 模块化开发主要是以module来拆分,觉的来代码直接⼀点。
⾸先看⼀下demo的studio结构:
简单说明⼀下,这⾥我只要是分成三个部分,⼀个肯定是我们的宿主APP模块,第⼆个就是Base模块,这个模块是我们的基础模块,也就是各个module的库,第三个是FirstModule(module的写错了),这个是我模拟的⼀个功能模块module(实际的业务模块)。
在FirstModule的gradle⽂件中
//在⽂件的顶部
自动翻板机Boolean()){
apply plugin: 'com.android.application'
}else{
apply plugin: 'com.android.library'
}
//在Android模块中
sourceSets {
main {
if (Boolean()) {
manifest.srcFile 'src/main/l'
} else {
manifest.srcFile 'src/main/l'
}
}
}
//isBuildModule是在gradle.properties中声明
isBuildModule=false
在然后是配置l⽂件,以为当isBuildModule=true时,FirstModule是⼀个可以运⾏的模块,为false时是⼀个库,所以要配置⼀个l
tr069
false就是debug的l,true就是release的l
两个代码是分别是
//debug
<?xml version="1.0" encoding="utf-8"?>
印花胶浆<manifest xmlns:android="/apk/res/android"
package="ample.fristmodule">
<application
android:allowBackup="true"
城市表层土壤重金属污染分析android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".FristApplication">
<activity
android:name="ample.fristmodule.FristActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
//release
<?xml version="1.0" encoding="utf-8"?>
家用智能豆腐机
<manifest xmlns:android="/apk/res/android"
package="ample.fristmodule">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="ample.fristmodule.FristActivity">
</activity>
</application>
</manifest>
FirstModule 基本就完成了,APP的宿主和我们平时⼀样,不⽤改什么,我在APP中创建MainActivity,在FirstModule中坚决了firstActivity。然后⽤intent跳转
Intent intent = new Intent(MainActivity.this, FristActivity.class);      startActivity(intent);
我把这个ARouter依赖带Base module库中,配置的时候有2个需要注意的是:
1:gradle的版本<2.2是是⽤apt的compilel的,版本>2.2的⽤api。
2:api 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' 这个是阿⾥的插件,每个module都要添加同样还有在gradle 的Android模块加
javaCompileOptions {
annotationProcessorOptions {
arguments = [ moduleName : Name() ]
}
}
然后在各个module中应⽤Base库
implementation project(':Base')
最后就按ARouter的规则来跳转。
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
});
@Route(path = "/frist/fristactivity")
public class FristActivity extends AppCompatActivity {...}

本文发布于:2024-09-22 04:35:51,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/100973.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:模块   开发   功能
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议