美文网首页Android SAPT
Android多渠道 打包 android studio

Android多渠道 打包 android studio

作者: GuoBangbang | 来源:发表于2016-11-25 11:45 被阅读16次

    介绍多渠道打包:以umeng为例。

    manifest文件
    <meta-data    android:name="UMENG_CHANNEL"    android:value="${UMENG_CHANNEL_VALUE}" />
    
    build.gradle文件
    defaultConfig {   
      //添加默认渠道
       manifestPlaceholders = [UMENG_CHANNEL_VALUE: "default"]
    }
    
     // 友盟多渠道打包   
     productFlavors {       
    //        wandoujia {}
    //        baidu {}
    //        xiaomi {}
    //        tencent {}    
    //        继续添加其他渠道
    }
    
    productFlavors.all { flavor ->   
           flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }
    
    //输出apk
    android.applicationVariants.all { variant ->    
      variant.outputs.each { output ->       
      def outputFile = output.outputFile        
      if (outputFile != null && outputFile.name.endsWith('.apk')) {           
      // 输出apk名称为app_release_v*.*.*_build*_channel.apk           
        def fileName = "app_release_v${defaultConfig.versionName}_build${defaultConfig.versionCode}_${variant.productFlavors[0].name}.apk"          
        if (variant.buildType.name.equals('debug')) {              
          fileName = "app_debug_v${defaultConfig.versionName}_build${defaultConfig.versionCode}.apk"    
        }
       output.outputFile = new File(outputFile.parent, fileName)       
      }   
     }
    }
    
    //debug版本使用release key进行签名
    buildTypes {    
      debug {        
        signingConfig signingConfigs.release 
      }
    }
    
    

    相关文章

      网友评论

        本文标题:Android多渠道 打包 android studio

        本文链接:https://www.haomeiwen.com/subject/uxgipttx.html