模块化开发时ARouter的配置
GitHub:https://github.com/alibaba/ARouter
跟官方提供的有点不一样
环境:Android studio 3.0.1
1.项目的结构
2.模块中添加配置
base模块:build.gradle文件
dependencies {
...
compile ('com.alibaba:arouter-api:1.3.1'){ exclude group: 'com.android.support' }
// implementation 'com.alibaba:arouter-api:1.3.1'
}
功能模块:build.gradle文件
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = [moduleName: project.getName()]
}
}
}
dependencies {
...
annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
implementation project(':base')//base模块里添加依赖
}
app模块:build.gradle文件
defaultConfig {
...
//Enabling multidex support.
multiDexEnabled true
}
dependencies {
...
implementation project(':base')
implementation project(':login')
implementation project(':find')
implementation project(':home')
implementation project(':user')
implementation project(':shoppingcart')
compile 'com.android.support:multidex:1.0.1'
}
app模块中MyApplication:需要在AndroidManifest.xml中配置
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
initRouter(this);
}
public static void initRouter(Application application) {
if (BuildConfig.DEBUG) {
ARouter.openLog(); // 打印日志
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
}
ARouter.init(application);
}
}