├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dhht │ │ └── module_api │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── dhht │ │ │ └── module_api │ │ │ ├── Application.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── 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 │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── dhht │ └── module_api │ └── ExampleUnitTest.java ├── baselibrary ├── .gitignore ├── api.gradle ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── dhht │ │ └── commonlibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ └── res │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── 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 │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── dhht │ └── commonlibrary │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── other-api ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── dhht │ └── other │ └── Other.java ├── other ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── dhht │ │ └── other │ │ ├── MainActivity.java │ │ └── Other.api │ └── res │ ├── layout │ └── other_activity_main.xml │ └── values │ └── strings.xml ├── settings.gradle ├── user-api ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── dhht │ └── user │ ├── UserInfo.java │ └── UserService.java └── user ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── com │ └── dhht │ └── user │ ├── UserInfo.api │ ├── UserService.api │ └── UserServiceImpl.java └── res └── values └── strings.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### macOS template 3 | # General 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must end with two \r 9 | Icon 10 | 11 | # Thumbnails 12 | ._* 13 | 14 | # Files that might appear in the root of a volume 15 | .DocumentRevisions-V100 16 | .fseventsd 17 | .Spotlight-V100 18 | .TemporaryItems 19 | .Trashes 20 | .VolumeIcon.icns 21 | .com.apple.timemachine.donotpresent 22 | 23 | # Directories potentially created on remote AFP share 24 | .AppleDB 25 | .AppleDesktop 26 | Network Trash Folder 27 | Temporary Items 28 | .apdisk 29 | ### Android template 30 | # Built application files 31 | *.apk 32 | *.ap_ 33 | 34 | # Files for the ART/Dalvik VM 35 | *.dex 36 | 37 | # Java class files 38 | *.class 39 | 40 | # Generated files 41 | bin/ 42 | gen/ 43 | out/ 44 | 45 | # Gradle files 46 | .gradle/ 47 | build/ 48 | 49 | # Local configuration file (sdk path, etc) 50 | local.properties 51 | 52 | # Proguard folder generated by Eclipse 53 | proguard/ 54 | 55 | # Log Files 56 | *.log 57 | 58 | # Android Studio Navigation editor temp files 59 | .navigation/ 60 | 61 | # Android Studio captures folder 62 | captures/ 63 | 64 | # IntelliJ 65 | *.iml 66 | .idea/workspace.xml 67 | .idea/tasks.xml 68 | .idea/gradle.xml 69 | .idea/assetWizardSettings.xml 70 | .idea/dictionaries 71 | .idea/libraries 72 | .idea/caches 73 | 74 | .idea/libraries/ 75 | .idea/.name 76 | .idea/compiler.xml 77 | .idea/copyright/profiles_settings.xml 78 | .idea/encodings.xml 79 | .idea/misc.xml 80 | .idea/modules.xml 81 | .idea/scopes/scope_settings.xml 82 | .idea/vcs.xml 83 | .classpath 84 | .project 85 | 86 | .idea 87 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 88 | .gradle 89 | 90 | # Keystore files 91 | # Uncomment the following line if you do not want to check your keystore files in. 92 | #*.jks 93 | 94 | # External native build folder generated in Android Studio 2.2 and later 95 | .externalNativeBuild 96 | 97 | # Google Services (e.g. APIs or Firebase) 98 | google-services.json 99 | 100 | # Freeline 101 | freeline.py 102 | freeline/ 103 | freeline_project_description.json 104 | 105 | # fastlane 106 | fastlane/report.xml 107 | fastlane/Preview.html 108 | fastlane/screenshots 109 | fastlane/test_output 110 | fastlane/readme.md 111 | 112 | .idea/fileTemplates/ 113 | fingersm2blibrary/src/androidTest/java/ 114 | fingersm2blibrary/src/main/java/com/example/fingersm2blibrary/ 115 | fingersm2blibrary/src/main/res/ 116 | fingersm2blibrary/src/test/ 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # module_api 2 | ## gradle实现Android组件化开发模块api化 3 | 4 | 最近看了[微信Android模块化架构重构实践](https://mp.weixin.qq.com/s/6Q818XA5FaHd7jJMFBG60w)这篇文章,刚好自己又正在搭建新项目的框架,用到组件化开发;感觉文章里面的一些技巧很有用,就跟着实现了一下,写一下自己的看法 5 | 6 | ### 模块间的交互 7 | 首先是解决模块之前的依赖问题,模块间肯定是不能相互依赖的,那如何进行数据交互就是一个问题了;比如用户模块和其他模块,其他模块如何在不依赖用户模块的情况下获取到用户信息; 8 | 9 | 10 | #### 使用EventBus 11 | 想要获取用户信息,那User类肯定是要引用的,肯定是要提取出User类放到公共模块里面,然后获取User可以通过EventBus来获取数据 12 | 13 | 公共模块将EventBus发送的Event定义为接口 14 | ```java 15 | public interface UserCallback { 16 | 17 | /** 18 | * 获取用户数据 19 | * 20 | * @param user 21 | */ 22 | void getUser(User user); 23 | } 24 | ``` 25 | 然后在用户模块订阅事件,返回用户信息 26 | ```java 27 | @Subscribe 28 | public void getUser(UserCallback callback){ 29 | callback.getUser(new com.dhht.baselibrary.User()); 30 | } 31 | ``` 32 | 在其他模块就可以通过EventBus来发送事件获取到用户信息 33 | ```java 34 | EventBus.getDefault().post(new UserCallback() { 35 | @Override 36 | public void getUser(User user) { 37 | mUser = user; 38 | } 39 | }); 40 | ``` 41 | 但是讲道理EventBus还是少用的好,业务多了会生成很多Event类,感觉是有点难受的,而且代码阅读起来非常难; 42 | 43 | #### SPI机制 44 | SPI全称Service Provider Interface,是Java提供的一套用来被第三方实现或者扩展的API,它可以用来启用框架扩展和替换组件。 45 | 46 | 整体机制图如下: 47 | 48 | ![image](http://upload-images.jianshu.io/upload_images/4906791-317d275c4d2260ae.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 49 | 50 | 51 | ##### 具体的实现(可以略过) 52 | 首先也是把User放在公共模块里面,获取用户信息的接口也放在公共模块里面 53 | ```java 54 | package com.dhht.baselibrary; 55 | public interface UserService { 56 | /** 57 | * 获取user 58 | * 59 | * @return 60 | */ 61 | User getUser(); 62 | } 63 | 64 | ``` 65 | 然后在用户模块里面实现接口 66 | ```java 67 | package com.dhht.user; 68 | 69 | public class UserImpl implements UserService { 70 | @Override 71 | public User getUser() { 72 | return new User("UserImpl"); 73 | } 74 | } 75 | ``` 76 | 77 | 需要在`user/src/main/resources/META-INF.services/`目录下面新建文件名为`com.dhht.baselibrary.UserService`的文件,文件内容就是实现类的路径 78 | ```java 79 | com.dhht.user.UserImpl 80 | ``` 81 | 82 | 这个时候再其他模块使用这个实现类就可以通过SPI机制来获取 83 | ```java 84 | ServiceLoader userServices = ServiceLoader.load(UserService.class); 85 | Iterator iterator = userServices.iterator(); 86 | while (iterator.hasNext()) { 87 | UserService userService = iterator.next(); 88 | ToastUtil.showShort(userService.getUser().getName()); 89 | } 90 | ``` 91 | 92 | #### ARouter 93 | 上面的过程稍微有点复杂,也没必要去实现,这个是一种思想,很多路由框架都是借助了这种思想,而且使用非常方便,比如阿里的ARouter框架;用户类不变,接口需要实现**IProvider**接口 94 | 95 | ```java 96 | public interface UserService extends IProvider { 97 | UserInfo getUser(); 98 | } 99 | ``` 100 | 101 | 然后在用户模块实现接口,并且添加`@Route`注解 102 | ```java 103 | @Route(path = "/user/UserService") 104 | public class UserServiceImpl implements UserService { 105 | @Override 106 | public UserInfo getUser() { 107 | return new UserInfo("Tyhj"); 108 | } 109 | 110 | @Override 111 | public void init(Context context) { 112 | 113 | } 114 | } 115 | ``` 116 | 然后在其他模块通过ARouter注解获取实例 117 | ```java 118 | @Autowired//(name = "/user/UserService") 119 | UserService mUserService; 120 | 121 | @Override 122 | protected void onCreate(Bundle savedInstanceState) { 123 | super.onCreate(savedInstanceState); 124 | ARouter.getInstance().inject(this); 125 | ... 126 | ``` 127 | 方法比较简单,相对于正常的代码只是添加了一个注解而已,ARouter的最新版本如下,每个模块都需要添加注解插件(第二行),库(第一行)只需要在公共模块添加就好了; 128 | ``` 129 | //arouter 130 | api 'com.alibaba:arouter-api:1.4.1' 131 | annotationProcessor 'com.alibaba:arouter-compiler:1.2.2' 132 | ``` 133 | 134 | 使用ARouter还需要在每个模块的build.gradle的defaultConfig节点下添加如下代码 135 | 136 | ```java 137 | javaCompileOptions { 138 | annotationProcessorOptions { 139 | arguments = [AROUTER_MODULE_NAME: project.getName()] 140 | } 141 | } 142 | ``` 143 | 144 | #### 提取出api模块 145 | 如果每次有一个模块要使用另一个模块的接口都把接口和相关文件放到公共模块里面,那么公共模块会越来越大,而且每个模块都依赖了公共模块,都依赖了一大堆可能不需要的东西; 146 | 147 | 所以我们可以提取出每个模块提供api的文件放到各种单独的模块里面;比如user模块,我们把公共模块里面的User和UserInfoService放到新的user-api模块里面,这样其他模块使用的时候可以单独依赖于这个专门提供接口的模块,以此解决公共模块膨胀的问题 148 | 149 | #### 自动生成Library 150 | 为了写代码方便,我们可以在写代码的时候,每个模块的东西都写在一起,比如User提供的接口我们也正常写在用户模块里面,在编译的时候,再使用gradle来自动生成各个api模块,这样会方便很多 151 | 152 | 153 | 原理是这样的,我们把需要单独生成api模块的.java文件改为另一种文件类型比如把UserInfo.java改为UserInfo.api,在设置/Editor/File Type中找到Java类型,添加*.api,然后就可以和Java文件一样使用了; 154 | 155 | 在项目的setting.gradle文件里面添加方法`includeWithApi("module名字")`,用这个方法来代替`include ":module名字"`,这个方法会从这个module里面找到以.api结尾的文件,复制到新的module里面并重命名,当然也会复制`gradle`文件和`AndroidManifest`文件,以此生成新的api模块 156 | 157 | ##### 具体实现 158 | setting.gradle文件的实现 159 | ```java 160 | def includeWithApi(String moduleName) { 161 | //先正常加载这个模块 162 | include(moduleName) 163 | //找到这个模块的路径 164 | String originDir = project(moduleName).projectDir 165 | //这个是新的路径 166 | String targetDir = "${originDir}-api" 167 | //原模块的名字 168 | String originName=project(moduleName).name; 169 | //新模块的名字 170 | def sdkName = "${originName}-api" 171 | 172 | //todo 替换成自己的公共模块,或者预先放api.gradle的模块 173 | //这个是公共模块的位置,我预先放了一个 新建的api.gradle 文件进去 174 | String apiGradle = project(":baselibrary").projectDir 175 | 176 | // 每次编译删除之前的文件 177 | deleteDir(targetDir) 178 | 179 | //复制.api文件到新的路径 180 | copy() { 181 | from originDir 182 | into targetDir 183 | exclude '**/build/' 184 | exclude '**/res/' 185 | include '**/*.api' 186 | } 187 | 188 | 189 | //直接复制公共模块的AndroidManifest文件到新的路径,作为该模块的文件 190 | copy() { 191 | from "${apiGradle}/src/main/AndroidManifest.xml" 192 | into "${targetDir}/src/main/" 193 | } 194 | 195 | //复制 gradle文件到新的路径,作为该模块的gradle 196 | copy() { 197 | from "${apiGradle}/api.gradle" 198 | into "${targetDir}/" 199 | } 200 | 201 | //删除空文件夹 202 | deleteEmptyDir(new File(targetDir)) 203 | 204 | 205 | //todo 替换成自己的包名,这里是 com/dhht/ 206 | //为AndroidManifest新建路径,路径就是在原来的包下面新建一个api包,作为AndroidManifest里面的包名 207 | String packagePath = "${targetDir}/src/main/java/com/dhht/${originName}/api"; 208 | 209 | 210 | //todo 替换成自己的包名,这里是baselibrary模块拷贝的AndroidManifest,替换里面的包名 211 | //修改AndroidManifest文件包路径 212 | fileReader("${targetDir}/src/main/AndroidManifest.xml", "commonlibrary","${originName}.api"); 213 | 214 | new File(packagePath).mkdirs() 215 | 216 | //重命名一下gradle 217 | def build = new File(targetDir + "/api.gradle") 218 | if (build.exists()) { 219 | build.renameTo(new File(targetDir + "/build.gradle")) 220 | } 221 | 222 | // 重命名.api文件,生成正常的.java文件 223 | renameApiFiles(targetDir, '.api', '.java') 224 | 225 | //正常加载新的模块 226 | include ":$sdkName" 227 | } 228 | 229 | private void deleteEmptyDir(File dir) { 230 | if (dir.isDirectory()) { 231 | File[] fs = dir.listFiles(); 232 | if (fs != null && fs.length > 0) { 233 | for (int i = 0; i < fs.length; i++) { 234 | File tmpFile = fs[i]; 235 | if (tmpFile.isDirectory()) { 236 | deleteEmptyDir(tmpFile); 237 | } 238 | if (tmpFile.isDirectory() && tmpFile.listFiles().length <= 0) { 239 | tmpFile.delete(); 240 | } 241 | } 242 | } 243 | if (dir.isDirectory() && dir.listFiles().length == 0) { 244 | dir.delete(); 245 | } 246 | } 247 | } 248 | 249 | private void deleteDir(String targetDir) { 250 | FileTree targetFiles = fileTree(targetDir) 251 | targetFiles.exclude "*.iml" 252 | targetFiles.each { File file -> 253 | file.delete() 254 | } 255 | } 256 | 257 | /** 258 | * rename api files(java, kotlin...) 259 | */ 260 | private def renameApiFiles(root_dir, String suffix, String replace) { 261 | FileTree files = fileTree(root_dir).include("**/*$suffix") 262 | files.each { 263 | File file -> 264 | file.renameTo(new File(file.absolutePath.replace(suffix, replace))) 265 | } 266 | } 267 | 268 | //替换AndroidManifest里面的字段 269 | def fileReader(path, name,sdkName) { 270 | def readerString = ""; 271 | def hasReplace = false 272 | 273 | file(path).withReader('UTF-8') { reader -> 274 | reader.eachLine { 275 | if (it.find(name)) { 276 | it = it.replace(name, sdkName) 277 | hasReplace = true 278 | } 279 | readerString <<= it 280 | readerString << '\n' 281 | } 282 | 283 | if (hasReplace) { 284 | file(path).withWriter('UTF-8') { 285 | within -> 286 | within.append(readerString) 287 | } 288 | } 289 | return readerString 290 | } 291 | } 292 | 293 | 294 | include ':app', ':baselibrary' 295 | includeWithApi ":user" 296 | includeWithApi ":other" 297 | 298 | ``` 299 | 300 | 其实讲的还是比较清楚了,我首先复制.api文件去生成Java文件,想要生成新的api模块,得有`gradle`和`AndroidManifest`文件才行,而这个api模块显然不需要过多的配置,于是我自己先生成一个简单的`gradle`文件,就是其他模块复制过来的,基础配置而已,然后复制到新的api模块搞定,对于AndroidManifest文件,基础模块肯定是没有什么配置的,复制过来使用完事儿; 301 | 302 | 303 | ### AndroidManifest路径问题 304 | 下面这个demo是随便写的,不是按照组件化来写的,只是简单展示一下这个脚本的作用而已,[组件化框架搭建点这里](https://blog.csdn.net/guiying712/article/details/55213884),第一个版本写完后能运行没发现问题,但是有位兄弟发现build的时候居然失败了,报错如下: 305 | ```java 306 | AGPBI: {"kind":"error","text":"Program type already present: com.dhht.commonlibrary.BuildConfig","sources":[{}],"tool":"D8"} 307 | ``` 308 | 这个错误很常见,意思就是`com.dhht.commonlibrary.BuildConfig`这个文件重复了,明显是因为我直接拷贝**AndroidManifest**文件,里面的包名没有修改导致的 309 | ```java 310 | 312 | ``` 313 | 314 | 发现只要将`minSdkVersion`设置为`21`就可以避免这个问题 315 | ```java 316 | defaultConfig { 317 | minSdkVersion 21 318 | ... 319 | ``` 320 | 但是后来打包签名apk的又报错了,那其实我们随便设置不同的包名就可以了,但是包名不能设置不存在的路径,所以在新的模块的原包下新建一个api文件夹,然后在复制过来的**AndroidManifest**里面修改包名,也不用把`minSdkVersion`设置为21,当然都是脚本完成 321 | ```java 322 | 324 | ``` 325 | 326 | 我这里创建的是Android Library,其实创建Java Library也是一样的,只是我感觉Android Library更好一点;可能感觉稍微有点复杂,其实只需要编写一个通用的setting.gradle文件然后改改.java文件名而已,这个也是微信重构的一个技巧,我觉得还是挺好的 327 | 328 | 329 | > 项目地址:https://github.com/tyhjh/module_api 330 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.dhht.module_api" 7 | minSdkVersion 14 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | 13 | javaCompileOptions { 14 | annotationProcessorOptions { 15 | arguments = [AROUTER_MODULE_NAME: project.getName()] 16 | } 17 | } 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | implementation 'com.android.support:appcompat-v7:28.0.0' 30 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | 35 | implementation project(":user") 36 | annotationProcessor 'com.alibaba:arouter-compiler:1.2.2' 37 | implementation project(':baselibrary') 38 | implementation project(":other") 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/dhht/module_api/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.dhht.module_api; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.dhht.module_api", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/dhht/module_api/Application.java: -------------------------------------------------------------------------------- 1 | package com.dhht.module_api; 2 | 3 | import com.alibaba.android.arouter.launcher.ARouter; 4 | 5 | /** 6 | * @author HanPei 7 | * @date 2019/4/4 下午1:47 8 | */ 9 | public class Application extends android.app.Application { 10 | 11 | boolean isDebug = true; 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | initARouter(); 17 | 18 | } 19 | 20 | 21 | /** 22 | * 初始化阿里路由 23 | */ 24 | private void initARouter() { 25 | if (isDebug) { 26 | ARouter.openLog(); 27 | ARouter.openDebug(); 28 | } 29 | ARouter.init(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/dhht/module_api/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dhht.module_api; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | 6 | import com.alibaba.android.arouter.launcher.ARouter; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.other_activity_main); 16 | ARouter.getInstance().build("/other/MainActivity").navigation(); 17 | } 18 | 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Module_Api 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/dhht/module_api/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.dhht.module_api; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /baselibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /baselibrary/api.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | javaCompileOptions { 17 | annotationProcessorOptions { 18 | arguments = [AROUTER_MODULE_NAME: project.getName()] 19 | } 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | sourceSets { 31 | main { 32 | manifest.srcFile 'src/main/AndroidManifest.xml' 33 | } 34 | } 35 | 36 | } 37 | 38 | dependencies { 39 | implementation fileTree(dir: 'libs', include: ['*.jar']) 40 | 41 | implementation 'com.android.support:appcompat-v7:28.0.0' 42 | testImplementation 'junit:junit:4.12' 43 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 45 | 46 | annotationProcessor 'com.alibaba:arouter-compiler:1.2.2' 47 | implementation project(":baselibrary") 48 | } 49 | -------------------------------------------------------------------------------- /baselibrary/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | javaCompileOptions { 17 | annotationProcessorOptions { 18 | arguments = [AROUTER_MODULE_NAME: project.getName()] 19 | } 20 | } 21 | 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | 36 | implementation 'com.android.support:appcompat-v7:28.0.0' 37 | testImplementation 'junit:junit:4.12' 38 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 40 | 41 | api 'com.alibaba:arouter-api:1.4.1' 42 | annotationProcessor 'com.alibaba:arouter-compiler:1.2.2' 43 | } 44 | -------------------------------------------------------------------------------- /baselibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /baselibrary/src/androidTest/java/com/dhht/commonlibrary/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.dhht.commonlibrary; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.dhht.commonlibrary.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /baselibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/baselibrary/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /baselibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | commonlibrary 3 | 4 | -------------------------------------------------------------------------------- /baselibrary/src/test/java/com/dhht/commonlibrary/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.dhht.commonlibrary; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.0' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tyhjh/module_api/85c46fc81e1ddf5bc96f051478b4ef5934237632/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /other-api/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | javaCompileOptions { 17 | annotationProcessorOptions { 18 | arguments = [AROUTER_MODULE_NAME: project.getName()] 19 | } 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | sourceSets { 31 | main { 32 | manifest.srcFile 'src/main/AndroidManifest.xml' 33 | } 34 | } 35 | 36 | } 37 | 38 | dependencies { 39 | implementation fileTree(dir: 'libs', include: ['*.jar']) 40 | 41 | implementation 'com.android.support:appcompat-v7:28.0.0' 42 | testImplementation 'junit:junit:4.12' 43 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 45 | 46 | annotationProcessor 'com.alibaba:arouter-compiler:1.2.2' 47 | implementation project(":baselibrary") 48 | } 49 | -------------------------------------------------------------------------------- /other-api/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /other-api/src/main/java/com/dhht/other/Other.java: -------------------------------------------------------------------------------- 1 | package com.dhht.other; 2 | 3 | /** 4 | * @author HanPei 5 | * @date 2019/4/23 下午2:43 6 | */ 7 | public class Other { 8 | String name; 9 | int id; 10 | } 11 | -------------------------------------------------------------------------------- /other/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /other/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | javaCompileOptions { 17 | annotationProcessorOptions { 18 | arguments = [AROUTER_MODULE_NAME: project.getName()] 19 | } 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | } 31 | 32 | dependencies { 33 | implementation fileTree(dir: 'libs', include: ['*.jar']) 34 | 35 | implementation 'com.android.support:appcompat-v7:28.0.0' 36 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 37 | testImplementation 'junit:junit:4.12' 38 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 40 | 41 | implementation project(':baselibrary') 42 | annotationProcessor 'com.alibaba:arouter-compiler:1.2.2' 43 | implementation project(":user-api") 44 | } 45 | -------------------------------------------------------------------------------- /other/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /other/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /other/src/main/java/com/dhht/other/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.dhht.other; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.alibaba.android.arouter.facade.annotation.Autowired; 9 | import com.alibaba.android.arouter.facade.annotation.Route; 10 | import com.alibaba.android.arouter.launcher.ARouter; 11 | import com.dhht.user.UserService; 12 | 13 | @Route(path = "/other/MainActivity") 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | @Autowired//(name = "/user/UserService") 17 | UserService mUserService; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | ARouter.getInstance().inject(this); 23 | setContentView(R.layout.other_activity_main); 24 | 25 | 26 | //mUserService=ARouter.getInstance().navigation(UserService.class); 27 | 28 | findViewById(R.id.btHello).setOnClickListener(new View.OnClickListener() { 29 | @Override 30 | public void onClick(View v) { 31 | Toast.makeText(MainActivity.this, "Hello:" + mUserService.getUser().getName(), Toast.LENGTH_SHORT).show(); 32 | } 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /other/src/main/java/com/dhht/other/Other.api: -------------------------------------------------------------------------------- 1 | package com.dhht.other; 2 | 3 | /** 4 | * @author HanPei 5 | * @date 2019/4/23 下午2:43 6 | */ 7 | public class Other { 8 | String name; 9 | int id; 10 | } 11 | -------------------------------------------------------------------------------- /other/src/main/res/layout/other_activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 |