apply plugin: 'com.android.application' apply plugin: 'com.jakewharton.butterknife' apply plugin: 'realm-android' android { compileSdkVersion rootProject.ext.android.compileSdkVersion defaultConfig { applicationId rootProject.ext.android.applicationId minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion // versionCode rootProject.ext.android.versionCode versionCode getProperty("version.properties","versionCode",true) versionName rootProject.ext.android.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } } multiDexEnabled true } lintOptions { checkReleaseBuilds false abortOnError false } signingConfigs { release { try { storeFile file("fxy.jks") storePassword KEYSTORE_PASSWORD keyAlias "fxy" keyPassword KEY_PASSWORD } catch (ex) { throw new ExceptionInInitializerError("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.") } } debug { try { storeFile file("fxy.jks") storePassword KEYSTORE_PASSWORD keyAlias "fxy" keyPassword KEY_PASSWORD } catch (ex) { throw new ExceptionInInitializerError("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.") } } } buildTypes { release { // 开启混淆 minifyEnabled false // 对齐zip zipAlignEnabled true // 删除无用资源 shrinkResources false // 是否debug debuggable false // 命名后缀 //versionNameSuffix "_release" applicationIdSuffix '.eac.fxy' // 签名 signingConfig signingConfigs.release buildConfigField("String", "OSS_HOST", "\"https://fhdr.oss-cn-shenzhen.aliyuncs.com\"") buildConfigField("String", "RESOURCE_TYPE", "\"aliyun\"") buildConfigField("String", "RESOURCE_PREFIX", "\"prod/fxy\"")//只是默认值 buildConfigField("String", "WELCOME_TITLE", "\"FXY\"") buildConfigField("String", "VERSION_API", "\"" + rootProject.ext.android.versionApi + "\"") buildConfigField("String", "VERSION_NUM", "\""+rootProject.ext.android.versionName+"\"") manifestPlaceholders = [ app_name:"返修易", icon:"@mipmap/ic_launcher", round_icon:"@mipmap/ic_launcher_round" ] proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { multiDexEnabled true debuggable true zipAlignEnabled false shrinkResources false minifyEnabled false versionNameSuffix "_debug" applicationIdSuffix '.eac.fxy.debug' signingConfig signingConfigs.debug manifestPlaceholders = [ app_name:"UAT-返修易", icon:"@mipmap/ic_launcher", round_icon:"@mipmap/ic_launcher_round" ] buildConfigField("String", "OSS_HOST", "\"https://fhdr.oss-cn-shenzhen.aliyuncs.com\"") buildConfigField("String", "RESOURCE_TYPE", "\"aliyun\"") buildConfigField("String", "RESOURCE_PREFIX", "\"uat/fxy\"")//只是默认值 buildConfigField("String", "WELCOME_TITLE", "\"UAT-返修易\"") buildConfigField("String", "VERSION_API", "\"" + rootProject.ext.android.versionApi + "\"") buildConfigField("String", "VERSION_NUM", "\""+rootProject.ext.android.versionName+"\"") proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } //需要在 baselibrary也配置一下 } android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "fxy-pda-${variant.buildType.name}_v${defaultConfig.versionName}_${releaseTime()}.apk" } } /* // 输出文件配置 applicationVariants.all { variant -> variant.outputs.each { output -> def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { def dirName = outputFile.parent // 输出文件夹所在的位置 // 文件名修改 def fileName = "app-${output.processResources.variantName}-${defaultConfig.versionName}-${variant.flavorName}.apk" // 比如不想这么麻烦,直接在后面加上版本号也行: // def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk") output.outputFile = new File(dirName, fileName) } } }*/ aaptOptions { cruncherEnabled = false useNewCruncher = false } sourceSets { main { jniLibs.srcDirs = ['libs'] } } packagingOptions { exclude 'META-INF/rxjava.properties' } } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') // androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { // exclude group: 'com.android.support', module: 'support-annotations' // }) // butterknife implementation rootProject.ext.dependencies.butterknife annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' implementation 'com.luozm.captcha:captcha:1.1.2' implementation rootProject.ext.dependencies.multidex implementation rootProject.ext.dependencies.Spinner // implementation rootProject.ext.dependencies.litepal testImplementation 'junit:junit:4.12' compile 'com.android.support:multidex:1.0.2' compile project(':baselibrary') implementation 'com.github.bingoogolapple.BGAQRCode-Android:zbar:1.3.8' // 自定义构建类型依赖 // raedebugCompile project(path: ':sdk', configuration: 'zj_release') } //解决控件台中文乱码问题 tasks.withType(JavaCompile) { options.encoding = "UTF-8" } def releaseTime() { return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+8:00")) } /** * @param filename 要打开的文件名字 * @param propName 文件里面的键名字 * @param isRootProject 是否用rootProject 文件打开,true 的话,在编译时候可以得到值,打包时候无法得到值。false的话在打包时候可以得到值,编译时候 无法得到值 * @return 所选择的文件里面的propName对应的值 */ def getProperty(String filename, String propName,boolean isRootProject) { //在这里 必须是在rootProject.file 如果 file的话 ,编译时候会出错 def propsFile def versionCode = 2 if (isRootProject) { propsFile = rootProject.file(filename) }else { propsFile = file(filename) } if (propsFile.exists()) { def props = new Properties() props.load(new FileInputStream(propsFile)) if (props[propName] != null) { //下面这个输出在android studio3.1里面 在Build窗口 右边一个锤子下面 toggle哪里,就是原来的message哪里 print("versionCode "+props[propName]) def code = (props[propName]).toInteger() //转成Integer props[propName] = (++code).toString() //自增 且转成String versionCode = code } else { print("No such property " + propName + " in file " + filename) } //在这里提交 对version.properties的更改 props.store(propsFile.newWriter(),null) } else { print(filename + " does not exist!") } return versionCode }