gradle大体内容
1 buildscript { 2 repositories { 3 mavenCentral() 4 } 5 dependencies { 6 classpath 'com.android.tools.build:gradle:1.2.3' 7 } 8 } 9 apply plugin: 'android' 10 11 dependencies { 12 compile fileTree(dir: 'libs', include: '*.jar') 13 } 14 // 方法超过65535 做法 还有。。。 15 afterEvaluate { 16 tasks.matching { 17 it.name.startsWith('dex') 18 }.each { dx -> 19 if (dx.additionalParameters == null) { 20 dx.additionalParameters = [] 21 } 22 dx.additionalParameters += '--multi-dex' // enable multidex 23 24 // optional 25 // dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list 26 } 27 } 28 29 android { 30 compileSdkVersion 8 31 buildToolsVersion "22.0.1" 32 sourceSets { 33 main { 34 manifest.srcFile 'AndroidManifest.xml' 35 java.srcDirs = ['src'] 36 resources.srcDirs = ['src'] 37 aidl.srcDirs = ['src'] 38 renderscript.srcDirs = ['src'] 39 res.srcDirs = ['res'] 40 assets.srcDirs = ['assets'] 41 } 42 43 // Move the tests to tests/java, tests/res, etc... 44 instrumentTest.setRoot('tests') 45 46 // Move the build types to build-types/<type> 47 // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 48 // This moves them out of them default location under src/<type>/... which would 49 // conflict with src/ being used by the main source set. 50 // Adding new build types or product flavors should be accompanied 51 // by a similar customization. 52 debug.setRoot('build-types/debug') 53 release.setRoot('build-types/release') 54 } 55 packagingOptions { 56 exclude 'META-INF/LICENSE.txt' 57 exclude 'META-INF/LICENSE' 58 exclude 'META-INF/NOTICE' 59 exclude 'META-INF/NOTICE.txt' 60 } 61 //签名 62 signingConfigs { 63 //你自己的keystore信息 64 releaseConfig { 65 storeFile file("wf.keystore") 66 storePassword "123456" 67 keyAlias "wfwf" 68 keyPassword "654321" 69 } 70 debugConfig { 71 storeFile file("wf.keystore") 72 storePassword "123456" 73 keyAlias "wfwf" 74 keyPassword "654321" 75 } 76 } 77 buildTypes { 78 release{ 79 minifyEnabled true 80 signingConfig signingConfigs.releaseConfig 81 proguardFile 'proguard.cfg' 82 zipAlignEnabled true 83 renderscriptOptimLevel 5 84 85 } 86 debug{ 87 minifyEnabled false 88 signingConfig signingConfigs.debugConfig 89 proguardFile 'proguard.cfg' 90 zipAlignEnabled true 91 renderscriptOptimLevel 5 92 93 } 94 } 95 // This is important, it will run lint checks but won't abort build 96 lintOptions { 97 abortOnError false 98 } 99 100 dexOptions { 101 incremental true 102 } 103 104 }
不分包
1 buildscript { 2 repositories { 3 mavenCentral() 4 } 5 dependencies { 6 classpath 'com.android.tools.build:gradle:1.3.0' 7 } 8 } 9 apply plugin: 'android' 10 11 dependencies { 12 compile fileTree(dir: 'libs', include: '*.jar') 13 //compile 'com.google.android:multidex:0.1' 14 } 15 16 android { 17 compileSdkVersion 8 18 buildToolsVersion "22.0.1" 19 20 sourceSets { 21 main { 22 manifest.srcFile 'AndroidManifest.xml' 23 java.srcDirs = ['src'] 24 resources.srcDirs = ['src'] 25 aidl.srcDirs = ['src'] 26 renderscript.srcDirs = ['src'] 27 res.srcDirs = ['res'] 28 assets.srcDirs = ['assets'] 29 } 30 31 // Move the tests to tests/java, tests/res, etc... 32 instrumentTest.setRoot('tests') 33 34 // Move the build types to build-types/<type> 35 // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 36 // This moves them out of them default location under src/<type>/... which would 37 // conflict with src/ being used by the main source set. 38 // Adding new build types or product flavors should be accompanied 39 // by a similar customization. 40 debug.setRoot('build-types/debug') 41 release.setRoot('build-types/release') 42 } 43 44 45 // //签名 46 // signingConfigs { 47 // //你自己的keystore信息 48 // releaseConfig { 49 // storeFile file("wf.keystore") 50 // storePassword "123456" 51 // keyAlias "wfwf" 52 // keyPassword "654321" 53 // } 54 // debugConfig { 55 // storeFile file("wf.keystore") 56 // storePassword "123456" 57 // keyAlias "wfwf" 58 // keyPassword "654321" 59 // } 60 // } 61 62 packagingOptions { 63 exclude 'META-INF/LICENSE.txt' 64 } 65 // buildTypes { 66 // release { 67 // minifyEnabled false 68 // signingConfig signingConfigs.releaseConfig 69 // proguardFile 'proguard.cfg' 70 // zipAlignEnabled true 71 // renderscriptOptimLevel 5 72 // 73 // } 74 // debug { 75 // minifyEnabled false 76 // signingConfig signingConfigs.debugConfig 77 // proguardFile 'proguard.cfg' 78 // zipAlignEnabled true 79 // renderscriptOptimLevel 5 80 // 81 // } 82 // } 83 84 lintOptions { 85 checkReleaseBuilds false 86 // Or, if you prefer, you can continue to check for errors in release builds, 87 // but continue the build even when errors are found: 88 abortOnError false 89 } 90 // afterEvaluate { 91 // tasks.matching { 92 // it.name.startsWith('dex') 93 // }.each { dx -> 94 // if (dx.additionalParameters == null) { 95 // dx.additionalParameters = [] 96 // } 97 // dx.additionalParameters += '--multi-dex' // enable multidex 98 // 99 // // optional 100 // // dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list 101 // } 102 // } 103 // ... 104 dexOptions { 105 preDexLibraries = false 106 javaMaxHeapSize "2g" 107 108 } 109 }
混淆,分包
1 buildscript { 2 repositories { 3 jcenter() 4 mavenCentral() 5 } 6 dependencies { 7 classpath 'com.android.tools.build:gradle:1.3.0' 8 // classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.3.0'//统计应用方法数 9 } 10 } 11 //Error:(51, 13) Failed to resolve: org.apache.commons:commons-lang3:3.4 12 //缺少jar包,可以指定一个仓库下载(jcenter) 13 allprojects{ 14 repositories{ 15 jcenter() 16 mavenCentral() 17 } 18 } 19 apply plugin: 'android' 20 //apply plugin: 'com.getkeepsafe.dexcount' 21 22 dependencies { 23 compile fileTree(dir: 'libs', include: '*.jar') 24 compile project(':DXSP_Android') 25 compile 'com.android.support:multidex:1.0.1' 26 } 27 28 //—multi-dex:多 dex 打包的开关 29 afterEvaluate { 30 tasks.matching { 31 it.name.startsWith('dex') 32 }.each { dx -> 33 if (dx.additionalParameters == null) { 34 dx.additionalParameters = [] 35 } 36 dx.additionalParameters += '--multi-dex' // enable multidex 37 dx.additionalParameters +='--set-max-idx-number=48000'//用于控制每一个dex的最大方法个数,写小一点可以产生好几个dex,默认每个 dex 中方法数最大为65536 38 // optional 39 // dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list 40 } 41 } 42 43 android { 44 // compileSdkVersion 14 45 // buildToolsVersion "23.0.1" 46 // applicationId "com.foundersc.mobile.account" 47 compileSdkVersion 16 48 buildToolsVersion '21.1.2' 49 50 defaultConfig{ 51 applicationId "com.hundsun.winner" 52 minSdkVersion 7 53 versionCode 1 54 versionName '2.0.0' 55 multiDexEnabled true 56 } 57 58 sourceSets { 59 main { 60 manifest.srcFile 'AndroidManifest.xml' 61 java.srcDirs = ['src'] 62 resources.srcDirs = ['src'] 63 aidl.srcDirs = ['src'] 64 renderscript.srcDirs = ['src'] 65 res.srcDirs = ['res'] 66 assets.srcDirs = ['assets'] 67 } 68 69 // Move the tests to tests/java, tests/res, etc... 70 instrumentTest.setRoot('tests') 71 72 // Move the build types to build-types/<type> 73 // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 74 // This moves them out of them default location under src/<type>/... which would 75 // conflict with src/ being used by the main source set. 76 // Adding new build types or product flavors should be accompanied 77 // by a similar customization. 78 debug.setRoot('build-types/debug') 79 release.setRoot('build-types/release') 80 } 81 82 83 //去掉第三方jar包中重复的类 84 packagingOptions { 85 // exclude 'META-INF/LICENSE.txt' 86 // exclude 'META-INF/LICENSE' 87 // exclude 'META-INF/NOTICE' 88 // exclude 'META-INF/NOTICE.txt' 89 90 exclude 'META-INF/DEPENDENCIES.txt' 91 exclude 'META-INF/LICENSE.txt' 92 exclude 'META-INF/NOTICE.txt' 93 exclude 'META-INF/NOTICE' 94 exclude 'META-INF/LICENSE' 95 exclude 'META-INF/DEPENDENCIES' 96 exclude 'META-INF/notice.txt' 97 exclude 'META-INF/license.txt' 98 exclude 'META-INF/dependencies.txt' 99 exclude 'META-INF/LGPL2.1' 100 exclude 'META-INF/ASL2.0' 101 } 102 //签名 103 signingConfigs { 104 //你自己的keystore信息 105 releaseConfig { 106 storeFile file("foundersc.keystore") 107 storePassword "founderSc20151015xiaofang" 108 keyAlias "foundersc" 109 keyPassword "founderSc20151015xiaofang" 110 } 111 112 debugConfig { 113 storeFile file("foundersc.keystore") 114 storePassword "founderSc20151015xiaofang" 115 keyAlias "foundersc" 116 keyPassword "founderSc20151015xiaofang" 117 } 118 } 119 buildTypes { 120 release{ 121 minifyEnabled true 122 // shrinkResources true//资源需要在服务端返回后动态绑定,现在不需要,我不可能在代码里预定义这个资源引用,类似这种情况可能会找不到资源文件 123 signingConfig signingConfigs.releaseConfig 124 proguardFile 'proguard.cfg' 125 zipAlignEnabled true 126 renderscriptOptimLevel 5 127 128 } 129 debug{ 130 minifyEnabled false 131 // shrinkResources true//资源需要在服务端返回后动态绑定,现在不需要,我不可能在代码里预定义这个资源引用,类似这种情况可能会找不到资源文件 132 signingConfig signingConfigs.debugConfig 133 proguardFile 'proguard.cfg' 134 zipAlignEnabled true 135 renderscriptOptimLevel 5 136 137 } 138 } 139 lintOptions { 140 abortOnError false 141 } 142 143 dexOptions { 144 //incremental true 145 // 对于dex 的--multi-dex 选项设置与预编译的library工程有冲突,因此如果你的应用中包含引用的lirary工程,需要将预编译设置为false 146 //否则会抛出com.android.dex.DexException: Library dex files are not supported in multi-dex mode异常 147 preDexLibraries = false 148 //设置虚拟机堆内存空间大小,避免在编译期间OOM 149 javaMaxHeapSize "2g" 150 } 151 152 }
另外的
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 buildscript { 2 repositories { 3 jcenter() 4 mavenCentral() 5 } 6 dependencies { 7 classpath 'com.android.tools.build:gradle:1.3.0' 8 // classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.3.0'//统计应用方法数 9 } 10 } 11 //Error:(51, 13) Failed to resolve: org.apache.commons:commons-lang3:3.4 12 //缺少jar包,可以指定一个仓库下载(jcenter) 13 allprojects{ 14 repositories{ 15 jcenter() 16 mavenCentral() 17 } 18 } 19 apply plugin: 'android' 20 //apply plugin: 'com.getkeepsafe.dexcount' 21 22 dependencies { 23 compile fileTree(dir: 'libs', include: '*.jar') 24 compile 'com.android.support:multidex:1.0.1' 25 compile(name:'pulltorefresh-lib',ext:'aar') 26 27 } 28 29 //—multi-dex:多 dex 打包的开关 30 afterEvaluate { 31 tasks.matching { 32 it.name.startsWith('dex') 33 }.each { dx -> 34 if (dx.additionalParameters == null) { 35 dx.additionalParameters = [] 36 } 37 dx.additionalParameters += '--multi-dex' // enable multidex 38 dx.additionalParameters +='--set-max-idx-number=48000'//用于控制每一个dex的最大方法个数,写小一点可以产生好几个dex,默认每个 dex 中方法数最大为65536 39 // optional 40 // dx.additionalParameters += "--main-dex-list=$projectDir/<filename>".toString() // enable the main-dex-list 41 } 42 } 43 repositories{ 44 flatDir{ 45 dirs 'libs' 46 } 47 } 48 android { 49 // compileSdkVersion 14 50 // buildToolsVersion "23.0.1" 51 // applicationId "com.foundersc.mobile.account" 52 compileSdkVersion 14 53 buildToolsVersion '22.0.1' 54 55 defaultConfig{ 56 applicationId "com.hundsun.winner" 57 minSdkVersion 14 58 versionCode 1 59 versionName '2.0.0' 60 multiDexEnabled true 61 } 62 63 sourceSets { 64 main { 65 manifest.srcFile 'AndroidManifest.xml' 66 java.srcDirs = ['src'] 67 resources.srcDirs = ['src'] 68 aidl.srcDirs = ['src'] 69 renderscript.srcDirs = ['src'] 70 res.srcDirs = ['res'] 71 assets.srcDirs = ['assets'] 72 } 73 74 // Move the tests to tests/java, tests/res, etc... 75 instrumentTest.setRoot('tests') 76 77 // Move the build types to build-types/<type> 78 // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... 79 // This moves them out of them default location under src/<type>/... which would 80 // conflict with src/ being used by the main source set. 81 // Adding new build types or product flavors should be accompanied 82 // by a similar customization. 83 debug.setRoot('build-types/debug') 84 release.setRoot('build-types/release') 85 } 86 87 88 //去掉第三方jar包中重复的类 89 packagingOptions { 90 // exclude 'META-INF/LICENSE.txt' 91 // exclude 'META-INF/LICENSE' 92 // exclude 'META-INF/NOTICE' 93 // exclude 'META-INF/NOTICE.txt' 94 95 exclude 'META-INF/DEPENDENCIES.txt' 96 exclude 'META-INF/LICENSE.txt' 97 exclude 'META-INF/NOTICE.txt' 98 exclude 'META-INF/NOTICE' 99 exclude 'META-INF/LICENSE' 100 exclude 'META-INF/DEPENDENCIES' 101 exclude 'META-INF/notice.txt' 102 exclude 'META-INF/license.txt' 103 exclude 'META-INF/dependencies.txt' 104 exclude 'META-INF/LGPL2.1' 105 exclude 'META-INF/ASL2.0' 106 } 107 //签名 108 signingConfigs { 109 //你自己的keystore信息 110 releaseConfig { 111 storeFile file("wf.keystore") 112 storePassword "123456" 113 keyAlias "wfwf" 114 keyPassword "654321" 115 } 116 117 debugConfig { 118 storeFile file("wf.keystore") 119 storePassword "123456" 120 keyAlias "wfwf" 121 keyPassword "654321" 122 } 123 } 124 buildTypes { 125 release{ 126 minifyEnabled true 127 // shrinkResources true//资源需要在服务端返回后动态绑定,现在不需要,我不可能在代码里预定义这个资源引用,类似这种情况可能会找不到资源文件 128 signingConfig signingConfigs.releaseConfig 129 proguardFile 'proguard.cfg' 130 zipAlignEnabled true 131 renderscriptOptimLevel 5 132 133 } 134 debug{ 135 minifyEnabled false 136 // shrinkResources true//资源需要在服务端返回后动态绑定,现在不需要,我不可能在代码里预定义这个资源引用,类似这种情况可能会找不到资源文件 137 signingConfig signingConfigs.debugConfig 138 proguardFile 'proguard.cfg' 139 zipAlignEnabled true 140 renderscriptOptimLevel 5 141 142 } 143 } 144 lintOptions { 145 abortOnError false 146 } 147 148 dexOptions { 149 //incremental true 150 // 对于dex 的--multi-dex 选项设置与预编译的library工程有冲突,因此如果你的应用中包含引用的lirary工程,需要将预编译设置为false 151 //否则会抛出com.android.dex.DexException: Library dex files are not supported in multi-dex mode异常 152 preDexLibraries = false 153 //设置虚拟机堆内存空间大小,避免在编译期间OOM 154 javaMaxHeapSize "2g" 155 } 156 157 }