proguard – com.google.android.gms.internal.zzhu: can't find referenced class android.security.NetworkSecurityPolicy-ThrowExceptions

Exception or error:

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;
    }
}
How to solve:

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!

###

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.

###

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.

###

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.** { *; }

###

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.

###

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'

Leave a Reply

Your email address will not be published. Required fields are marked *