Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
    }
}
like image 610
Felipe Porge Xavier Avatar asked Oct 06 '15 15:10

Felipe Porge Xavier


3 Answers

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!

like image 69
yuval Avatar answered Nov 04 '22 09:11

yuval


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.

like image 39
Sean Barbeau Avatar answered Nov 04 '22 10:11

Sean Barbeau


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.

like image 2
Akah Avatar answered Nov 04 '22 09:11

Akah