General purpose Gradle package obfuscates Jar and merges Jar referenced by a third party (Gradle 3.0)

Keywords: Android Gradle SDK

There are requirements to provide SDK to customers, in the form of jar package Our project references the jars of the third party (actually the jars of another company project), so we also need to type the jars of the third party into the SDK Search online found that the information is not very perfect, comprehensive, their own implementation of gradle script

Pack and go command 1. Unambiguous jar

gradle makeJar

2. Confused Jar gradle makeJar_Pro

The code of the Gradle script is as follows


task clearJar(type: Delete) {
    delete 'build/libs/livesdk_pro.jar'
    delete 'build/libs/livesdk.jar'

}

task makeJar(type: Jar, dependsOn: ['build']) {
    archiveName = 'livesdk.jar'
    from('build/intermediates/classes/release')
    from(project.zipTree("libs/kk_common_sdk.jar"))

    destinationDir = file('build/libs')
    exclude('com/tvmao/sdk/live/BuildConfig.class')
    exclude('com/tvmao/sdk/live/BuildConfig\$*.class')
    exclude('**/R.class')
    exclude('**/R\$*.class')
}

def androidSDKDir = project.android.sdkDirectory.absolutePath
def androidJarDir = androidSDKDir.toString() + '/platforms/' + "${android.compileSdkVersion}" + '/android.jar'   

task makeJar_Pro(type: proguard.gradle.ProGuardTask, dependsOn: "build") {
// Unambiguous jar
    injars 'build/libs/livesdk.jar'
// jar path after confusion
    outjars 'build/libs/livesdk_pro.jar'
    libraryjars(androidJarDir)
// Specific classes that need keep
    configuration 'proguard-rules.pro'
    copy {
        from('build/libs/')
        into('/')
        include('livesdk_pro.jar')
        rename('livesdk_pro.jar', 'livesdk_pro_' + sdkvercode + '.jar')
    }
}
makeJar_Pro.dependsOn(makeJar, clearJar, build)

Note that the way in which the lower version of gradle gets SDK dir is different

def androidSDKDir = plugins.getPlugin('com.android.library').sdkHandler.getSdkFolder()
def androidJarDir = androidSDKDir.toString() + '/platforms/' + "${android.compileSdkVersion}" + '/android.jar'

Posted by LAMP on Sat, 02 May 2020 22:21:02 -0700