官方文檔地址java
其餘配置android
1.建立一個config.gradlegit
ext{ isDebug = false //false:做爲Lib集成存在, true:做爲application組件存在 android = [ compileSdkVersion : 28, minSdkVersion :19, targetSdkVersion :27, versionCode :1, versionName :"1.0", ] libsVersion=[ // App dependencies version supportVersion = "28.0.0", glideVersion = "4.7.1", retrofitVersion ="2.5.0", okhttpVersion = "3.8.0", ] dependencies = [ //android 官方庫 "appcompat-v7" : "com.android.support:appcompat-v7:$rootProject.supportVersion", "support-v4" : "com.android.support:support-v4:$rootProject.supportVersion", "design" : "com.android.support:design:$rootProject.supportVersion", "annotations" : "com.android.support:support-annotations:$rootProject.supportVersion", "gson" : "com.google.code.gson:gson:2.6.2", //路由通信 "arouter-api" : "com.alibaba:arouter-api:1.4.1", "arouter-compiler" : "com.alibaba:arouter-compiler:1.2.2", ] }
Project gradle引用github
apply from:"config.gradle"
2.module gradle配置api
def isDebug = rootProject.ext.isDebug def configs = rootProject.ext.android def librarys = rootProject.ext.dependencies if(isDebug){ apply plugin: 'com.android.application' }else { apply plugin: 'com.android.library' } android { compileSdkVersion configs.compileSdkVersion defaultConfig { minSdkVersion configs.minSdkVersion targetSdkVersion configs.targetSdkVersion versionCode configs.versionCode versionName configs.versionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" if (isDebug) { applicationId "xx.xx.xx" } javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } } sourceSets { main { //控制兩種模式下的資源和代碼配置狀況 if (isDebug) { manifest.srcFile 'src/main/debug/AndroidManifest.xml' } else { manifest.srcFile 'src/main/AndroidManifest.xml' //集成開發模式下排除debug文件夾中的全部Java文件 java { exclude 'debug/**' } } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }
debug下的app
做爲lib時的ide
解決錯誤:InstantRun support error, com.android.tools.fd.runtime.Paths 以及 There is no route match the path gradle
每一個須要路由操做的module 都須要添加ui
implementation 'com.alibaba:arouter-api:x.x.x' annotationProcessor 'com.alibaba:arouter-compiler:x.x.x'
app gradle配置(將須要路由操做的module都依賴到app的module下)google
dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' //noinspection GradleCompatible androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation project(':基類module') if (!isDebug){ implementation project(':login') implementation project(':test') } }