组件化配置

这篇文件介绍的很好,强烈建议先看看
Android组件化方案

1.创建依赖包 名为test_library
2.Global gradle.properties中添加

# true 单独模块编译
isModule=true

3.在依赖gradle 添加

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

android {   
  defaultConfig {
if(isModule.toBoolean()){
            applicationId "com.test.test_library"
        }
}
 sourceSets {
        main {
            if (isModule.toBoolean()) {
                manifest.srcFile 'src/main/module/AndroidManifest.xml'
            } else {
                manifest.srcFile 'src/main/AndroidManifest.xml'
            }
        }
    }
}

4.创建依赖包单独编译的Mainfest
在这里插入图片描述
module 里新建的 mainfest ,包含了application和启动信息,只用于依赖包加载

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.test_library">

    <application
        android:name=".ServiceApplication"
        android:allowBackup="true"
        android:icon="@mipmap/icon_list_water"
        android:label="@string/third_menu_sdxx"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"

        >
        <activity android:name="com.test.TestActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

依赖包自动生成的mainfest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.test_library">

    <application>
        <activity android:name="com.test.TestActivity"></activity>
    </application>

</manifest>

5.主项目gradle

dependencies {
if(!isModule.toBoolean()){
        implementation project(path: ':test_library')
    }
}

6.针对资源文件重名的问题,可以依赖gradle添加前缀,保障依赖包文件必须有此前缀

android {
 resourcePrefix "testlib"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值