├── app ├── .gitignore ├── build.gradle ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── wuxiaolong │ │ │ └── modularsample │ │ │ ├── AndroidApplication.java │ │ │ └── MainActivity.java │ │ ├── AndroidManifest.xml │ │ └── res │ │ └── layout │ │ └── app_activity_main.xml └── proguard-rules.pro ├── common ├── .gitignore ├── aars │ └── AndroidUtils1.0.7.aar ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── wuxiaolong │ │ │ └── common │ │ │ ├── activity │ │ │ ├── ButterKnifeActivity.java │ │ │ └── BaseActivity.java │ │ │ ├── retrofit │ │ │ ├── ApiStores.java │ │ │ ├── ApiCallback.java │ │ │ └── ApiClient.java │ │ │ └── model │ │ │ ├── UserModel.java │ │ │ └── WeatherModel.java │ │ └── res │ │ └── layout │ │ └── toolbar.xml ├── proguard-rules.pro └── build.gradle ├── router ├── .gitignore ├── src │ └── main │ │ ├── res │ │ └── values │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── wuxiaolong │ │ └── router │ │ ├── Module1Service.java │ │ ├── RouterConstants.java │ │ └── RouterUtils.java ├── build.gradle └── proguard-rules.pro ├── module1 ├── .gitignore ├── src │ └── main │ │ ├── release │ │ └── AndroidManifest.xml │ │ ├── res │ │ └── layout │ │ │ ├── module1_fragment_module1.xml │ │ │ └── module1_activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── wuxiaolong │ │ └── module1 │ │ ├── Module1ServiceImpl.java │ │ ├── Module1Fragment.java │ │ ├── debug │ │ └── Module1Application.java │ │ └── MainActivity.java ├── build.gradle └── proguard-rules.pro ├── module2 ├── .gitignore ├── src │ └── main │ │ ├── release │ │ └── AndroidManifest.xml │ │ ├── AndroidManifest.xml │ │ ├── res │ │ └── layout │ │ │ └── module2_activity_main.xml │ │ └── java │ │ └── com │ │ └── wuxiaolong │ │ └── module2 │ │ └── MainActivity.java ├── build.gradle └── proguard-rules.pro ├── resource ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ └── AndroidManifest.xml ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── versions.gradle ├── config.gradle ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /common/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /router/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /module1/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /module2/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /resource/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':module1', ':module2', ':common', ':resource', ':router' 2 | -------------------------------------------------------------------------------- /router/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | router 3 | 4 | -------------------------------------------------------------------------------- /common/aars/AndroidUtils1.0.7.aar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/common/aars/AndroidUtils1.0.7.aar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /resource/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: config 2 | 3 | dependencies { 4 | compile fileTree(dir: 'libs', include: ['*.jar']) 5 | compile project(':router') 6 | } 7 | -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /resource/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WuXiaolong/ModularSample/HEAD/resource/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | .idea -------------------------------------------------------------------------------- /router/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: config 2 | 3 | dependencies { 4 | compile fileTree(dir: 'libs', include: ['*.jar']) 5 | compile project(':common') 6 | //arouter 7 | compile arouterApi 8 | } 9 | -------------------------------------------------------------------------------- /resource/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Jul 23 12:26:27 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /router/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /resource/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /common/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /router/src/main/java/com/wuxiaolong/router/Module1Service.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.router; 2 | 3 | import com.alibaba.android.arouter.facade.template.IProvider; 4 | 5 | /** 6 | * Created by WuXiaolong on 2017/7/24. 7 | * 个人博客:http://wuxiaolong.me 8 | */ 9 | 10 | public interface Module1Service extends IProvider { 11 | boolean share(); 12 | } 13 | -------------------------------------------------------------------------------- /module2/src/main/release/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /module1/src/main/release/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /module1/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jakewharton.butterknife' 2 | apply from: config 3 | 4 | dependencies { 5 | compile fileTree(include: ['*.jar'], dir: 'libs') 6 | 7 | //arouter 8 | annotationProcessor arouterCompiler 9 | 10 | compile project(':resource') 11 | 12 | //dagger2 13 | annotationProcessor dagger2Compiler 14 | 15 | //butterknife 16 | annotationProcessor butterknifeCompiler 17 | } 18 | -------------------------------------------------------------------------------- /module2/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jakewharton.butterknife' 2 | apply from: config 3 | 4 | dependencies { 5 | compile fileTree(dir: 'libs', include: ['*.jar']) 6 | 7 | //arouter 8 | annotationProcessor arouterCompiler 9 | 10 | compile project(':resource') 11 | 12 | //dagger2 13 | annotationProcessor dagger2Compiler 14 | 15 | //butterknife 16 | annotationProcessor butterknifeCompiler 17 | } 18 | -------------------------------------------------------------------------------- /resource/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /module1/src/main/res/layout/module1_fragment_module1.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /resource/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ModularSample 3 | module2 4 | 城市: 5 | \n风向: 6 | \n风级: 7 | \n发布时间: 8 | module1 9 | 来自Module1Fragment 10 | app壳 11 | 跳转mudule2 12 | 13 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: config 2 | 3 | dependencies { 4 | compile fileTree(include: ['*.jar'], dir: 'libs') 5 | 6 | //arouter 7 | annotationProcessor arouterCompiler 8 | 9 | //butterknife 10 | annotationProcessor butterknifeCompiler 11 | 12 | //dagger2 13 | annotationProcessor dagger2Compiler 14 | 15 | if (isDebug.toBoolean()) { 16 | //当isDebug true,app得依赖基础库,保证app不报错 17 | compile project(':resource') 18 | } else { 19 | compile project(':module1') 20 | compile project(':module2') 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuxiaolong/common/activity/ButterKnifeActivity.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.common.activity; 2 | 3 | import android.support.annotation.LayoutRes; 4 | 5 | import butterknife.ButterKnife; 6 | import butterknife.Unbinder; 7 | 8 | public class ButterKnifeActivity extends BaseActivity { 9 | 10 | private Unbinder unbinder; 11 | 12 | 13 | @Override 14 | public void setContentView(@LayoutRes int layoutResID) { 15 | super.setContentView(layoutResID); 16 | unbinder = ButterKnife.bind(this); 17 | } 18 | 19 | @Override 20 | protected void onDestroy() { 21 | super.onDestroy(); 22 | unbinder.unbind(); 23 | }} 24 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuxiaolong/common/retrofit/ApiStores.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.common.retrofit; 2 | 3 | import com.wuxiaolong.common.model.WeatherModel; 4 | 5 | import retrofit2.http.GET; 6 | import retrofit2.http.Path; 7 | import rx.Observable; 8 | 9 | /** 10 | * Created by WuXiaolong on 2016/3/24. 11 | * github:https://github.com/WuXiaolong/ 12 | * 微信公众号:吴小龙同学 13 | * 个人博客:http://wuxiaolong.me/ 14 | */ 15 | public interface ApiStores { 16 | //baseUrl 17 | String API_SERVER_URL = "http://www.weather.com.cn/"; 18 | 19 | 20 | //加载天气 21 | @GET("adat/sk/{cityId}.html") 22 | Observable loadWeatherData(@Path("cityId") String cityId); 23 | } 24 | -------------------------------------------------------------------------------- /router/src/main/java/com/wuxiaolong/router/RouterConstants.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.router; 2 | 3 | /** 4 | * Created by WuXiaolong on 2017/7/24. 5 | * 个人博客:http://wuxiaolong.me 6 | */ 7 | 8 | public final class RouterConstants { 9 | 10 | /** 11 | * module1 12 | */ 13 | public static final String MODULE1_MAIN_ACTIVITY = "/module1/MainActivity"; 14 | public static final String MODULE1_SERVICE_IMPL = "/module1/Module1ServiceImpl"; 15 | public static final String MODULE1_MODULE1_FRAGMENT = "/module1/Module1Fragment"; 16 | 17 | /** 18 | * module2 19 | */ 20 | public static final String MODULE2_MAIN_ACTIVITY = "/module2/MainActivity"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuxiaolong/common/model/UserModel.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.common.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by WuXiaolong on 2017/7/24. 7 | * 个人博客:http://wuxiaolong.me 8 | */ 9 | 10 | public class UserModel implements Serializable{ 11 | private String name; 12 | private String message; 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getMessage() { 23 | return message; 24 | } 25 | 26 | public void setMessage(String message) { 27 | this.message = message; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /module1/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /router/src/main/java/com/wuxiaolong/router/RouterUtils.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.router; 2 | 3 | import com.alibaba.android.arouter.launcher.ARouter; 4 | 5 | /** 6 | * Created by WuXiaolong on 2017/7/31. 7 | * 个人博客:http://wuxiaolong.me 8 | */ 9 | 10 | public class RouterUtils { 11 | public static Object navigation(String path) { 12 | // 构建标准的路由请求 13 | return ARouter.getInstance().build(path).navigation(); 14 | } 15 | public void startActivityForResult() { 16 | // 构建标准的路由请求,startActivityForResult 17 | // navigation的第一个参数必须是Activity,第二个参数则是RequestCode 18 | // ARouter.getInstance().build("/home/main").navigation(this, 5); 19 | 20 | } 21 | 22 | public void startActivityForCallback() { 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /module2/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /module1/src/main/java/com/wuxiaolong/module1/Module1ServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.module1; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import com.alibaba.android.arouter.facade.annotation.Route; 7 | import com.wuxiaolong.router.Module1Service; 8 | import com.wuxiaolong.router.RouterConstants; 9 | 10 | /** 11 | * Created by WuXiaolong on 2017/7/24. 12 | * 个人博客:http://wuxiaolong.me 13 | */ 14 | @Route(path = RouterConstants.MODULE1_SERVICE_IMPL) 15 | public class Module1ServiceImpl implements Module1Service { 16 | @Override 17 | public boolean share() { 18 | Log.d("wxl","share"); 19 | return true; 20 | } 21 | 22 | @Override 23 | public void init(Context context) { 24 | Log.d("wxl","init="+context); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/wuxiaolong/modularsample/AndroidApplication.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.modularsample; 2 | 3 | import android.app.Application; 4 | 5 | import com.alibaba.android.arouter.launcher.ARouter; 6 | 7 | /** 8 | * Created by WuXiaolong on 2017/7/24. 9 | * 个人博客:http://wuxiaolong.me 10 | */ 11 | public class AndroidApplication extends Application { 12 | @Override 13 | public void onCreate() { 14 | super.onCreate(); 15 | if (BuildConfig.DEBUG) { 16 | // 这两行必须写在init之前,否则这些配置在init过程中将无效 17 | ARouter.openLog(); // 打印日志 18 | ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) 19 | ARouter.printStackTrace(); // 打印日志的时候打印线程堆栈 20 | } 21 | ARouter.init(this); // 尽可能早,推荐在Application中初始化 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # 效果预览 3 | ![](http://7q5c2h.com1.z0.glb.clouddn.com/ModularSample.gif?watermark/2/text/5ZC05bCP6b6Z5ZCM5a24/font/5qW35L2T/fontsize/500/fill/I0VGRUZFRg==/dissolve/100/gravity/SouthEast/dx/10/dy/10) 4 | 5 | # 详情介绍 6 | [Android 组件化探索与思考](http://wuxiaolong.me/2017/08/01/ModularExploree/),来自我的博客,推荐 7 | 8 | [Android 组件化探索与思考](http://mp.weixin.qq.com/s/RGmzjIM4y7Yxz723Vp8uzA),来自我的公众号 9 | 10 | 11 | # 微信公众号 12 | ![](http://7q5c2h.com1.z0.glb.clouddn.com/qrcode_WuXiaolong1.JPG) 13 | 14 | # 赞赏作者 15 | ![](http://7q5c2h.com1.z0.glb.clouddn.com/wechatpay.JPG) 16 | 17 | # 更新记录 18 | * v0.03 19 | 1. 统一管理了build.gradle文件 20 | 2. 现在只要是'module'开头的module,都可以使用同一份build.gradle,配置参见'rootDir/config.gradle' 21 | 22 | * v0.02 23 | 24 | 1. 新增 resource,存放项目的所有资源,从 common 分出来 25 | 26 | 2. 新增 router,路由,所有页面请求都由它中转 27 | 28 | * v0.01 29 | 30 | 1. 组件化初步形成 31 | -------------------------------------------------------------------------------- /common/src/main/res/layout/toolbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | 19 | # 组件单独调试开关,true 可以,false 不可以 20 | isDebug=false -------------------------------------------------------------------------------- /module1/src/main/java/com/wuxiaolong/module1/Module1Fragment.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.module1; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.alibaba.android.arouter.facade.annotation.Route; 11 | import com.wuxiaolong.router.RouterConstants; 12 | 13 | 14 | @Route(path = RouterConstants.MODULE1_MODULE1_FRAGMENT) 15 | public class Module1Fragment extends Fragment { 16 | 17 | 18 | @Override 19 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 20 | Bundle savedInstanceState) { 21 | // Inflate the layout for this fragment 22 | return inflater.inflate(R.layout.module1_fragment_module1, container, false); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /module1/src/main/java/com/wuxiaolong/module1/debug/Module1Application.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.module1.debug; 2 | 3 | import android.app.Application; 4 | 5 | import com.alibaba.android.arouter.launcher.ARouter; 6 | import com.wuxiaolong.module1.BuildConfig; 7 | 8 | /** 9 | * Created by WuXiaolong on 2017/8/1. 10 | * 个人博客:http://wuxiaolong.me 11 | */ 12 | 13 | public class Module1Application extends Application { 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | if (BuildConfig.DEBUG) { 18 | // 这两行必须写在init之前,否则这些配置在init过程中将无效 19 | ARouter.openLog(); // 打印日志 20 | ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) 21 | ARouter.printStackTrace(); // 打印日志的时候打印线程堆栈 22 | } 23 | ARouter.init(this); // 尽可能早,推荐在Application中初始化 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wuxiaolong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /common/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wuxiaolong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /module1/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wuxiaolong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /module2/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wuxiaolong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /resource/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wuxiaolong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /router/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/wuxiaolong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /versions.gradle: -------------------------------------------------------------------------------- 1 | ext{ 2 | androidSupportVersion = '25.3.1' 3 | butterknifeVersion = '8.7.0' 4 | 5 | 6 | compile_sdk_version = 25 7 | build_tools_version = "26.0.0" 8 | 9 | min_sdk_version = 14 //兼容的最低 SDK 版本 10 | target_sdk_version = 22 //向前兼容,保存新旧两种逻辑,并通过 if-else 方法来判断执行哪种逻辑 11 | 12 | version_code = 3 13 | version_name = "0.03" 14 | 15 | appcompatV7 = "com.android.support:appcompat-v7:$androidSupportVersion" 16 | constraintLayout = 'com.android.support.constraint:constraint-layout:1.0.2' 17 | 18 | //arouter 19 | arouterApi = 'com.alibaba:arouter-api:1.2.1.1' 20 | arouterCompiler = 'com.alibaba:arouter-compiler:1.1.2.1' 21 | alibabaFastjson = 'com.alibaba:fastjson:1.2.9' 22 | 23 | //dagger2 24 | dagger2 = 'com.google.dagger:dagger:2.11' 25 | dagger2Compiler = 'com.google.dagger:dagger-compiler:2.11' 26 | 27 | //butterknife 28 | butterknife = "com.jakewharton:butterknife:$butterknifeVersion" 29 | butterknifeCompiler = "com.jakewharton:butterknife-compiler:$butterknifeVersion" 30 | } -------------------------------------------------------------------------------- /common/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: config 2 | 3 | repositories { 4 | flatDir { 5 | dirs 'aars' 6 | } 7 | } 8 | dependencies { 9 | compile fileTree(dir: 'libs', include: ['*.jar']) 10 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 11 | exclude group: 'com.android.support', module: 'support-annotations' 12 | }) 13 | //testCompile 'junit:junit:4.12' 14 | compile appcompatV7 15 | compile constraintLayout 16 | //compile 'com.wuxiaolong.androidutils:androidutils:1.0.6' 17 | // compile(name:'AndroidUtils1.0.7', ext:'aar') 18 | 19 | //butterknife 20 | compile butterknife 21 | 22 | //dagger 23 | compile dagger2 24 | 25 | //pullloadmorerecyclerview 26 | compile 'com.wuxiaolong.pullloadmorerecyclerview:library:1.1.2' 27 | 28 | //retrofit 29 | compile 'com.squareup.retrofit2:retrofit:2.0.2' 30 | compile 'com.squareup.okhttp3:logging-interceptor:3.1.2' 31 | compile 'com.squareup.retrofit2:converter-gson:2.0.2' 32 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 33 | 34 | //rxjava 35 | compile 'io.reactivex:rxandroid:1.1.0' 36 | compile 'io.reactivex:rxjava:1.1.0' 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuxiaolong/common/retrofit/ApiCallback.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.common.retrofit; 2 | 3 | 4 | 5 | import retrofit2.adapter.rxjava.HttpException; 6 | import rx.Subscriber; 7 | 8 | /** 9 | * Created by WuXiaolong on 2016/9/22. 10 | * github:https://github.com/WuXiaolong/ 11 | * 微信公众号:吴小龙同学 12 | * 个人博客:http://wuxiaolong.me/ 13 | */ 14 | public abstract class ApiCallback extends Subscriber { 15 | 16 | public abstract void onSuccess(M model); 17 | 18 | public abstract void onFailure(String msg); 19 | 20 | public abstract void onFinish(); 21 | 22 | 23 | @Override 24 | public void onError(Throwable e) { 25 | e.printStackTrace(); 26 | if (e instanceof HttpException) { 27 | HttpException httpException = (HttpException) e; 28 | //httpException.response().errorBody().string() 29 | int code = httpException.code(); 30 | String msg = httpException.getMessage(); 31 | if (code == 504) { 32 | msg = "网络不给力"; 33 | } 34 | if (code == 502 || code == 404) { 35 | msg = "服务器异常,请稍后再试"; 36 | } 37 | onFailure(msg); 38 | } else { 39 | onFailure(e.getMessage()); 40 | } 41 | onFinish(); 42 | } 43 | 44 | @Override 45 | public void onNext(M model) { 46 | onSuccess(model); 47 | 48 | } 49 | 50 | @Override 51 | public void onCompleted() { 52 | onFinish(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /common/src/main/java/com/wuxiaolong/common/retrofit/ApiClient.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.common.retrofit; 2 | 3 | 4 | import com.wuxiaolong.common.BuildConfig; 5 | 6 | import okhttp3.OkHttpClient; 7 | import okhttp3.logging.HttpLoggingInterceptor; 8 | import retrofit2.Retrofit; 9 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 10 | import retrofit2.converter.gson.GsonConverterFactory; 11 | 12 | /** 13 | * Created by WuXiaolong on 2016/3/24. 14 | * github:https://github.com/WuXiaolong/ 15 | * 微信公众号:吴小龙同学 16 | * 个人博客:http://wuxiaolong.me/ 17 | */ 18 | public class ApiClient { 19 | public static Retrofit mRetrofit; 20 | 21 | public static Retrofit retrofit() { 22 | if (mRetrofit == null) { 23 | OkHttpClient.Builder builder = new OkHttpClient.Builder(); 24 | 25 | 26 | if (BuildConfig.DEBUG) { 27 | // Log信息拦截器 28 | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); 29 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 30 | //设置 Debug Log 模式 31 | builder.addInterceptor(loggingInterceptor); 32 | } 33 | OkHttpClient okHttpClient = builder.build(); 34 | mRetrofit = new Retrofit.Builder() 35 | .baseUrl(ApiStores.API_SERVER_URL) 36 | .addConverterFactory(GsonConverterFactory.create()) 37 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 38 | .client(okHttpClient) 39 | .build(); 40 | } 41 | return mRetrofit; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /module1/src/main/java/com/wuxiaolong/module1/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wuxiaolong.module1; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import android.widget.TextView; 6 | 7 | import com.alibaba.android.arouter.facade.annotation.Route; 8 | import com.wuxiaolong.common.activity.BaseActivity; 9 | import com.wuxiaolong.common.model.UserModel; 10 | import com.wuxiaolong.router.RouterConstants; 11 | import com.wuxiaolong.router.RouterUtils; 12 | 13 | import butterknife.BindView; 14 | import butterknife.OnClick; 15 | 16 | @Route(path = RouterConstants.MODULE1_MAIN_ACTIVITY) 17 | public class MainActivity extends BaseActivity { 18 | 19 | 20 | @BindView(R2.id.module1_text) 21 | TextView module1Text; 22 | 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.module1_activity_main); 28 | initToolBar(getString(R.string.module1)); 29 | 30 | if (this.getIntent() != null) { 31 | UserModel userModel = (UserModel) this.getIntent().getSerializableExtra("obj"); 32 | if (userModel != null) 33 | module1Text.setText("带参数:"+userModel.getName() + "," + userModel.getMessage()); 34 | } 35 | } 36 | 37 | /** 38 | * click方法中同样使用R2,但是找id的时候使用R, 39 | * ibrary中是不能使用 switch- case 找id的,原因:http://www.jianshu.com/p/89687f618837 40 | */ 41 | @OnClick({R2.id.module1_button}) 42 | public void onViewClicked(View view) { 43 | int id = view.getId(); 44 | if (id == R.id.module1_button) { 45 | RouterUtils.navigation(RouterConstants.MODULE2_MAIN_ACTIVITY); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /module2/src/main/res/layout/module2_activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 |