gradle 发表于 2017-08-25 | 分类于 技术博客 | Gradle不知道的配置,不止是编译运行打包依赖 application的gradle123456789101112131415161718192021222324252627//对整个项目的gradle进行配置buildscript { //编译依赖的仓库,也就是gradle的仓库 repositories { jcenter() } dependencies { //grale的依赖,这里是Google指定的版本和真正的版本不一致 classpath 'com.android.tools.build:gradle:2.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}//module的依赖仓库allprojects { repositories { jcenter() maven { url "https://jitpack.io" } }}//clean时清空项目根目录的bulid文件夹task clean(type: Delete) { delete rootProject.buildDir} setting的gradle123//项目包含的moduleinclude ':app'include ':bluetoothDemo' moudle的gradle12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091//使用app插件 apply plugin: 'com.android.application'//library使用插件 apply plugin: 'com.android.library'android { signingConfigs { config { keyAlias 'xxxx' keyPassword 'xxxx' storeFile file('H:/xxx.jks') storePassword 'xxxx' } } compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { //真正的包名 applicationId "com.zwang.jxc" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //开启分包,64k方法数 multiDexEnabled true } //指定打包后应用名称 applicationVariants.all {variant -> variant.outputs.each {output -> def outputFile = output.outputFile def fileName if (outputFile != null && outputFile.name.endsWith('.apk')) { if (variant.buildType.name.equals('release')) { fileName = "应用 _${defaultConfig.versionName}_${defaultConfig.versionCode}.apk" } else if (variant.buildType.name.equals('debug')) { fileName = "应用_${defaultConfig.versionName}_${defaultConfig.versionCode}_debug.apk" } output.outputFile = new File(outputFile.parent, fileName) } } } //混淆 buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } //打包内存分配 dexOptions { javaMaxHeapSize "4g" } //编译打包不同版本,编译时间减少一半 productFlavors { dev { minSdkVersion 21 } prod { minSdkVersion 16 } }}dependencies { //依赖的文件位置 compile fileTree(include: ['*.jar'], dir: 'libs') //jar宝依赖 compile files('libs/butterknife-7.0.1.jar') //仓库依赖 compile 'com.android.support:appcompat-v7:25.3.1' //分包依赖 compile 'com.android.support:multidex:1.0.1' //解决第三方库冲突 //build.gradle所在目录下执行gradlew -q app:dependencies命令查看依赖情况 compile('cn.qqtheme.framework:WheelPicker:latest.release') { //解决特定的 exclude module: 'support-v4' //解决一类的 exclude group: 'com.android.support' } //library依赖 compile project(':bluetoothDemo') //更新依赖,指定版本号只会更新该版本号 compile("com.tencent.tinker:tinker-android-lib:1.7.6") { changing = true }} gradle.properties123456789# 守护进程org.gradle.daemon=true# 并行编译org.gradle.parallel=true#代理systemProp.http.proxyHost=127.0.0.1systemProp.http.proxyPort=1080systemProp.https.proxyHost=127.0.0.1systemProp.https.proxyPort=1080