com.google.android.gms.internal.zzhu: can't fi

2019-01-24 00:20发布

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;
    }
}

5条回答
▲ chillily
2楼-- · 2019-01-24 00:46

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!

查看更多
做自己的国王
3楼-- · 2019-01-24 00:51

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.

查看更多
【Aperson】
4楼-- · 2019-01-24 01:05

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'
查看更多
Luminary・发光体
5楼-- · 2019-01-24 01:07

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.

查看更多
仙女界的扛把子
6楼-- · 2019-01-24 01:07

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.

查看更多
登录 后发表回答