打包配置java
執行命令 ./gradlew -Pmarket=app/config/markets.txt clean apkRelease 進行打包android
apply plugin: 'com.android.application'
apply plugin:'android-apt'
apply plugin: 'packer'
def AAVersion='3.2' android { compileSdkVersion 23 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.fifedu.preschool" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src/main/java'] resources.srcDirs = ['src/main/resources'] aidl.srcDirs = ['src/main/aidl'] renderscript.srcDirs = ['src/main'] res.srcDirs = ['src/main/res'] assets.srcDirs = ['src/main/assets'] jniLibs.srcDir 'src/main/jniLibs' } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') } //執行lint檢查,有任何的錯誤或者警告提示,都會終止構建,咱們能夠將其關掉。 lintOptions { abortOnError false } //簽名 signingConfigs { debug { storeFile file("/Users/weidingqiang/.android/debug.keystore") } release { //這樣寫就得把demo.jk文件放在項目目錄 storeFile file("/Users/weidingqiang/.android/key.jks") storePassword "123456" keyAlias "hello" keyPassword "123456" } } 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 //Zipalign優化 zipAlignEnabled true multiDexEnabled true // 移除無用的resource文件 shrinkResources true //前一部分表明系統默認的android程序的混淆文件,該文件已經包含了基本的混淆聲明 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //簽名 signingConfig signingConfigs.release } } // buildTypes { // release { // minifyEnabled true // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // } // } } dependencies {
complie 'com.mcxiaoke.gradle:packer-helper:1.0.4' compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' apt "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" compile 'com.mcxiaoke.volley:library:1.0.19' compile 'com.github.bumptech.glide:volley-integration:1.0.+' // compile 'com.github.bumptech.glide:glide:3.6.1' compile 'com.zhy:autolayout:1.3.6' compile 'de.greenrobot:eventbus:2.4.0' // compile files('libs/log4j-1.2.17.jar') // compile files('libs/android-logging-log4j-1.0.3.jar') // compile files('libs/AMap_2DMap_V2.8.0_20151231.jar') // compile files('libs/AMap_Location_v2.3.0_20160112.jar') // compile files('libs/AMap_Search_V2.8.0_20160105.jar') } apt { arguments { androidManifestFile variant.outputs[0].processResources.manifestFile resourcePackageName "com.fifedu.preschool" } }
packer {
archiveOutput = file(new File(project.rootProject.buildDir.path, "myapks"))
}
二、默認打包git
執行命令 github
./gradlew assembleDebug 編譯並打Debug包api
./gradlew assembleRelease 編譯並打Release的包app
apply plugin: 'com.android.application' apply plugin:'android-apt' def AAVersion='3.2' android { compileSdkVersion 23 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.fifedu.preschool" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" // dex突破65535的限制 // multiDexEnabled true // AndroidManifest.xml 裏面UMENG_CHANNEL的value爲 ${UMENG_CHANNEL_VALUE} manifestPlaceholders = [UMENG_CHANNEL_VALUE: "channel_name"] } sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src/main/java'] resources.srcDirs = ['src/main/resources'] aidl.srcDirs = ['src/main/aidl'] renderscript.srcDirs = ['src/main'] res.srcDirs = ['src/main/res'] assets.srcDirs = ['src/main/assets'] jniLibs.srcDir 'src/main/jniLibs' } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') // Move the build types to build-types/<type> // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // This moves them out of them default location under src/<type>/... which would // conflict with src/ being used by the main source set. // Adding new build types or product flavors should be accompanied // by a similar customization. debug.setRoot('build-types/debug') release.setRoot('build-types/release') } //執行lint檢查,有任何的錯誤或者警告提示,都會終止構建,咱們能夠將其關掉。 lintOptions { abortOnError false } //簽名 signingConfigs { debug { storeFile file("/Users/weidingqiang/.android/debug.keystore") } release { //這樣寫就得把demo.jk文件放在項目目錄 storeFile file("/Users/weidingqiang/.android/key.jks") storePassword "123456" keyAlias "hello" keyPassword "123456" } } 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 //Zipalign優化 zipAlignEnabled true multiDexEnabled true // 移除無用的resource文件 shrinkResources true //前一部分表明系統默認的android程序的混淆文件,該文件已經包含了基本的混淆聲明 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //簽名 signingConfig signingConfigs.release } } //開啓後 會報錯 must be specified after an input jar, or it will be empty. //不清楚爲何 //渠道Flavors,配置不一樣風格的app productFlavors { GooglePlay {} // xiaomi {} // umeng {} // _360 {} // baidu {} // wandoujia {} } //批量配置 productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk") output.outputFile = new File(outputFile.parent, fileName) } } } // buildTypes { // release { // minifyEnabled true // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // } // } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' apt "org.androidannotations:androidannotations:$AAVersion" compile "org.androidannotations:androidannotations-api:$AAVersion" compile 'com.mcxiaoke.volley:library:1.0.19' compile 'com.github.bumptech.glide:volley-integration:1.0.+' // compile 'com.github.bumptech.glide:glide:3.6.1' compile 'com.zhy:autolayout:1.3.6' compile 'de.greenrobot:eventbus:2.4.0' // compile files('libs/log4j-1.2.17.jar') // compile files('libs/android-logging-log4j-1.0.3.jar') // compile files('libs/AMap_2DMap_V2.8.0_20151231.jar') // compile files('libs/AMap_Location_v2.3.0_20160112.jar') // compile files('libs/AMap_Search_V2.8.0_20160105.jar') } apt { arguments { androidManifestFile variant.outputs[0].processResources.manifestFile resourcePackageName "com.fifedu.preschool" } }