[Android 常用配置] Android 项目配置,包含常用的库,自己习惯的配置项等
// BugTags
compile 'com.bugtags.library:bugtags-lib:latest.integration'
// 官方库
compile 'com.android.support:multidex:1.0.1'
//noinspection GradleDependency
compile "com.android.support:appcompat-v7:$rootProject.supportVersion"
//noinspection GradleDependency
compile "com.android.support:design:$rootProject.supportVersion"
//noinspection GradleDependency
compile "com.android.support:support-v4:$rootProject.supportVersion"
// Gridlayout兼容包,为了使用 Api 21 才引入的 layout_columnWeight 和 layout_rowWeight 属性
//noinspection GradleDependency
compile "com.android.support:gridlayout-v7:$rootProject.supportVersion"
// java8-like stream api
compile 'com.annimon:stream:1.1.6'
// 网络库
// compile "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
compile 'com.github.twiceyuan.retrofit:retrofit:a5252e4bfb'
compile("com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion") {
exclude group: 'com.squareup.retrofit2', module: 'retrofit'
}
compile("com.squareup.retrofit2:adapter-rxjava:$rootProject.retrofitVersion") {
exclude group: 'com.squareup.retrofit2', module: 'retrofit'
}
compile 'com.squareup.okhttp3:logging-interceptor:3.4.2'
compile 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
// 请求模拟
compile 'com.github.twiceyuan.RetrofitMockResult:processor:c1cdc0ee5a'
compile 'com.github.twiceyuan.RetrofitMockResult:core:c1cdc0ee5a'
// 控件绑定
compile 'com.jakewharton:butterknife:8.5.1'
apt 'com.jakewharton:butterknife-compiler:8.5.1'
// 基本控件
compile 'com.jude:rollviewpager:1.2.8'
compile 'in.srain.cube:ultra-ptr:1.0.11'
compile 'jp.wasabeef:recyclerview-animators:1.3.0'
compile 'com.github.aakira:expandable-layout:1.6.0@aar'
compile 'com.sunfusheng:marqueeview:1.2.0'
compile 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
// 模仿 iOS 的 PickerView 的控件(访客预约二级联动选择需求)
compile 'com.bigkoo:pickerview:2.1.1'
// 数据解析
compile 'com.google.code.gson:gson:2.7'
// RxJava
compile 'io.reactivex:rxjava:1.1.6'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
// 图片浏览
compile 'com.commit451:PhotoView:1.2.5'
// 通用适配器
compile('com.github.twiceyuan:CommonAdapter:0.6.4') {
exclude group: 'com.android.support', module: 'recyclerview-v7'
}
// 极光推送
compile 'cn.jiguang:jpush:2.2.0'
// Parcel 预编译动态生成
compile "org.parceler:parceler-api:$rootProject.parcelerVersion"
apt "org.parceler:parceler:$rootProject.parcelerVersion"
// facebook Chrome debug tool (只在开发版本引入, 通过反射动态加载)
compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
// 下拉刷新
compile 'com.navercorp.pulltorefresh:library:3.2.0@aar'
// 内容状态管理
compile 'com.github.twiceyuan:StatefulLayout:1.2.1-custom'
// 事件总线
compile 'de.greenrobot:eventbus:2.4.0'
// 图片加载
compile 'com.github.bumptech.glide:glide:3.7.0'
// 日志打印
compile 'com.github.twiceyuan:AndroidLog:1.0.4'
// 设置存储
compile 'com.github.twiceyuan:RetroPreference:0.5'
// 常用函数
compile 'com.github.twiceyuan:JavaSugar:985b41b36c'
// RxActivity Result
compile 'com.github.twiceyuan.RxActivityResult:rxactivityresult:1.1-rxjava1@aar'
// 打包信息辅助工具
compile 'com.meituan.android.walle:library:1.0.5'
// Bugly
// 其中latest.release指代最新Bugly SDK版本号,也可以指定明确的版本号,例如2.2.0
compile 'com.tencent.bugly:crashreport:latest.release'
maven { url "https://jitpack.io" }
build.gradle 项目级别:
buildscript {
repositories {
jcenter()
}
dependencies {
// Android Gradle 插件
classpath 'com.android.tools.build:gradle:2.3.1'
// AnnotationProcessor
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// Java 8
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
项目级别用到的依赖,推荐放到项目级别去定义版本,方便模块间统一
ext {
minSdk = 18
targetSdk = 24
compileSdkVersion = 25
supportVersion = "25.3.1"
buildTools = "25.0.2"
parcelerVersion = "1.1.5"
retrofitVersion = "2.2.0"
}
需要通过 gradle 任务打包的,需要在 module 中配置项目的证书信息:
android {
signingConfigs {
config {
keyAlias 'alias 名称'
keyPassword '证书 phrase'
storeFile file('../证书的路径,相对本文件的路径')
storePassword '存储密码'
}
}
}
例如清单文件中有 ${applicationId} 是默认替换的,如果定义了 ${XXX_APP_ID} 那么在 gralde android 节点下可以这样定义
manifestPlaceholders = [
XXX_APP_ID : "real-app-id",
]
resValue "string", "app_name", DEV_APP_NAME
// build type name
alpha {
// 定义替换 BuildConfig 这个类中的常量值
buildConfigField "boolean", "amIGroot", "false"
// 是否进行混淆
minifyEnabled true
// 是否去除没有用到的资源
shrinkResources true
// zip 对齐
zipAlignEnabled true
// 证书信息
signingConfig signingConfigs.config
// 是否可以 debug
debuggable true
// 混淆文件
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}