Android 常用开源框架和项目(持续更新中...)

前言

把之前项目中用到和网上看到一些Android框架、库和开源项目进行汇总,方便今天的查找和使用。日后会不断更新和添加…另外,文章中 gif 图可能会挂,开源到 GitHub 上看一下原图(比较大)


1、网络请求框架


1.1、OkHttp


An HTTP & HTTP/2 client for Android and Java applications

Android 和 Java 应用的 Http & Http/2 client

1
compile 'com.squareup.okhttp3:okhttp:3.5.0'

ProGuard

1
-dontwarn okhttp3.**


1.2、Retrofit


Type-safe HTTP client for Android and Java by Square, Inc. Retrofit turns your HTTP API into a Java interface.

类型安全的 Android 和 Java 的 Http 请求库。

1
compile 'com.squareup.retrofit2:retrofit:2.1.0'

需要 Java7 或者 Android Studio 2.3


1.3、Volley



1
git clone https://android.googlesource.com/platform/frameworks/volley


1.4、Asynchronous Http Client for Android



An asynchronous, callback-based Http client for Android built on top of Apache’s HttpClient libraries.

一个异步、基于回调的Android Http Client, 封装了 Apache 的 HttpClient 库

1
compile 'com.loopj.android:android-async-http:1.4.9'


1.5、框架比较



网络框架比较


2、图片加载框架


2.1、ImageLoader


Android 2.0+ support

Features

  • Multithread image loading (async or sync)
  • Wide customization of ImageLoader’s configuration (thread executors, downloader, decoder, memory and disk cache, display image options, etc.)
  • Many customization options for every display image call (stub images, caching switch, decoding options, Bitmap processing and displaying, etc.)
  • Image caching in memory and/or on disk (device’s file system or SD card)
  • Listening loading process (including downloading progress)

Load & Display Task Flow

Load & Display Task Flow

1
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'

2.2、Picasso



A powerful image downloading and caching library for Android

image

1
compile 'com.squareup.picasso:picasso:2.5.2'

ProGuard

1
-dontwarn com.squareup.okhttp.**

2.3、Glide



Glide is a fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug in to Google’s Volley project or Square’s OkHttp library instead.

Glide’s primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

1
2
3
4
5
6
7
8
repositories {
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:19.1.0'
}

ProGuard

Depending on your ProGuard (DexGuard) config and usage, you may need to include the following lines in your proguard.cfg (see Configuration wiki for more details):

1
2
3
4
5
6
7
8
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
# for DexGuard only
-keepresourcexmlelements manifest/application/meta-data@value=GlideModule

2.4、Fresco


Fresco supports Android 2.3 (Gingerbread) and later.

Fresco is a powerful system for displaying images in Android applications.

Fresco takes care of image loading and display, so you don’t have to. It will load images from the network, local storage, or local resources, and display a placeholder until the image has arrived. It has two levels of cache; one in memory and another in internal storage.

In Android 4.x and lower, Fresco puts images in a special region of Android memory. This lets your application run faster - and suffer the dreaded OutOfMemoryError much less often.

Fresco also supports:

  • streaming of progressive JPEGs
  • display of animated GIFs and WebPs
  • extensive customization of image loading and display
    and much more!
1
compile 'com.facebook.fresco:fresco:1.1.0'


2.5、框架比较



图片缓存原理、特性对比


3、响应式编程


3.1、RxJava

1
compile 'io.reactivex.rxjava2:rxjava:x.y.z'


3.2、RxAndroid



RxAndroid: Reactive Extensions for Android

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.0.1'


4、注解


4.1、Butter Knife



image

1
2
3
4
dependencies {
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}

然后,附赠一个 ‘Android Studio’ 的插件 ‘Android ButterKnife Zelezny’,能够自动生成代码以及Holder


4.2、Dagger



A fast dependency injector for Android and Java.

教程

Android:dagger2让你爱不释手-基础依赖注入框架篇

Android:dagger2让你爱不释手-重点概念讲解、融合篇




5、数据库


5.1、OrmLite



Object Relational Mapping Lite (ORM Lite) provides some lightweight functionality for persisting Java objects to SQL databases while avoiding the complexity and overhead of more standard ORM packages. It supports a number of SQL databases using JDBC and also supports Sqlite with native calls to Android OS database APIs.

ORMLite provides the following features:

  • Setup your classes by simply adding Java annotations.
  • Powerful abstract Database Access Object (DAO) classes.
  • Flexible QueryBuilder to easily construct simple and complex queries.
  • Supports MySQL, Postgres, Microsoft SQL Server, H2, Derby, HSQLDB, and Sqlite and can be extended to additional databases relatively easily.
  • Provisional support for DB2, Oracle, ODBC, and Netezza. Contact the author if your database type is not supported.
  • Handles “compiled” SQL statements for repetitive query tasks.
  • Supports “foreign” objects with the class field being the object but an id stored in the database table.
  • Basic support for database transactions.
  • Auto generates SQL to create and drop database tables.
  • Spring configuration support for DOAs and class configurations.
  • Support for configuring of tables and fields without annotations.

    5.2、GreenDao



    image

greenDAO’s Features at a glance

  • Maximum performance (probably the fastest ORM for Android); our benchmarks are open sourced too
  • Easy to use powerful APIs covering relations and joins
  • Minimal memory consumption
  • Small library size (<100KB) to keep your build times low and to avoid the 65k method limit
  • Database encryption: greenDAO supports SQLCipher to keep your user’s data safe
  • Strong community: More than 5.000 GitHub stars show there is a strong and active community
    -

GreenDao的特性或者说优势主要体现高性能、易用性、内存占用少、jar包小、安全性(加密)以及强大的社区(资料多)


5.3、Realm



The Realm Mobile Database is built from the ground up to run on mobile devices. Unlike a traditional database, objects in a Realm are native objects. You don’t have to copy objects out of the database, modify them, and save them back—you’re always working with the “live,” real object. If one thread or process modifies an object, other threads and processes can be immediately notified. Objects always stay in sync.

The Realm Mobile Database is open source (using the Apache license) and ==cross-platform==, with libraries available for Android, iOS, Xamarin (.NET), and React Native. Realms are fully interchangeable between platforms.

Realm是一个跨平台的开源库,这点很重要!!!


5.4、Sugar



Insanely easy way to work with Android databases.

Sugar ORM was built in contrast to other ORM’s to have:

  • A simple, concise, and clean integration process with minimal configuration.
  • Automatic table and column naming through reflection.
  • Support for migrations between different schema versions.
1
compile 'com.github.satyan:sugar:1.5'

ProGuard

1
2
# Ensures entities remain un-obfuscated so table and columns are named correctly
-keep class com.yourpackage.yourapp.domainclasspackage.** { *; }


5.5、ActiveAndroid



ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().

ActiveAndroid does so much more than this though. Accessing the database is a hassle, to say the least, in Android. ActiveAndroid takes care of all the setup and messy stuff, and all with just a few simple steps of configuration.

1
2
3
4
5
6
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'


6、文件下载



7、事件/消息库


7.1、EventBus



Android optimized event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

image

EventBus…

  • simplifies the communication between components
  1. decouples event senders and receivers
  2. performs well with Activities, Fragments, and background threads
  3. avoids complex and error-prone dependencies and life cycle issues
  • makes your code simpler
  • is fast
  • is tiny (~50k jar)
  • is proven in practice by apps with 100,000,000+ installs
    has advanced features like delivery threads, subscriber priorities, etc.
1
compile 'org.greenrobot:eventbus:3.0.0'


8、跨平台


8.1、React Native



中文教程


8.2、Weex



Weex 是一套简单易用的跨平台开发方案,能以 web 的开发体验构建高性能、可扩展的 native 应用,为了做到这些,Weex 与 Vue 合作,使用 Vue 作为上层框架,并遵循 W3C 标准实现了统一的 JSEngine 和 DOM API,这样一来,你甚至可以使用其他框架驱动 Weex,打造三端一致的 native 应用。

Weex 表面上是一个客户端技术,但实际上它串联起了从本地开发环境到云端部署和分发的整个链路。开发者首先可以在本地像撰写 web 页面一样撰写一个 app 的页面,然后编译成一段 JavaScript 代码,形成 Weex 的一个 JS bundle;在云端,开发者可以把生成的 JS bundle 部署上去,然后通过网络请求或预下发的方式传递到用户的移动应用客户端;在移动应用客户端里,WeexSDK 会准备好一个 JavaScript 引擎,并且在用户打开一个 Weex 页面时执行相应的 JS bundle,并在执行过程中产生各种命令发送到 native 端进行的界面渲染或数据存储、网络通信、调用设备功能、用户交互响应等移动应用的场景实践;同时,如果用户没有安装移动应用,他仍然可以在浏览器里打开一个相同的 web 页面,这个页面是使用相同的页面源代码,通过浏览器里的 JavaScript 引擎运行起来的。

image

官方教程


9、热修复

(先占坑…)


10、UI组件库


10.1、刷新组件


10.1.1、EasyRecyclerView



ArrayAdapter,pull to refresh,auto load more,Header/Footer,EmptyView,ProgressView,ErrorView

支持ArrayAdapter、下拉、自动加载、头部Header/尾部Footer、空数据view、进度View、错误View

image

1
compile 'com.jude:easyrecyclerview:4.4.0'


10.2、Dialog对话框


10.2.1、DialogPlus



image
image

1
compile 'com.orhanobut:dialogplus:1.11@aar'


10.3、图表库


10.3.1、MPAndroidChart



image


10.4、Banner


10.4.1、youth5201314/banner



image
image

1
2
3
4
5
6
7
compile 'com.youth.banner:banner:1.4.9' //最新版本
<!-- if you want to load images from the internet -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- if you want to load images from a file OR from the internet -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


10.5、Skin 换肤


10.5.1、Android-Skin-Loader



一个通过动态加载本地皮肤包进行换肤的皮肤框架


11、Utils工具库


11.1、AndroidUtilCode



1
compile 'com.blankj:utilcode:1.3.6'

How to use

Utils.init(context);

Proguard

1
2
3
-keep class com.blankj.utilcode.** { *; }
-keepclassmembers class com.blankj.utilcode.** { *; }
-dontwarn com.blankj.utilcode.**


11.2、Lazy



常用的工具类

1
compile 'com.github.lazylibrary:lazylibrary:1.0.2'


11.3、logger



Simple, pretty and powerful logger for android

Logger provides :

  • Thread information
  • Class information
  • Method information
  • Pretty-print for json content
  • Pretty-print for new line “\n”
  • Clean output
  • Jump to source
1
compile 'com.orhanobut:logger:1.15'


11.4、Toasty



image
image

1
2
3
4
5
6
7
8
9
10
11
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
...
compile 'com.github.GrenderG:Toasty:1.1.3'
}


11.5、StatusBarUtil



A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4).

image

1
compile 'com.jaeger.statusbaruitl:library:1.3.6'


11.6、Android-SplashView


11.7、LoadingLayout



简单实用的页面多状态布局(content,loading,empty,error)

image

1
2
3
4
5
6
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.czy1121:loadinglayout:1.0.1'
}


11.8、NineGridView



类似QQ空间,微信朋友圈,微博主页等,展示图片的九宫格控件,自动根据图片的数量确定图片大小和控件大小,使用Adapter模式设置图片,对外提供接口回调,支持任意的图片加载框架,如 Glide,ImageLoader,Fresco,xUtils3,Picasso 等,支持点击图片全屏预览大图。

image

1
compile 'com.lzy.widget:ninegridview:0.2.0'


12、开源 Android apps


12.1、open-source-android-apps


13、源码解析