<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                由于國內Android市場眾多渠道,為了統計每個渠道的下載及其它數據統計,就需要我們針對每個渠道單獨打包,如果讓你打幾十個市場的包豈不煩死了,不過有了Gradle,這再也不是事了。 ## 友盟多渠道打包 廢話不多說,以友盟統計為例,在AndroidManifest.xml里面會有這么一段: ~~~ <meta-data android:name="UMENG_CHANNEL" android:value="Channel_ID" /> ~~~ 里面的Channel_ID就是渠道標示。我們的目標就是在編譯的時候這個值能夠自動變化。 * 第一步 在AndroidManifest.xml里配置PlaceHolder ~~~ <meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" /> ~~~ * 第二步 在build.gradle設置productFlavors ~~~ android { productFlavors { xiaomi { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"] } _360 { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "_360"] } baidu { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "baidu"] } wandoujia { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"] } } } ~~~ 或者批量修改 ~~~ android { productFlavors { xiaomi {} _360 {} baidu {} wandoujia {} } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } } ~~~ 很簡單清晰有沒有?直接執行?**./gradlew assembleRelease**?, 然后就可以靜靜的喝杯咖啡等待打包完成吧。 ## assemble結合Build Variants來創建task 上一篇博客介紹了?**assemble**?這個命令,會結合?**Build Type**?創建自己的task,如: * ./gradlew assembleDebug * ./gradlew assembleRelease 除此之外?**assemble**?還能和?**Product Flavor**?結合創建新的任務,其實?**assemble**?是和?**Build Variants**?一起結合使用的,而?**Build Variants**?=?**Build Type**?+?**Product Flavor**?, 舉個例子大家就明白了: 如果我們想打包wandoujia渠道的release版本,執行如下命令就好了: * ./gradlew assembleWandoujiaRelease 如果我們只打wandoujia渠道版本,則: * ./gradlew assembleWandoujia 此命令會生成wandoujia渠道的Release和Debug版本 同理我想打全部Release版本: * ./gradlew assembleRelease 這條命令會把Product Flavor下的所有渠道的Release版本都打出來。 總之,**assemble**?命令創建task有如下用法: * **assemble**: 允許直接構建一個Variant版本,例如assembleFlavor1Debug。 * **assemble**: 允許構建指定Build Type的所有APK,例如assembleDebug將會構建Flavor1Debug和Flavor2Debug兩個Variant版本。 * **assemble**: 允許構建指定flavor的所有APK,例如assembleFlavor1將會構建Flavor1Debug和Flavor1Release兩個Variant版本。 ## 完整的gradle腳本 最后福利大放送,來一份我在項目中使用的完整的gradle文件配置: ~~~ apply plugin: 'com.android.application' def releaseTime() { return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) } android { compileSdkVersion 21 buildToolsVersion '21.1.2' defaultConfig { applicationId "com.boohee.*" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" // dex突破65535的限制 multiDexEnabled true // 默認是umeng的渠道 manifestPlaceholders = [UMENG_CHANNEL_VALUE: "umeng"] } lintOptions { abortOnError false } signingConfigs { debug { // No debug config } release { storeFile file("../yourapp.keystore") storePassword "your password" keyAlias "your alias" keyPassword "your password" } } buildTypes { debug { // 顯示Log buildConfigField "boolean", "LOG_DEBUG", "true" versionNameSuffix "-debug" minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.debug } release { // 不顯示Log buildConfigField "boolean", "LOG_DEBUG", "false" minifyEnabled true zipAlignEnabled true // 移除無用的resource文件 shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { // 輸出apk名稱為boohee_v1.0_2015-01-15_wandoujia.apk def fileName = "boohee_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk" output.outputFile = new File(outputFile.parent, fileName) } } } } } // 友盟多渠道打包 productFlavors { wandoujia {} _360 {} baidu {} xiaomi {} tencent {} taobao {} ... } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-v4:21.0.3' compile 'com.jakewharton:butterknife:6.0.0' ... } ~~~ 大家有問題或疑問、建議歡迎博客留言,Android Studio的教程暫且到這里結束了,相信大家基本的都已會使用了,還有其他技巧與操作靠大家自己摸索了,之后有時間也會在博客上整理下一些Tips之類的,歡迎大家關注。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看