Android-项目架构

前言

写完一个小项目,接着写下一个的时候,总是会发现,有些必要的工具库或者代码库,要回过头去寻找。又或者一些库的名字有所遗忘,版本有更新,再去寻找的时候,总是会浪费很多时间。所以在这篇文章中,记录一下日后项目构建所需要的代码库的地址和配置,以及一些简单必要的代码。

工具库

RxLifecycle

Installation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
compile 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
// If you want to bind to Android-specific lifecycles
compile 'com.trello.rxlifecycle2:rxlifecycle-android:2.2.1'
// If you want pre-written Activities and Fragments you can subclass as providers
compile 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
// If you want pre-written support preference Fragments you can subclass as providers
compile 'com.trello.rxlifecycle2:rxlifecycle-components-preference:2.2.1'
// If you want to use Navi for providers
compile 'com.trello.rxlifecycle2:rxlifecycle-navi:2.2.1'
// If you want to use Android Lifecycle for providers
compile 'com.trello.rxlifecycle2:rxlifecycle-android-lifecycle:2.2.1'
// If you want to use Kotlin syntax
compile 'com.trello.rxlifecycle2:rxlifecycle-kotlin:2.2.1'
// If you want to use Kotlin syntax with Android Lifecycle
compile 'com.trello.rxlifecycle2:rxlifecycle-android-lifecycle-kotlin:2.2.1'

地址

Github

Gson

地址

Github

RxPicker

Installation

compile 'com.caimuhao:rxpicker:1.1.5'

地址

Github

MNCrashMonitor

CrashMonitor 监听程序崩溃日志,直接页面展示崩溃日志列表

Installation

  • 在Project的build.gradle中添加仓库地址
1
2
3
4
5
6
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
  • 在app目录下的build.gradle中添加依赖
1
2
3
dependencies {
compile 'com.github.maning0303:MNCrashMonitor:V1.0.5'
}

地址

Github

Logger

Installation

compile 'com.orhanobut:logger:2.1.1'

地址

Github

ASimpleCache

地址

Github

Android Studio Plugins

地址

Github

RxGps

Installation

compile 'com.github.florent37:rxgps:(last version)'

地址

Github

ObjectBox

Installation

Add this to your root build.gradle (project level):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
buildscript {
ext.objectboxVersion = '1.3.4'
repositories {
maven { url "http://objectbox.net/beta-repo/" }
}
dependencies {
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
}
}
allprojects {
repositories {
maven { url "http://objectbox.net/beta-repo/" }
}
}

And this to our app’s build.gradle (module level):

apply plugin: 'io.objectbox' // after applying Android plugin

地址

Github

ARouter

Installation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
android {
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [ moduleName : project.getName() ]
}
}
}
}
dependencies {
// 替换成最新版本, 需要注意的是api
// 要与compiler匹配使用,均使用最新版可以保证兼容
compile 'com.alibaba:arouter-api:x.x.x'
annotationProcessor 'com.alibaba:arouter-compiler:x.x.x'
...
}

地址

Github

RxFile

Installation

compile 'com.github.pavlospt:rxfile:1.7'

地址

Github

Matisse

Installation

1
2
3
4
5
6
7
repositories {
jcenter()
}
dependencies {
compile 'com.zhihu.android:matisse:0.4.3'
}

地址

Github

JKeyboardPanelSwitch

Installation

compile 'cn.dreamtobe.kpswitch:library:1.6.0'

地址

Github

Phoenix

Installation

1
2
3
4
5
6
7
8
//图片/视频选择、预览、编辑与拍照
compile 'com.github.guoxiaoxing:phoenix:x'
//选填 - 图片压缩,开启功能:Phoenix.with().enableCompress(true),获取结果:MediaEntity.getCompressPath()
compile 'com.github.guoxiaoxing:phoenix-compress-picture:1.0.11'
//选填 - 视频压缩,开启功能:Phoenix.with().enableCompress(true),获取结果:MediaEntity.getCompressPath()
compile 'com.github.guoxiaoxing:phoenix-compress-video:1.0.11'

地址

Github

AndroidPerformanceMonitor

Installation

1
2
3
4
5
6
7
8
dependencies {
// most often used way, enable notification to notify block event
compile 'com.github.markzhai:blockcanary-android:1.5.0'
// this way you only enable BlockCanary in debug package
// debugCompile 'com.github.markzhai:blockcanary-android:1.5.0'
// releaseCompile 'com.github.markzhai:blockcanary-no-op:1.5.0'
}

地址

Github

drawable-optimizer

Installation

In build.gradle

1
2
3
4
5
6
7
8
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.fabiomsr:drawable-optimizer-gradle-plugin:1.0.4'
}
}

And in app\build.gradle

1
2
// Make sure this line comes *after* you apply the Android plugin (apply plugin: 'com.android.application')
apply plugin: 'org.fabiomsr.drawableoptimizer'

Android-Debug-Database

Installation

debugCompile 'com.amitshekhar.android:debug-db:1.0.1'

地址

Github

RxAndroid

Installation

1
2
3
4
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex.rxjava2:rxjava:2.1.7'

地址

Github

RxPermissions

Installation

compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar'

地址

Github

UI库

android-Ultra-Pull-To-Refresh

Installation

compile 'in.srain.cube:ultra-ptr:1.0.11'

地址

Github