使用Gradle文件進行分包操作

1.在開發(fā)過程中會有多個平臺不同包名的打包需求,這里記錄一下使用Gradle來進行分包操作的筆記。

productFlavors {
        googleplay_A {
            applicationId "com.demo.demoA"
            versionName '1.1.2'
            buildConfigField("int", "APP_TYPE", "0")
            buildConfigField("int", "UNIT_TYPE", "0")
            buildConfigField("int", "APP_LOCATION", "0")
            manifestPlaceholders = [APP_ICON: "@mipmap/ic_launcher"]
            resValue "string", "app_name", "EasyTouch"
        }
        googleplay_B {
            applicationId "com.demo.demoB"
            versionName '1.1.2'
            buildConfigField("int", "APP_TYPE", "0")
            buildConfigField("int", "UNIT_TYPE", "1")
            buildConfigField("int", "APP_LOCATION", "0")
            manifestPlaceholders = [APP_ICON: "@mipmap/ic_launcher"]
            resValue "string", "app_name", "EasyTouch"
        }

2.對于不同的包需要使用到不同的屬性,有如下方式:

2.1 buildConfigField("int", "APP_TYPE", "0")使用Build參數(shù),代碼中使用如下:

int appType=BuildConfig.APP_TYPE;

2.2 manifestPlaceholders = [APP_ICON: "@mipmap/ic_launcher"]使用替代符,使用在XML中。使用如下:

<application
  android:largeHeap="true"
  android:name=".MyApplication"
  android:allowBackup="true"
  android:icon="${APP_ICON}"
  android:label="@string/app_name"
  android:persistent="true"
  android:supportsRtl="true"
  android:theme="@style/AppTheme">
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,745評論 25 709
  • 1. 前言 11月分勞務(wù)派遣進了家大公司orz,開始一個新的項目。當(dāng)我將一張切圖分別放在drawable的各個dp...
    AItsuki閱讀 38,990評論 25 147
  • 用兩張圖告訴你,為什么你的 App 會卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 13,912評論 2 59
  • 最近在項目中遇到需要實現(xiàn) Apk 多渠道、定制化打包, Google 、百度查找了一些資料,成功實現(xiàn)了上述功能,在...
    看一季殘花落幕閱讀 2,645評論 1 8
  • 生活和廣闊的大海那樣微妙,時時刻刻發(fā)生一點變化都足以讓人措手不及。在潮起潮落間,平靜的水面,在絲絲的波瀾中看風(fēng)起云...
    四葉草紫丁香閱讀 153評論 0 0

友情鏈接更多精彩內(nèi)容