shwenzhang / AndResGuard

proguard resource for Android by wechat team
Apache License 2.0
8.49k stars 1.53k forks source link

Gradle Kts #464

Open SudoDios opened 3 years ago

SudoDios commented 3 years ago

How to use in gradle.kts ????

Paidaxi commented 3 years ago

i have the same question

SudoDios commented 3 years ago

I found the answer : In Gradle Settings ->

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.1.3")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
        classpath("com.tencent.mm:AndResGuard-gradle-plugin:1.2.20")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

fun clean (type: Delete) {
    delete(rootProject.buildDir)
}

and In your gradle ->

plugins {
    id("com.android.application")
    id("AndResGuard")
    kotlin("android")
    kotlin("android.extensions")
}

apply {
    plugin("AndResGuard")
}

android {
    compileSdkVersion(30)
    buildToolsVersion("30.0.2")

    defaultConfig {
        applicationId ("com.sdidev.work.firstkotlin")
        minSdkVersion (21)
        targetSdkVersion (30)
        versionCode (1)
        versionName ("1.0")
        multiDexEnabled = true

    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.4.32")
    implementation("androidx.core:core-ktx:1.6.0-alpha02")
    testImplementation("junit:junit:4.13.2")
}

andResGuard {
    mappingFile = file("./resource_mapping.txt")
    use7zip = true
    useSign = true
    keepRoot = false
    fixedResName = "arg"
    mergeDuplicatedRes = true
    compressFilePattern = arrayOf("*.png","*.jpg","*.jpeg","*.gif").toMutableList()
    sevenzip {
        artifact = "com.tencent.mm:SevenZip:1.2.20"
    }
}