专栏名称: 程序员大咖
为程序员提供最优质的博文、最精彩的讨论、最实用的开发资源;提供最新最全的编程学习资料:PHP、Objective-C、Java、Swift、C/C++函数库、.NET Framework类库、J2SE API等等。并不定期奉送各种福利。
目录
相关文章推荐
程序猿  ·  传字节跳动内部开始禁用Cursor了 ·  3 天前  
京东零售技术  ·  做「长期主义者」的技术人们 ·  4 天前  
极客之家  ·  一键将 Docker 命令转化为 ... ·  3 天前  
程序员的那些事  ·  重写太成功反遭封杀!CTO 用 6 个月把 ... ·  2 天前  
51好读  ›  专栏  ›  程序员大咖

详解Android多版本、多环境、多渠道打包,附源码Demo

程序员大咖  · 公众号  · 程序员  · 2018-04-30 10:24

正文

请到「今天看啥」查看全文



dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.meituan.android.walle:plugin:1.0.3'
}
}

(2) 在当前App的 build.gradle 文件中apply这个插件,并添加上用于读取渠道号的aar

apply plugin: 'com.android.application'
apply plugin: 'walle'

android {
   compileSdkVersion 25
   buildToolsVersion "25.0.2"
   defaultConfig {
           minSdkVersion 15
           targetSdkVersion 25
           versionCode 1
           versionName "1.0"
           testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }    
           signingConfigs {
               release {      
                   keyAlias KEY_ALIAS            
                   keyPassword KEY_PASSWORD storeFile rootProject.file(KEYSTORE_FILE)            
                   storePassword KEYSTORE_PASSWORD        
               }    
           }    
           
           buildTypes {
               //调试版本,无混淆
               debug {
                   minifyEnabled false
                   signingConfig signingConfigs.release        
               }
               //发布版本,有混淆
               release {        
                   minifyEnabled true
                   zipAlignEnabled true
                   shrinkResources true
                   signingConfig signingConfigs.release            
                   proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
               }    
          }    
         
          productFlavors {
              //开发环境
              develop {
                  buildConfigField "int", "ENV_TYPE", "1"
                  applicationId 'om.soubu.walledemo.develop'
                  manifestPlaceholders = [      
                          app_name: "开-WalleDemo",                    
                          app_icon: "@drawable/icon_develop"
                  ]        
              }
              //测试环境
              check {
                  buildConfigField "int", "ENV_TYPE", "2"
                  applicationId 'om.soubu.walledemo.check'
                  manifestPlaceholders = [          
                          app_name: "测-WalleDemo",                    
                          app_icon: "@drawable/icon_check"
                  ]        
              }
              //生产环境
              product {    
                  buildConfigField "int", "ENV_TYPE", "3"
                  applicationId 'com.soubu.walledemo.product'
                  manifestPlaceholders = [        
                           app_name: "WalleDemo",                    
                           app_icon: "@drawable/icon_product"
                  ]        
              }    
           }
       }
       
       dependencies {
           compile fileTree(dir: 'libs', include: ['*.jar'])    
           androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
               exclude group: 'com.android.support', module: 'support-annotations'
           })    
           compile 'com.android.support:appcompat-v7:25.1.0'
           testCompile 'junit:junit:4.12'
           
           compile 'com.meituan.android.walle:library:1.0.3'
      }

(3) 这里,我根据不同的环境生成了不同包名的apk,方便在手机上同时安装多个环境的应用。为了让gradle动态更改apk的名称和图标,我们需要在manifest文件中使用{app_name}等占位符







请到「今天看啥」查看全文