Gradle 多渠道打包的使用和錯誤分析,gradle打包錯誤

來源:互聯網
上載者:User

Gradle 多渠道打包的使用和錯誤分析,gradle打包錯誤

剛接觸到android的開發,對什麼都陌生的,本文是自己在項目中使用的技術要點總結,大咖遇到可直接飄過。。。。。

1.Gradle 打包(不廢話了直接來指令碼),將下列指令碼放到build.gradle檔案android{}內;

 1     defaultConfig{ 2         //applicationId "" //應用程式套件名 3         minSdkVersion 9       //sdk最小支援版本 4         targetSdkVersion 17   //sdk目標版本 5         versionCode 1 6         versionName "1.0" 7  8         //dex突破65535限制 9         multiDexEnabled true10 11         // AndroidManifest.xml 裡面UMENG_CHANNEL的value為 ${UMENG_CHANNEL_VALUE}12         //manifestPlaceholders = [UMENG_CHANNEL_VALUE:""]13     }14 15     //執行lint檢查,有任何的錯誤或者警告提示,都會終止構建,我們可以將其關掉。16     lintOptions{17         abortOnError false18     }19 20     //簽名21     signingConfigs{22         myConfig{23             storeFile file("123456") //簽名檔案路徑24             storePassword "123456"25             keyAlias "123456"26             keyPassword "123456"27         }28     }29 30 31     buildTypes {32         release {33             // 不顯示Log34             buildConfigField "boolean", "LOG_DEBUG", "false"35             //混淆36             minifyEnabled true37             //Zipalign最佳化38             zipAlignEnabled true39             // 移除無用的resource檔案40             shrinkResources true41             //載入預設混淆設定檔 progudard-android.txt在sdk目錄裡面,不用管,proguard.cfg是我們自己配<span></span>的混淆檔案42             proguardFiles getDefaultProguardFile('proguard-android.txt')43             proguardFile 'proguard.cfg'44             //簽名45             signingConfig signingConfigs.myConfig46         }47     }48 49     //flavorDimensions "abi"50 51     //渠道Flavors,我這裡寫了一些常用的52     productFlavors {53         _360 {54         }55         xiaomi {56         }57     }58 59 60     productFlavors.all { flavor ->61         flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]62     }63 64 65     applicationVariants.all { variant ->66         variant.outputs.each { output ->67             def outputFile = output.outputFile68             if (outputFile != null && outputFile.name.endsWith('.apk')) {69                 70                 // 輸出apk名稱為appName_v1.0.apk71                 def fileName = "${variant.productFlavors[0].name}_v${defaultConfig.versionName}.apk"72                 output.outputFile = new File(outputFile.parent, fileName)73             }74         }75     }

然後 使用 gradle clean assembleRelease -d(輸出debug資訊) 一般就會成功打出360和小米的渠道包。

Notes:

1.混淆檔案問題

proguard.ParseException: Unknown option '鍩?--dump.txt

先查看混淆設定檔的編碼和然後最將檔案修改為proguard.cfg,並開啟查看檔案中命令列被識別為止;

2.引用第三方jar問題

Execution failed for task java.io.IOException: Can't write ‘ ’ Can't read

查看引用第三方jar包是否被多次引用(刪除被多次引用jar),引用依賴maven的寫法

dependencies {
    compile 'com.android.support:support-v4:13.0.0'
}

並且Can't read後面跟著的jar在libs中刪除。

(使用Gradle2.2.1 eclipse轉android studio項目)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.