点击(此处)折叠或打开
apply plugin: 'com.android.application' apply plugin: 'com.droidtitan.lintcleaner' def releaseTime() { return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) } def vCode() { return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC")) } android { compileSdkVersion 21 buildToolsVersion "22.0.1" signingConfigs { apply plugin: 'signing' release { storeFile file("../androidkey.keystore") storePassword "yourpassword" keyAlias "youralias" keyPassword "yourkey" } } defaultConfig { applicationId "your package name" minSdkVersion 15 targetSdkVersion 21 versionCode Integer.valueOf(vCode()) versionName "2.1.10" } //多个版本的打包配置 productFlavors { Version1{ applicationId "your package name1" manifestPlaceholders = [GAO_DE_KEY: "your gaode key1", UMENG_KEY: "your umeng key1"] } Version2 { applicationId "your package name2" manifestPlaceholders = [GAO_DE_KEY: "your gaode key2", UMENG_KEY: "your umeng key2"] } } buildTypes { release { signingConfig signingConfigs.release shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //将release版本的包名重命名,加上版本及日期 applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('release.apk')) { def fileName = "${variant.productFlavors[0].name}_V${defaultConfig.versionName}_${releaseTime()}.apk" output.outputFile = new File(outputFile.parent, fileName) } } } } debug { signingConfig signingConfigs.release minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } repositories { maven { url "https://jitpack.io" } } //用来清除无用资源的插件,详见https://github.com/marcoRS/lint-cleaner-plugin lintCleaner { // Exclude specific files exclude = ['umeng*.png', '*.xml'] // Ability to ignore all resource files. False by default. ignoreResFiles = true } //将打包后的文件复制到build目录下,这样就不用深入到apk目录,同时还看不到unaligned的apk了 task copyTask(type: Copy) { from 'build/outputs/apk/' into 'build/' exclude '*-unaligned.apk' } task bd(dependsOn: ['assembleDebug', 'assembleRelease', 'copyTask']){ copyTask.mustRunAfter assembleRelease } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') // compile 'com.squareup.retrofit:retrofit:1.9.0' // compile 'com.squareup.okhttp:okhttp:2.3.0' // compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0' // compile 'com.facebook.stetho:stetho:1.1.1' // compile 'com.facebook.stetho:stetho-okhttp:1.1.1' // compile 'io.reactivex:rxandroid:0.24.0' // compile 'com.jakewharton:butterknife:6.1.0' compile 'com.facebook.fresco:fresco:0.5.2+' compile 'me.imid.swipebacklayout.lib:library:1.0.0' compile 'se.emilsjolander:stickylistheaders:2.6.0' compile 'de.greenrobot:eventbus:2.4.0' compile 'com.github.PhilJay:MPAndroidChart:v2.0.9' compile 'com.google.code.gson:gson:2.3.1' compile 'com.android.support:support-v13:22.2.0' compile project(':carShopSyncLib') } 最后在终端运行命令 gradlew bd即可