马甲包、多渠道打包 demo

 gradle文件

apply plugin: 'com.android.application'


def app_label    //app名字
def app_icon    //app图标
def app_applicationId  //app id
def app_main    //main页面 全路径
def app_name    //app的application全路径
android {
    defaultConfig {
        flavorDimensions("app")
        productFlavors {

            main_ { //空文件夹  做主包
                dimension "app"
                app_applicationId = "com.example.main"//马甲包应用id
                app_label = "@string/main"
                app_icon = "@drawable/main"
                app_main = "com.example.win10_jycainiao.test.MainActivity"
                app_name = "com.example.win10_jycainiao.test.MainApp"
                applicationId app_applicationId
                versionCode 1
                versionName "1.0"
                manifestPlaceholders = [    //AndroidMainfest.xml文件拿值
                        MY_LABEL: app_label, //马甲包 应用名称
                        MY_ICON : app_icon, //马甲包 应用图标
                        MY_MAIN : app_main, //马甲包 主页面全路径
                        MY_NAME : app_name, //马甲包 application全路径
                ]
                buildConfigField("String", "APPTAG", "\"main\"")//代码拿值
            }

            majiabao1 { //马甲包1
                dimension "app"
                app_applicationId = "com.example.majiabao1"//马甲包应用id
                app_label = "@string/majiabao1"
                app_icon = "@drawable/majiabao1"
                app_main = "majiabao1.MainActivity1"
                app_name = "com.example.win10_jycainiao.test.MyApp1"
                applicationId app_applicationId
                versionCode 1
                versionName "1.0"
                manifestPlaceholders = [    //AndroidMainfest.xml文件拿值
                        MY_LABEL: app_label, //马甲包 应用名称
                        MY_ICON : app_icon, //马甲包 应用图标
                        MY_MAIN : app_main, //马甲包 主页面全路径
                        MY_NAME : app_name, //马甲包 application全路径
                ]
                buildConfigField("String", "APPTAG", "\"majiabao1\"")//代码拿值
            }

            majiabao2 { //马甲包2
                dimension "app"
                app_applicationId = "com.example.majiabao2"//马甲包应用id
                app_label = "@string/majiabao2"
                app_icon = "@drawable/majiabao2"
                app_main = "majiabao2.MainActivity2"
                app_name = "com.example.win10_jycainiao.test.MyApp2"
                applicationId app_applicationId
                versionCode 11
                versionName "121.0"
                manifestPlaceholders = [    //AndroidMainfest.xml文件拿值
                        MY_LABEL: app_label, //马甲包 应用名称
                        MY_ICON : app_icon, //马甲包 应用图标
                        MY_MAIN : app_main, //马甲包 主页面全路径
                        MY_NAME : app_name, //马甲包 application全路径
                ]
                buildConfigField("String", "APPTAG", "\"majiabao2\"")//代码拿值
            }
        }
        compileSdkVersion 29
        minSdkVersion 19
        targetSdkVersion 29
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    majiabao1Implementation 'com.android.support:appcompat-v7:28.0.0'
    majiabao1Implementation 'com.android.support:support-compat:28.0.0'

    majiabao2Implementation 'com.android.support:appcompat-v7:28.0.0'
    majiabao2Implementation 'com.android.support:support-compat:28.0.0'


    main_Implementation 'com.android.support:appcompat-v7:28.0.0'
    main_Implementation 'com.android.support:support-compat:28.0.0'

}

  

main目录里面AndroidMainfest.xml内容,引用了gradle配置的一些字段

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

    <application
        android:name="${MY_NAME}"
        android:icon="${MY_ICON}"
        android:label="${MY_LABEL}"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <activity android:name="${MY_MAIN}" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

  

 

 

 

 

 

main_用来做main的完全维度包

 

马甲包如果有新加或者更改 application、activity,要对gradle中的字段进行赋值,并且在AndroidMainfest.xml中添加activity

 

posted @ 2020-11-13 17:19  凤雏小呆  阅读(527)  评论(0编辑  收藏  举报