为了更好的管理依赖包的版本以及编译sdk的版本号,这里单独抽出一个dependency.gradle来做统一管理
-
在项目build.gradle同级的根目录下创建dependency.gradle,内容如下
ext { extAndroid = [ compileSdkVersion: 26, minSdkVersion : 18, targetSdkVersion : 26 ] extDependencies = [ appcompat : 'com.android.support:appcompat-v7:24.2.1', constraint_layout : 'com.android.support.constraint:constraint-layout:1.0.2', gson : 'com.google.code.gson:gson:2.8.1', butterknife : 'com.jakewharton:butterknife:8.7.0', butterknife_compile: 'com.jakewharton:butterknife-compiler:8.7.0', ormlite_core : 'com.j256.ormlite:ormlite-core:5.0', ormlite_android : 'com.j256.ormlite:ormlite-android:5.0', design : 'com.android.support:design:24.2.1', okhttp : 'com.squareup.okhttp3:okhttp:3.2.0', junit : 'junit:junit:4.12', test_runner : 'com.android.support.test:runner:1.0.1', test_espresso : 'com.android.support.test.espresso:espresso-core:3.0.1' ] }
-
在build.gradle中添加apply from: './dependency.gradle',使得dependency.gradle内容可以被其他的.gradle文件直接引用。
-
在app目录下的build.gradle中使用
compileSdkVersion extAndroid['compileSdkVersion'] defaultConfig { applicationId "com.simple" minSdkVersion extAndroid['minSdkVersion'] targetSdkVersion extAndroid['targetSdkVersion'] versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } ----------------------------------------------------------------------------- dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation extDependencies['appcompat'] implementation extDependencies['constraint_layout'] testImplementation extDependencies['junit'] androidTestImplementation extDependencies['test_runner'] androidTestImplementation extDependencies['test_espresso'] }
对布局文件进行分包处理
-
res目录右键新建res folder
20180326113413.png -
相对应的build.gradle中将添加
sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/layouts', 'src/main/res/layouts/login', 'src/main/res/layouts/main', 'src/main/res/layouts/setting'] } }
网友评论