简体   繁体   中英

Android Studio Proguard Base location

I'm using Zelix Klass Master to obfuscate my android apps. Been using It for about 1 year. I decided to upgrade my android studio since I was still running version 3.0.1. After updating android studio I can no longer obfuscate my apk with Zelix, It's using Proguard to obfuscate my android application the way Zelix works via proguard is that I need to replace the proguard jar inside the directory

<Android Studio>\\gradle\\m2repository\\net\\sf\\proguard\\proguard-base

I have replaced all the proguard jars in the directory and even delated the proguard parent file inside sf and it still uses proguard to obfuscate my android apk my guess is it no longer uses proguard from <Android Studio>\\gradle\\m2repository\\net\\sf\\proguard because I deleted that directory and android studio still builds using proguard.

So the question is where is the new proguard lib? and how do I get it to use proguard from that directory (proguard-base) instead? for information about how to setup Zelix you can read it here :

Edit: After Svet's answer I tried doing what he suggested and it's throwing this error now..

Unable to find method 'proguard.KeepClassSpecification.(ZZZZZZZLproguard/ClassSpecification;Lproguard/ClassSpecification;)V'. Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

The problem appears to be the fact that ProGuard is now treated as a dependency of the Android Gradle plugin in the latest versions of Android Studio and so is updated along with it. So any replacement of the proguard.jar with the renamed proGuardStub.jar may being automatically reversed.

I am definitely not a Gradle expert. However, I am told that a change to the build.gradle like the following works.

buildscript {  
    repositories {
        flatDir { dirs '/proguard' }
    }
    dependencies {
        classpath ':proguard:'
    }
}

The "flatDir" specifies a flat directory repository which I believe will not be automatically updated. If there are any Gradle experts out there who can improve or elaborate on this approach then it would be greatly appreciated.

The fact that you are getting the "Unable to find method 'proguard.KeepClassSpecification.(ZZZZZZZLproguard/ClassSpecification;Lproguard/ClassSpecification;)V" error suggests that you are successfully using the renamed proguardStub.jar. The problem is that the current proguardStub.jar needs to be updated to more fully reflect ProGuard 6.0. It looks like ProGuard 6.0 adds an extra constructor which does not appear in the KeepClassSpecification class in proguardStub.jar.

You could reasonably expect a new release of proguardStub.jar in the next week or so.

Okay, I have fixed the issue thanks to Svet. I will reward him the bounty for helping me. So He answered and told me I had to change the proguard classPath like the following

buildscript {  
    repositories {
        flatDir { dirs '/proguard' }
    }
    dependencies {
        classpath ':proguard:'
    }
}

After that obviously It won't work with the original proguardStub.jar since It's for proguard 5.0 and not 6.0.3 I am taken the code apart and injected code into the old proguardStub.jar to be treated as 6.0.3 and now it finally works! here is the updated proguardStub.jar that I have created here .

If any of you are wondering how I did it, I just changed the bytecode using ASM so it doesn't cause errors and also changed the old String so it shows 6.0.3 instead of 5.0 :) Of course the String doesn't effect anything rather then just showing what version it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM