Android Studio 是采用 gradle 来构建项目的,gradle 是基于 groovy 语言的,如果只是用它构建普通 Android 项目的话,是可以不去学 groovy 的。当我们创建一个 Android 项目时会包含两个 Android build.gradle 配置详解文件。
1. Project 的 build.gradle 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0'
} }
allprojects { repositories { google() jcenter() } }
task clean(type: Delete) { delete rootProject.buildDir }
|
2. Module 的 build.gradle 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
apply plugin: 'com.android.application'
android { signingConfigs { release { keyAlias 'test' keyPassword '123456' storeFile file('test.jks') storePassword '123456' } debug { keyAlias 'test' keyPassword '123456' storeFile file('test.jks') storePassword '123456' } } compileSdkVersion 27 defaultConfig { applicationId "com.billy.myapplication" minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" flavorDimensions "versionCode" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { buildConfigField("boolean", "LOG_DEBUG", "false") buildConfigField("String", "URL_PERFIX", "\"https://release.cn/\"") minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release pseudoLocalesEnabled false zipAlignEnabled true applicationIdSuffix 'test' versionNameSuffix 'test' } debug { buildConfigField("boolean", "LOG_DEBUG", "true") buildConfigField("String", "URL_PERFIX", "\"https://test.com/\"") minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.debug debuggable false jniDebuggable false renderscriptDebuggable false zipAlignEnabled true pseudoLocalesEnabled false applicationIdSuffix 'test' versionNameSuffix 'test' } }
sourceSets { main { jniLibs.srcDirs = ['libs'] } }
packagingOptions{ pickFirsts = ['META-INF/LICENSE']
merge 'META-INF/LICENSE'
exclude 'META-INF/services/javax.annotation.processing.Processor' }
productFlavors { wandoujia {} xiaomi {} _360 {} }
productFlavors.all { flavor -> flavor.manifestPlaceholders = [IFLYTEK_CHANNEL: name] }
lintOptions { abortOnError false checkReleaseBuilds false }
}
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
|
本文参考:https://www.jianshu.com/p/c11862136abf