hch
2023-11-19 a458ea510569c1c8ef0ca67b8af21ccf9447c9a3
SdkProject/library/build.gradle
@@ -1,6 +1,8 @@
plugins {
    id 'com.android.library'
    id 'com.google.gms.google-services'
}
def rootPath = rootProject.getRootDir().getAbsolutePath()
def channelPath = "${rootPath}/channel/${CHANNEL_NAME}"
@@ -25,24 +27,27 @@
//插件脚本
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 "28.0.1"
    compileSdkVersion 30
    buildToolsVersion "30.0.3"
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
//        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
        multiDexEnabled true
    }
    flavorDimensions "version"
    productFlavors {
@@ -61,6 +66,7 @@
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {exclude 'META-INF/rxjava.properties'}
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
@@ -97,11 +103,7 @@
                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"
                }
                //清单只能合并一个,所有插件的清单需要手动复制到对应的渠道里
            }
        }
    }
@@ -111,12 +113,6 @@
    variant.outputs.all {
        outputFileName = "library-${buildType.name}-${CHANNEL_NAME}.aar"
    }
}
//拷贝渠道的第三方依赖库脚本
task copyDepsGradle(type: Copy) {
    from "${channelPath}/"
    include "deps.gradle"
    into "${outPutPath}\\${CHANNEL_NAME}\\"
}
//拷贝清单文件
@@ -140,30 +136,91 @@
    into "${outPutPath}\\${CHANNEL_NAME}\\debug\\libs\\"
}
//执行打包任务以及拷贝到外部
task assembleAndCopySdk(type: Copy) {
    delete "${outPutPath}\\${CHANNEL_NAME}"
    dependsOn 'assembleMerger'
//    dependsOn copyManifest
    dependsOn copyDebugSdk
    dependsOn copyDepsGradle
task copyReleaseSdk(type: Copy) {
    from "build/outputs/aar/"
    include "library-release-${CHANNEL_NAME}.aar"
    into "${outPutPath}\\${CHANNEL_NAME}\\release\\libs\\"
}
dependencies {
    implementation 'com.android.support:support-annotations:28.0.0'
    testImplementation 'junit:junit:4.13.1'
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.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'])
    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
    }
    //sdk所需依赖
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
    //firebase
    implementation(platform("com.google.firebase:firebase-bom:32.2.2"))
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-auth'
    // google
    implementation 'com.google.android.gms:play-services-auth:20.6.0'
    // facebook
    implementation 'com.facebook.android:facebook-login:16.2.0'
    implementation 'androidx.activity:activity-compose:1.3.1'
    // google 支付
    implementation 'com.android.billingclient:billing:6.0.1'
    implementation 'androidx.fragment:fragment:1.3.2'
    // adjust (V1.0.2新增)
    implementation 'com.adjust.sdk:adjust-android:4.33.5'
    implementation 'com.android.installreferrer:installreferrer:2.2'
    implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
    implementation 'com.google.android.gms:play-services-appset:16.0.2'
}