36

I am using android studio to build debug and release application. When i build debug/release application

./gradlew assembleDebug

./gradlew assembleRelease

both build are created perfectly and run as well. Shows appropriate dialog box for debug or release

now i have added proguard details in build.gradle:

signingConfigs {
    myConfig {
           storeFile file("keystore.jks")
           storePassword "abc123!"
           keyAlias "androidreleasekey"
           keyPassword "pqrs123!"
    }
}

buildTypes {
    release {
        runProguard true
        proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        signingConfig signingConfigs.myConfig
    }
}
productFlavors {
    defaultFlavor {
        proguardFile 'proguard-rules.txt'
    }
}

Now it shows error in event log as

Warning: there were 7 unresolved references to classes or interfaces. You may need to add missing library jars or update their versions. If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options. (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

Warning: there were 2 unresolved references to program class members. Your input classes appear to be inconsistent. You may need to recompile the code.

(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember) :Flash Sales:proguardDefaultFlavorRelease FAILED

If i turn the runProguard option to false then its running.

I have these questions:

1) is it ok to release apk with runProguard = false?

2) How to use dontwarn while creating release build?

Jonik
  • 80,077
  • 70
  • 264
  • 372
morya
  • 835
  • 2
  • 10
  • 19
  • Is that the full error log? It seems like you left out the actual 7 + 2 unresolved references. Using `-dontwarn` is quite easy, see e.g. this for an example: http://stackoverflow.com/questions/6974231/proguard-hell-cant-find-referenced-class – Jonik Jan 14 '14 at 21:06
  • 1
    As to your question 1), for actual release build (to Google Play etc), it's recommended to use ProGuard. (But not mandatory if you don't care that your app is easy to reverse engineer.) I'd say it's definitely worth taking an hour to two to learn to use ProGuard & solve those errors you're getting. – Jonik Jan 14 '14 at 21:11
  • Thanks for quick response. Now when add that line dontwarn in proguard-rules.txt the build created successfully. Now i have one more question I was getting reference warning as Warning: jcifs.http.NetworkExplorer: can't find superclass or interface javax.servlet.http.HttpServlet Warning: jcifs.http.NtlmHttpFilter: can't find superclass or interface javax.servlet.Filter When i used way 1: -dontwarn javax.servlet.** or this way 2: -dontwarn jcifs.http.** the build created successfully. So which way should be preferred and what is difference n this two? – morya Jan 14 '14 at 21:43
  • I think you can find your answer at this link https://stackoverflow.com/questions/35268287/what-is-the-difference-between-keep-class-and-dontwarn – Sepehr Jun 01 '19 at 11:21

2 Answers2

30

When I add new lib to project Generally this How I need to define for Progaurd.

Let's say I am using Twitter4J lib then I add dontwarn this way.

-keep class twitter4j.** { *; }

-dontwarn twitter4j.**

Community
  • 1
  • 1
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • 3
    does the "unresolved references" warning mean that Proguard did remove the classes or not? Shouldn't I filter those rather then dontwarn? – Kamil Seweryn Mar 07 '15 at 13:14
  • 8
    where do u add this exactly? – Jono Apr 27 '15 at 14:57
  • @jonney please check [**this**](http://stackoverflow.com/questions/4732656/enabling-proguard-in-eclipse-for-android) post, may help you. – swiftBoy Apr 28 '15 at 05:31
  • Add these to your proguard-project.txt file in section # Dont warn – Lou Morda Jan 11 '16 at 17:00
  • 2
    can I use -dontwarn *.** ? – WitVault Sep 25 '17 at 17:26
  • Can someone please expand this answer to give some context? As in you've adopted someone else's project but have no idea what proguard is? A few basics such as what file to change would be helpful. – dthree Jan 20 '18 at 02:26
  • @dthree ProGuard is a shrinking/obfuscation tool for Java and Android. You can read much more about it on their official website: https://www.guardsquare.com/en/products/proguard – xarlymg89 Jun 19 '18 at 18:00
  • 2
    Note: writing `-keep class some.library.** { *; }` for all your libraries is like not using ProGuard at all. – Miha_x64 Nov 26 '18 at 11:00
2

Put the -dontwarn lines in the proguard-rules.pro or proguard-rules.txt file.

Had to google this elsewhere since none of the answers included this info. Check the other answers for the specific lines you need for your case.

JJ Du Plessis
  • 1,047
  • 12
  • 9