plugins {
|
id 'com.android.library'
|
}
|
|
def rootPath = rootProject.getRootDir().getAbsolutePath()
|
def channelPath = "${rootPath}/channel/${CHANNEL_NAME}"
|
|
def applyGradle(String path) {
|
path = "${path}.gradle"
|
File file = file(path)
|
if (file.exists())
|
apply from: path
|
}
|
|
applyGradle("${rootPath}/utils")//工具脚本
|
applyGradle("${channelPath}/build")//渠道脚本
|
applyGradle("${channelPath}/deps")//渠道的远程依赖脚本
|
|
Properties localProp = loadProperties('local')//本地配置
|
Properties channelProp = loadProperties("${channelPath}/config")//渠道所属的配置
|
|
def outPutPath = localProp.getProperty("OUTPUT_PATH")//工程sdk输出路径
|
|
//当前渠道所应用的插件名
|
def plugins = channelProp.getProperty("PLUGINS").split(';')
|
//插件脚本
|
plugins.each {
|
applyGradle("${rootPath}/plugins/${it}/build")
|
applyGradle("${rootPath}/plugins/${it}/deps")
|
}
|
|
//渠道需要覆盖主目录的java文件
|
def channelJavaFiles = getAllFiles(new ArrayList<File>(), "${channelPath}/java")
|
|
android {
|
compileSdkVersion 30
|
buildToolsVersion "28.0.1"
|
|
defaultConfig {
|
minSdkVersion 21
|
targetSdkVersion 30
|
versionCode 1
|
versionName "1.0"
|
|
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
consumerProguardFiles "consumer-rules.pro"
|
}
|
|
|
flavorDimensions "version"
|
productFlavors {
|
merger {
|
dimension "version"
|
}
|
}
|
|
buildTypes {
|
release {
|
minifyEnabled false
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
}
|
}
|
compileOptions {
|
sourceCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
}
|
lintOptions {
|
checkReleaseBuilds false
|
abortOnError false
|
}
|
|
//合并资源
|
sourceSets {
|
main {
|
java {
|
//剔除主目录下,渠道重复的类
|
channelJavaFiles.each {
|
def tag = "java\\"
|
def str = it.getAbsolutePath()
|
def str1 = str.substring(0, str.indexOf(tag))
|
def str2 = str.substring(str1.length() + tag.length(), str.length())
|
exclude str2
|
}
|
}
|
}
|
merger {
|
java {
|
srcDirs "${channelPath}/java"
|
}
|
jniLibs.srcDirs "${channelPath}/libs"
|
res.srcDirs "${channelPath}/res"
|
manifest {
|
File file = file("${channelPath}/AndroidManifest.xml")
|
if (file.exists())
|
srcFile "${channelPath}/AndroidManifest.xml"
|
}
|
//合并插件
|
plugins.each {
|
def pluginPath = "${rootPath}/plugins/${it}"
|
java.srcDirs "${pluginPath}/java"
|
jniLibs.srcDirs "${pluginPath}libs"
|
res.srcDirs "${pluginPath}/res"
|
//清单只能合并一个,所有插件的清单需要手动复制到对应的渠道里
|
}
|
}
|
}
|
}
|
|
android.libraryVariants.all { variant ->
|
variant.outputs.all {
|
outputFileName = "library-${buildType.name}-${CHANNEL_NAME}.aar"
|
}
|
}
|
|
//拷贝清单文件
|
task copyDebugManifest(type: Copy) {
|
from zipTree("build/outputs/aar/library-debug-${CHANNEL_NAME}.aar")
|
include "AndroidManifest.xml"
|
into "${outPutPath}\\${CHANNEL_NAME}\\debug"
|
}
|
//拷贝清单文件
|
task copyManifest(type: Copy) {
|
dependsOn 'copyDebugManifest'
|
from zipTree("build/outputs/aar/library-release-${CHANNEL_NAME}.aar")
|
include "AndroidManifest.xml"
|
into "${outPutPath}\\${CHANNEL_NAME}\\release"
|
}
|
|
//拷贝debug aar
|
task copyDebugSdk(type: Copy) {
|
from "build/outputs/aar/"
|
include "library-debug-${CHANNEL_NAME}.aar"
|
into "${outPutPath}\\${CHANNEL_NAME}\\debug\\libs\\"
|
}
|
|
task copyReleaseSdk(type: Copy) {
|
from "build/outputs/aar/"
|
include "library-release-${CHANNEL_NAME}.aar"
|
into "${outPutPath}\\${CHANNEL_NAME}\\release\\libs\\"
|
}
|
|
task deleteSdk() {
|
delete "${outPutPath}\\${CHANNEL_NAME}\\debug"
|
delete "${outPutPath}\\${CHANNEL_NAME}\\release"
|
}
|
|
//执行打包任务以及拷贝到外部
|
task assembleAndCopySdk() {
|
dependsOn 'assemble'
|
dependsOn deleteSdk
|
dependsOn copyDebugSdk
|
dependsOn copyReleaseSdk
|
|
tasks.findByName('deleteSdk').mustRunAfter 'assembleMerger'
|
tasks.findByName('copyDebugSdk').mustRunAfter 'deleteSdk'
|
tasks.findByName('copyReleaseSdk').mustRunAfter 'deleteSdk'
|
|
//导出所有外部引用
|
String content = ""
|
def deps = file("${channelPath}\\deps.gradle")
|
deps.eachLine { line ->
|
if (line != null)
|
content += line + "\n"
|
}
|
plugins.each {
|
deps = file("${rootPath}/plugins/${it}/deps.gradle")
|
if(deps.exists()){
|
deps.eachLine { line ->
|
if (line != null)
|
content += line + "\n"
|
}
|
}
|
}
|
def dir = new File("${outPutPath}\\${CHANNEL_NAME}")
|
def libraries = new File("${outPutPath}\\${CHANNEL_NAME}\\deps.gradle")
|
dir.mkdir()
|
if (libraries.exists())
|
libraries.delete()
|
if (!libraries.exists())
|
libraries.createNewFile()
|
libraries.text = content
|
}
|
|
dependencies {
|
implementation 'androidx.annotation:annotation:1.0.0'
|
testImplementation 'junit:junit:4.13.2'
|
//noinspection GradleCompatible
|
// implementation 'com.android.support:appcompat-v7:28.0.0'
|
|
// implementation 'com.github.pqpo:Log4a:1.4.2@aar'
|
|
implementation fileTree(dir: "../channel/${CHANNEL_NAME}/libs/", include: ['*.jar'])
|
plugins.each {
|
implementation fileTree(dir: "${rootPath}/plugins/${it}/libs/", include: ['*.jar'])
|
}
|
implementation fileTree(dir: 'libs', include: ['*.jar'], exclude: ['unity-classes.jar'])
|
|
compileOnly fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
|
|
implementation('androidx.appcompat:appcompat:1.0.0') {
|
force = true
|
}
|
implementation(name: 'SohaSDK', ext: 'aar')
|
|
implementation 'com.google.android.material:material:1.0.0'
|
|
|
api 'com.squareup.retrofit2:retrofit:2.5.0'
|
api 'com.squareup.retrofit2:converter-gson:2.4.0'
|
api 'com.squareup.okhttp3:logging-interceptor:3.9.0'
|
|
|
implementation 'com.google.firebase:firebase-analytics:17.4.1'
|
implementation 'com.google.firebase:firebase-messaging:20.1.7'
|
implementation 'com.google.firebase:firebase-dynamic-links:19.1.0'
|
implementation 'com.google.firebase:firebase-config:19.1.4'
|
|
|
|
|
implementation 'com.facebook.android:facebook-login:11.1.0'
|
|
implementation 'com.android.billingclient:billing:3.0.0'
|
|
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1'
|
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
|
|
api 'com.github.bumptech.glide:glide:4.9.0'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
implementation 'com.github.ybq:Android-SpinKit:1.1.0'
|
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
|
api 'androidx.multidex:multidex:2.0.1'
|
api 'com.appsflyer:af-android-sdk:5.4.1'
|
api 'com.android.installreferrer:installreferrer:1.0'
|
api 'com.google.android.gms:play-services-auth:18.0.0'
|
|
implementation 'com.adjust.sdk:adjust-android:4.28.3'
|
}
|