Android_build.gradle配置

1.使用自定义签名
android {
    compileSdkVersion 17
    buildToolsVersion "19.0.3"


    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 18
    }


    File signFile = rootProject.file('sign/keystore.properties')
    if (signFile.exists()) {
        Properties properties = new Properties()
        properties.load(new FileInputStream(signFile))
        signingConfigs {
            release {
                storeFile rootProject.file(properties['keystore'])
                storePassword properties['storePassword']
                keyAlias properties['keyAlias']
                keyPassword properties['keyPassword']
            }
        }
    }


    buildTypes {
        release {
            runProguard true
            zipAlign true
            proguardFile rootProject.file('proguard-rules.cfg')
            signingConfig signingConfigs.release
        }
        debug {
            runProguard false
            zipAlign true
        }
    }
}
2.build.gradle
// 看注释基本可以满足基本试用场景
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
}
}


//可以定义变量
def isPrintLog = "isprintlog=true"
def ln = System.getProperty('line.separator')


//工程描述
description = 'The Build for Android'


//表明是gradle-android插件
apply plugin: 'android'


//设置文件编码
tasks.withType(Compile) {
options.encoding = 'UTF-8'
}


//本地libs
dependencies {
//compile fileTree(dir: 'libs', include: '*.jar')
compile files('libs/android-support-v4.jar')
}


//修改配置文件
task modifyFile << {
def File f = project.file('assets1/config.dat')
f << "$isPrintLog$ln"
println "****** = modify file = ******"
}


//替换字符串
task replaceFile << {
ant.replace(
file: 'assets1/config.dat',
token: "isprintlog=true",
value: "$isPrintLog$ln")
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
//可以修改包名
project.archivesBaseName = "MyAndroid";


defaultConfig {
minSdkVersion 7
targetSdkVersion 16
versionCode = 3
versionName = '1.0.1'
}


//签名配置
signingConfigs {
release {
storeFile file("baseAndroid.keystore")
storePassword "base1234"
keyAlias "baseAndroid"
keyPassword "base1234"
}
}
buildTypes {


release {
signingConfig signingConfigs.release
runProguard true
proguardFile 'proguard-project.txt'//混淆
}


}


productFlavors {
playstore {
packageName = 'com.yanlu.goocyx.android'
}
taobao {
packageName = 'com.yanlu.goocyx.android2'
}
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
//不同的productFlavors,使用不同的assets文件
playstore {
assets.srcDirs = ['assets1']
}
}
}



你可能感兴趣的:(Android/iOS测试)