Android Studio(Gradle)中的java library模块如何使用Proguard混淆代码

参考:

https://stackoverflow.com/questions/40616077/using-proguard-in-java-modules-android-studio

https://segmentfault.com/a/1190000010338331


Project:

    -app (android application)

    -common (java library)

        -build.gradle

        import proguard.gradle.ProGuardTask

        buildscript {

            classpath"net.sf.proguard:proguard-gradle:5.3.3"

        }

        task proguardFiles(type: ProGuardTask,dependsOn: compileJava) {

            // make jar task wait for proguardFiles task finish

            tasks.jar.dependsOn.add(proguardFiles)

            println"proguarding"

            // build\classes\java\main

            println"${sourceSets.main.java.outputDir}"

            // main classes

            println"${sourceSets.main.output}"

            printmapping"$buildDir/mapping.txt"

            configuration'proguard-rules.pro'

            libraryjars files(configurations.compile.findAll {}.collect())

            injarssourceSets.main.output

            // setup proguard output classes: output not .jar

            outjars"$buildDir/libs/${project.name}"

            // delete previous outputs

            delete"$buildDir/libs/${project.name}"

            // replace the original classes

            doLast {

                println"copying product"

                // delete original classes in "${sourceSets.main.java.outputDir}"

                delete"${sourceSets.main.java.outputDir}"  //"${sourceSets.main.output.classesDir}"

                copy {

                    from"$buildDir/libs/${project.name}"

                    // copy proguard outputs into "${sourceSets.main.java.outputDir}"

                    into"${sourceSets.main.java.outputDir}"  //"${sourceSets.main.output.classesDir}"

                }

            }

        }


Android Studio(Gradle)中的java library模块如何使用Proguard混淆代码_第1张图片


依赖的jar需不需要打包进来,如果需要怎么搞?

如何在该模块内区分release/debug,让debug不混淆?

你可能感兴趣的:(Android Studio(Gradle)中的java library模块如何使用Proguard混淆代码)