build.gradle文件
1 apply plugin: 'com.android.application' 2 apply plugin: 'org.greenrobot.greendao' // 使用greenDAO 3 4 def static releaseTime() {//获取当前时间 5 return new Date().format("MMdd", TimeZone.getTimeZone("UTC")) 6 } 7 android { 8 compileSdkVersion project.ext.compileSdkVersion//引用统一配置 9 buildToolsVersion '28.0.3' 10 11 compileOptions { 12 sourceCompatibility JavaVersion.VERSION_1_8//支持java8 13 targetCompatibility JavaVersion.VERSION_1_8 14 } 15 16 defaultConfig { 17 applicationId "xx.xx.xx" 18 minSdkVersion project.ext.minSdkVersion 19 targetSdkVersion project.ext.targetSdkVersion 20 versionCode 24 21 versionName "1.0.9.4" 22 23 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 24 ndk { 25 26 // 设置支持的SO库架构 27 abiFilters 'armeabi-v7a' //设置支持的arm架构 28 } 29 30 vectorDrawables.useSupportLibrary = true//是否使用svg 31 32 33 } 34 35 signingConfigs {//使用签名文件 36 debug { 37 storeFile file('xx.jks') 38 storePassword "xxxx" 39 keyAlias "xxxx" 40 keyPassword "xxxx" 41 } 42 43 release { 44 storeFile file('xxx.jks') 45 storePassword "xxx" 46 keyAlias "xxx" 47 keyPassword "xxxx" 48 } 49 } 50 51 buildTypes {//打包命名 52 release { 53 minifyEnabled false 54 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 55 buildConfigField "boolean", "isNative", "false" 56 applicationVariants.all { variant -> 57 variant.outputs.all { output -> 58 def outputFile = output.outputFile 59 if (outputFile != null && outputFile.name.endsWith('.apk')) { 60 outputFileName = "${defaultConfig.versionName}.apk" 61 } 62 } 63 } 64 signingConfig signingConfigs.release 65 } 66 debug { 67 minifyEnabled false 68 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 69 buildConfigField "boolean", "isNative", "true" 70 applicationVariants.all { variant -> 71 variant.outputs.all { output -> 72 def outputFile = output.outputFile 73 if (outputFile != null && outputFile.name.endsWith('.apk')) { 74 outputFileName = "${defaultConfig.versionName}_${versionNameSuffix}.apk" 75 } 76 } 77 } 78 versionNameSuffix "_debug_${releaseTime()}" 79 } 80 } 81 82 flavorDimensions "api" 83 84 85 productFlavors {//个性化配置 86 dev { 87 dimension "api" 88 buildConfigField "String", "BaseURL", '"http://192.168.10.175:3201"' 89 buildConfigField "String", "APIURL", '"http://192.168.10.175:3201"' 90 buildConfigField "String", "MQTT_SERVER", '"tcp://192.168.25.209:1883"' 91 92 } 93 94 95 normal { 96 dimension "api" 97 buildConfigField "String", "BaseURL", '"http://xxxx.com.cn"' 98 buildConfigField "String", "APIURL", '"http://xxxx.com.cn"' 99 buildConfigField "String", "MQTT_SERVER", '"ssl://xxxxx.com.cn:8883"' 100 } 101 } 102 103 104 sourceSets {//jniLib目录支持app/libs 105 main.jniLibs.srcDirs = ['libs'] 106 } 107 108 109 lintOptions { 110 checkReleaseBuilds false 111 // Or, if you prefer, you can continue to check for errors in release builds, 112 // but continue the build even when errors are found: 113 abortOnError false 114 } 115 116 117 } 118 119 greendao { 120 schemaVersion 4 121 daoPackage 'ai.yunji.delivery.greendao.gen' 122 targetGenDir 'src/main/java' 123 } 124 125 repositories { 126 flatDir { 127 dirs 'libs' 128 } 129 } 130 131 dependencies { 132 implementation fileTree(include: ['*.jar'], dir: 'libs') 133 testImplementation 'junit:junit:4.12' 134 implementation "com.android.support:appcompat-v7:${supportLibVersion}" 135 implementation 'com.android.support.constraint:constraint-layout:1.1.2' 136 // implementation 'org.glassfish.tyrus.bundles:tyrus-standalone-client:1.5' 137 // implementation('edu.wpi.rail:jrosbridge:0.2.0') { 138 // exclude group: 'org.glassfish.grizzly' 139 // exclude group: 'org.glassfish.tyrus' 140 // } 141 //log相关 142 implementation 'com.tencent.bugly:crashreport:latest.release' 143 //其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.1.9 144 implementation 'com.tencent.bugly:nativecrashreport:latest.release' 145 //其中latest.release指代最新Bugly NDK版本号,也可以指定明确的版本号,例如3.0 146 implementation 'com.trello.rxlifecycle2:rxlifecycle:2.1.0' 147 implementation 'com.trello.rxlifecycle2:rxlifecycle-android:2.1.0' 148 implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.1.0' 149 implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.3@aar' 150 implementation 'com.jakewharton:butterknife:8.8.1' 151 implementation "com.android.support:design:${supportLibVersion}" 152 annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 153 // implementation 'com.github.bumptech.glide:glide:4.7.1' 154 // annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1' 155 implementation "com.android.support:recyclerview-v7:${supportLibVersion}" 156 // implementation 'com.jcodecraeer:xrecyclerview:1.5.9' 157 // implementation 'com.orhanobut:logger:2.2.0' 158 implementation 'com.elvishew:xlog:1.4.0' 159 implementation 'org.greenrobot:eventbus:3.0.0' 160 debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.3' 161 releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.3' 162 implementation 'com.github.bumptech.glide:glide:4.8.0' 163 implementation 'com.zhy:okhttputils:2.6.2' 164 //greenDao 165 implementation 'org.greenrobot:greendao:3.1.0' 166 //logger 167 // implementation 'com.orhanobut:logger:2.2.0' 168 169 170 implementation 'com.squareup.retrofit2:retrofit:2.4.0' 171 // Retrofit库 172 implementation('com.squareup.retrofit2:converter-gson:2.1.0') { 173 exclude group: 'com.google.code.gson', module: 'gson' 174 } 175 implementation 'com.alibaba:fastjson:1.2.58' 176 implementation 'com.belerweb:pinyin4j:2.5.1' 177 178 implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' 179 implementation 'io.reactivex.rxjava2:rxjava:2.1.1' 180 181 debugImplementation 'com.amitshekhar.android:debug-db:1.0.3' 182 implementation project(path: ':logger') 183 // implementation project(path: ':Water') 184 185 configurations { 186 all*.exclude group: 'com.google.code.gson' 187 } 188 189 }
项目的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google()//如果网络不好,可以使用阿里服务器的镜像地址 maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'com.novoda:bintray-release:0.8.0' // classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1-rc1' //GreanDao classpath 'org.greenrobot:greendao-gradle-plugin:3.1.0' } }/* ext { compileSdkVersion = 27 buildToolsVersion = '27.0.3' minSdkVersion = 14 targetSdkVersion = 27 supportLibraryVersion = '27.0.2' versionCode = 113 versionName = "1.1.3" }*/ ext { minSdkVersion = 8 targetSdkVersion = 27 compileSdkVersion = 27 buildToolsVersion = '27.0.3' } ext.deps = [ junit : 'junit:junit:4.12', truth : 'com.google.truth:truth:0.28', robolectric : 'org.robolectric:robolectric:3.3', mockito : "org.mockito:mockito-core:2.8.9", json : "org.json:json:20160810", supportAnnotations: "com.android.support:support-annotations:27.1.0", ] subprojects { apply from: "${rootProject.rootDir}/common_config.gradle" } allprojects { repositories { google() maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } jcenter() mavenCentral() } } task clean(type: Delete) { delete rootProject.buildDir }
gradle.properties
android.injected.testOnly=false#一般情况下debug包给用户是安装不了的,因为打包的时候会自动在androidmenifest.xml中添加testOnly=true,这种情况下只能使用adb install -t xxx.apk安装,如果加这句话就不会影响安装了