23

I tried to generate an apk using proguard, but I've got this error while trying to build:

Warning: com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy

Warning: there were 3 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)
:app:proguardRelease FAILED
Error:Execution failed for task ':app:proguardRelease'.
java.io.IOException: Please correct the above warnings first.

Recently, I upgraded my Android SDK Tools. Before it, this project presented no problems with proguard. I found this post (https://plus.google.com/+PaulBurke/posts/T3vmAnRP3q6) where Oliver Renner wrote:

"So basically the next Google library that may not be upgraded to the latest version. It also seems to require compileSdk 23 in order to be able to use ProGuard without modifications (Warning: com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy)"*

I updated my project to compile using SDK 23, but the problem wasn't solved.

Bellow, I included some parts of my build.gradle file:

compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.sample.sample"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0.0"
    }

.
.
.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:design:23.0.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.0@aar') {
        transitive = true;
    }
}
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
Felipe Porge Xavier
  • 2,236
  • 6
  • 19
  • 27
  • Did you try the `-dontwarn android.security.**` Plus try to disable optimizations with `-dontoptimize` and see how it goes – ThanosFisherman Oct 06 '15 at 16:29
  • 1
    Ok try this one: In your attached gradle file, under your `buildToolsVersion "23.0.0"` enter the following `useLibrary 'org.apache.http.legacy'` If this works I will write a more detailed answer on how and why this worked – ThanosFisherman Oct 06 '15 at 22:58
  • Had the same problem, but I'm not using Gradle for building and `-dontwarn android.security.**` worked for me. – NumberFour Oct 08 '15 at 17:18
  • i hope you are aware what using + in your dependencies have on compiling your code. Attempts are made on each build to determine the latest version of the dependency and downloaded. This will bring about conflicts especially for a dependency like firebase that needs to be in synch with google play services. – Akah Dec 09 '16 at 15:14
  • @ThanosFisherman: your solution works for me :) – Steve Luck Mar 28 '18 at 02:51

6 Answers6

27

I had this same problem. The warning message says:

If your code works fine without the missing classes, you can suppress the warnings with '-dontwarn' options.

So let's take its suggestion:

-dontwarn com.google.android.gms.internal.zzhu

For me, this fixed the issue. However, if for some reason your code does NOT work fine without the class, you can do something like this in addition (not tested):

-keep class com.google.android.gms.internal.** { *; }

Note that you'll need the -dontwarn line either way. Good luck!

yuval
  • 6,369
  • 3
  • 32
  • 44
  • 2
    Avoid adding lines to your proguard if they do nothing useful. -keep class com.google.android.gms.internal.** { *; } only tells proguard not to obfuscate the classes in the package you mentioned. It will not solve the warning as the problem is not with the class android.gms.internal.zzhu but with the referenced class android.security.NetworkSecurityPolicy from that class. Proguard just can not find the definition of the class so it throws a warning. If you know that this class (NetworkSecurityPolicy) should be there at runtime you can use the dontwarn. – MikeL Sep 03 '16 at 10:15
  • 1
    Also I would check that NetworkSecurityPolicy class is not obfuscated (and thus proguard does not see it) and maybe put a keep on it. – MikeL Sep 03 '16 at 10:30
7

For me, it looks like this was actually caused by Google accidentally including AdMob in the dependencies of Play Services Analytics 8.1: https://plus.google.com/+GoogleDevelopers/posts/HsSNWEQ6H4e

If I exclude the play-services-ads module in build.gradle I don't get the Proguard error with android.security.NetworkSecurityPolicy, and my release build installs and runs without any problems (it was previously crashing on startup with java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity, while debug build was working fine):

compile ('com.google.android.gms:play-services-analytics:8.1.0') {
    exclude module: 'play-services-ads'
}

In Proguard rules you also need:

-dontwarn com.google.android.gms.ads.**

Thanks to this post for details (although it doesn't reference builds crashing at all, just APK size): https://medium.com/google-developer-experts/warning-for-google-analytics-users-44b0096084e2#.4b3egtbxh

Here's the issue for the project I was working on, which includes the commit that resolved the issue: https://github.com/OneBusAway/onebusaway-android/issues/342

EDIT

Users are reporting that this is resolved in 8.3, which means you could fix this by setting your build.gradle to:

compile 'com.google.android.gms:play-services-analytics:8.3.0'

I have yet to confirm myself.

Sean Barbeau
  • 11,496
  • 8
  • 58
  • 111
2

I had such a similar error when i was recently upgrading my play service dependency. It seems to occur when you leave out updating the firebase dependencies that correspond to the version of play services you use.

Here is what the two versions of my dependencies were:

Error version of dependencies

compile 'com.google.firebase:firebase-appindexing:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-places:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.firebase:firebase-auth:9.8.0'
compile 'com.google.firebase:firebase-database:9.8.0'
compile 'com.firebaseui:firebase-ui-database:1.0.1'
compile 'com.google.firebase:firebase-storage:9.8.0'

Working version of dependencies ``

compile 'com.google.firebase:firebase-appindexing:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-places:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.0'
compile 'com.google.firebase:firebase-database:10.0.0'
compile 'com.firebaseui:firebase-ui-database:1.0.1'
compile 'com.google.firebase:firebase-storage:10.0.0'

`` Google seems to move play service updates along with firebase updates these days. Hopes this saves a few souls out there.

Akah
  • 1,389
  • 14
  • 19
2

The problem comes when I update the version, I try all the solutions but don't work for me.Then I see this isuue #24109609 and the rule into pro-guard is works for me.

-keepattributes Signature -keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.apache.** -dontwarn org.w3c.dom.**
-dontwarn android.support.v4.**
-dontwarn com.google.android.gms.**
-dontwarn com.google.firebase.**
-keep class * extends com.myCompany.package.flavor.Flavor { *; }
-keep class com.myCompany.** { *; }
Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60
0

For me I just synched all my project's modules to use a recent play services library and I was able to use the package.

what I use in my build.gradle (for all modules) :

compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0'

Before I was using compile 'com.google.android.gms:play-services:7.5.0'

Hope this helps someone.

Driss Bounouar
  • 3,182
  • 2
  • 32
  • 49
-3

For me it work by replacing

compile 'com.google.android.gms:play-services-appindexing:9.8.0'

with:

compile 'com.google.android.gms:play-services:10.0.0'
user4016525
  • 29
  • 1
  • 3