hch
2024-05-22 1f9ca5966385f6b4932ac1d0c17b03c6c03b9afd
SdkProject/library/build.gradle
@@ -1,6 +1,7 @@
plugins {
    id 'com.android.library'
}
def rootPath = rootProject.getRootDir().getAbsolutePath()
def channelPath = "${rootPath}/channel/${CHANNEL_NAME}"
@@ -11,34 +12,41 @@
        apply from: path
}
applyGradle("${rootPath}/utils")
applyGradle("${channelPath}/build")
applyGradle("${rootPath}/utils")//工具脚本
applyGradle("${channelPath}/build")//渠道脚本
applyGradle("${channelPath}/deps")//渠道的远程依赖脚本
Properties localProp = loadProperties('local')
Properties channelProp = loadProperties("${channelPath}/config")
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 29
    buildToolsVersion "30.0.2"
    compileSdkVersion 33
    buildToolsVersion "33.0.0"
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
        multiDexEnabled true
    }
    flavorDimensions "version"
    productFlavors {
@@ -57,6 +65,7 @@
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {exclude 'META-INF/rxjava.properties'}
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
@@ -93,25 +102,126 @@
                java.srcDirs "${pluginPath}/java"
                jniLibs.srcDirs "${pluginPath}libs"
                res.srcDirs "${pluginPath}/res"
                manifest {
                    File file = file("${pluginPath}/AndroidManifest.xml")
                    if (file.exists())
                        srcFile "${pluginPath}/AndroidManifest.xml"
                }
                //清单只能合并一个,所有插件的清单需要手动复制到对应的渠道里
            }
        }
    }
}
dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.3'
    implementation 'androidx.navigation:navigation-fragment:2.3.1'
    implementation 'androidx.navigation:navigation-ui:2.3.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation files('libs/unity-classes.jar')
}
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 files('libs/unity-classes.jar')
    implementation('androidx.appcompat:appcompat:1.0.0') {
        force = true
    }
//以下为必需依赖的库
    implementation(name: 'common-release', ext: 'aar')
    implementation(name: 'sdk_mycard-release', ext: 'aar')
    implementation(name: 'sdk_oaid-release', ext: 'aar')
    implementation(name: 'sdk_res_ald-release', ext: 'aar')
    //SDK基础能力
    implementation 'com.appsflyer:af-android-sdk:6.9.0'
    implementation 'com.android.installreferrer:installreferrer:2.2'
    api 'androidx.annotation:annotation:1.5.0'
    api 'androidx.core:core:1.6.0'
    api 'androidx.percentlayout:percentlayout:1.0.0'
    //google ID
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    //firebase
    implementation 'com.google.firebase:firebase-analytics'
    implementation platform('com.google.firebase:firebase-bom:31.2.2') {
        exclude group: 'com.android.support', module: 'support-compat'
    }
    //base  theme
    api 'androidx.appcompat:appcompat:1.2.0'
    //ald ui用
    api 'androidx.cardview:cardview:1.0.0'
}