android 模块化开发

当一个android程序过大的话代码编译的速度也会慢,代码冗余太厉害,而且团队开发时候也不方便,不能独立的开发自己的一块,这个时候我们都会用到模块化开发,每一个module依赖都会成为单独运行的app,这样就方便了

//主要是使用阿里开发的Arouter路由开方便模块开发,因为我们在跳转的时候要是使用原生的Intent后期会比较混乱,如果使用Arouter路由就不会发生了
这里就介绍Arouter的使用了,读者可以自己查询一下资料
就想这样把所有跳转的路径配置到一个类中
/**

  • 跳转路径的配置
    /
    public class MyTaskArouterConsts {
    /
    *
    • 登录页面
      /
      public static final String USER_LOGIN = “/user/login”;
      /
      *
    • 数据页面
      */
      public static final String Data = “/user/data”;
      }

这是我们一个module中build.gradle的配置,这个baselib是最底层的依赖
如果想把我们的module变成独立的app的话就在全局的gradle.properties
里面配置mytask=true,这样还不够我们还得再main文件下新创建buildApp文件夹和buildmodule供我们加载
if (mytask.toBoolean()) {
apply plugin: ‘com.android.application’
} else {
apply plugin: ‘com.android.library’
}
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName “1.0”
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
javaCompileOptions {
annotationProcessorOptions {
arguments = [moduleName: project.getName()]
}
}

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
//组件资源前缀
resourcePrefix "user_"
sourceSets {
    main {
        if (mytask.toBoolean()) {
            manifest.srcFile 'src/main/buildApp/AndroidManifest.xml'
        } else {
            manifest.srcFile 'src/main/buildModule/AndroidManifest.xml'
        }
    }
}

}

dependencies {
implementation fileTree(dir: ‘libs’, include: [’*.jar’])
implementation ‘com.android.support:appcompat-v7:26.1.0’
testImplementation ‘junit:junit:4.12’
androidTestImplementation ‘com.android.support.test🏃1.0.2’
androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2’
annotationProcessor ‘com.alibaba:arouter-compiler:1.1.4’
implementation project(’:baselib’)
}

最后在app的build.gradle中配置
apply plugin: ‘com.android.application’

apply plugin: ‘kotlin-android’

apply plugin: ‘kotlin-android-extensions’

android {
compileSdkVersion 26
defaultConfig {
applicationId “com.example.drcomponentdemo”
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName “1.0”
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
javaCompileOptions {
annotationProcessorOptions {
arguments = [moduleName: project.getName()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
}
}
}

dependencies {
implementation fileTree(dir: ‘libs’, include: [’*.jar’])
implementation “org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version”
implementation ‘com.android.support:appcompat-v7:26.1.0’
implementation ‘com.android.support.constraint:constraint-layout:1.1.3’
testImplementation ‘junit:junit:4.12’
androidTestImplementation ‘com.android.support.test🏃1.0.2’
androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2’
annotationProcessor ‘com.alibaba:arouter-compiler:1.1.4’
implementation project(’:baselib’)
if (!myhome.toBoolean()) {
api project(’:myhome’)
}
if (!mytask.toBoolean()) {
api project(’:mytask’)
}
}
//我们都知道一个app只能有一个Application这个解决方案在代码中有解决有需要的评论区发邮箱就行,我会单独吧代码给你

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值