從圖能夠大體知道,經過不一樣的模塊工程,已經將不一樣的分享平臺隔離開來。android
dependencies {
implementation 'com.ysbing.yshare:yshare:1.0.0'
implementation 'com.ysbing.yshare:qq:1.0.0'
implementation 'com.ysbing.yshare:wechat:1.0.0'
implementation 'com.ysbing.yshare:weibo:1.0.0'
}
複製代碼
依賴了四個,第一個是必須有的,是YShare的入口類,全部的交互只在這個庫進行,其他的是按需接入的,好比qq,若是沒依賴它的話,是不能使用的,由於處理的邏輯在qq模塊裏,因此要用哪一個分享平臺,就寫上對應的分享平臺依賴。git
看了依賴方式,應該對這種方式的實現有點好奇,咱們先來看下'com.ysbing.yshare:yshare:1.0.0'自己,打開它的pom文件github
<dependencies>
<dependency>
<groupId>com.ysbing.yshare</groupId>
<artifactId>base</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.ysbing.yshare</groupId>
<artifactId>qq</artifactId>
<version>1.0.0-blank</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.ysbing.yshare</groupId>
<artifactId>wechat</artifactId>
<version>1.0.0-blank</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.ysbing.yshare</groupId>
<artifactId>weibo</artifactId>
<version>1.0.0-blank</version>
<scope>compile</scope>
</dependency>
<dependency>
複製代碼
裏面實際上是有作了對qq、wechat和weibo的工程依賴,可是版本號有點奇怪,是1.0.0-blank,而不是1.0.0,這個blank版本是有什麼特殊嗎?來,看下qq模塊工程的build.graleapp
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: new File(rootProject.projectDir, "gradle/gradle-on-demand.gradle")
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode VERSION_CODE.toInteger()
versionName VERSION_NAME.toString()
if (VERSION_NAME.contains("blank")) {
defaultPublishConfig "blankRelease"
} else {
defaultPublishConfig "fullRelease"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "channel"
productFlavors {
blank {
dimension "channel"
}
full {
dimension "channel"
}
}
}
dependencies {
debugImplementation project(':base')
releaseImplementation 'com.ysbing.yshare:base:' + VERSION_NAME.replace("-blank", "")
fullImplementation files('libs/open_sdk_r6019_lite.jar')
}
複製代碼
這裏配置了兩種風味,分別是full和blank,full風味裏是真正實現分享邏輯的類,而blank風味裏面是空實現,在發佈的時候,用yshare入口庫引用了blank風味,因此就不會增大致積,按需引用full風味,根據不一樣的版本號,就將blank風味替換成full風味,這樣就實現了真正邏輯上的替換。gradle