您的位置:首页 > 移动开发 > Android开发

android Gradle打包使用教程

2016-05-15 22:59 399 查看
添加依赖:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.1.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
}

自定义函数:

def releaseTime() {
return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))
}

配置java编译参数:

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

配置签名文件

//配置签名文件
signingConfigs {
config {
keyAlias 'android'
keyPassword '123456'
storeFile file('E:/Android文档/keystore/keystore.jks')
storePassword '123456'
}
}


默认配置参数

defaultConfig {
applicationId "com.hai"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName '1.0'
signingConfig signingConfigs.config
}


编译types

buildTypes {
release {
//引用签名配置
signingConfig signingConfigs.config
//移除无用的资源文件
minifyEnabled true
proguardFile 'E:/Workspace_studio/Test_android/app/proguard-rules.pro'
applicationIdSuffix 'release'
//版本名后缀
versionNameSuffix 'release'
//本地化支持管理
pseudoLocalesEnabled true
//zip align优化
zipAlignEnabled true
//修改apk文件名
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
def fileName = "myapp_v${defaultConfig.versionName}_${releaseTime()}.apk"
output.outputFile = new File(outputFile.parent, fileName)

}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gradle