2015-10-06 91 views
16

我試圖使用ProGuard生成APK,但我一直在試圖建立得到這個錯誤:com.google.android.gms.internal.zzhu:找不到引用的類android.security.NetworkSecurityPolicy

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. 

最近,我升級了我的Android SDK工具。在此之前,這個項目沒有提出有關proguard的問題。我發現這個職位(https://plus.google.com/+PaulBurke/posts/T3vmAnRP3q6),其中奧利弗·倫納寫道:

「因此,基本上可以不升級到最新版本,下一個谷歌圖書館也似乎需要compileSdk 23,以便能夠使用的ProGuard無需修改(警告:com.google.android.gms.internal.zzhu:找不到引用的類android.security.NetworkSecurityPolicy)「*

我更新了我的項目中使用SDK 23來編譯,但問題沒有解決。

婁,我包括我的build.gradle文件的某些部分:

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:[email protected]') { 
     transitive = true; 
    } 
} 
+0

你嘗試了'-dontwarn android.security **'加試着用'-dontoptimize'禁用優化,看看它是如何去 – ThanosFisherman

+0

它不起作用:/ –

+0

好吧試試這個:在你附加的gradle文件中,在你的'buildToolsVersion「23.0.0」'輸入下面的'useLibrary'org.apache.http.legacy''如果這個工作,我會寫關於如何和爲什麼這個工作的更詳細的答案 – ThanosFisherman

回答

18

我有同樣的問題。警告消息說:

如果您的代碼可以正常工作而沒有丟失的類,則可以使用'-twtwarn'選項禁止 警告。

因此,讓我們的建議:

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

對於我來說,這個固定的問題。但是,如果由於某種原因,您的代碼不無級工作正常,你可以做除了像這樣(未測試):

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

請注意,您所需要的-dontwarn線兩種方式。祝你好運!

+0

避免添加行到你的proguard,如果他們什麼都沒有用。維護類com.google.android.gms.internal。** {*; }只會告訴proguard不要混淆你提到的包中的類。它不會解決警告,因爲問題不在android.gms.internal.zzhu類中,而是從該類中引用的類android.security.NetworkSecurityPolicy。 Proguard無法找到該類的定義,因此會引發警告。如果你知道這個類(NetworkSecurityPolicy)應該在運行時存在,你可以使用dontwarn。 – MikeL

+0

另外我會檢查NetworkSecurityPolicy類沒有被混淆(因此proguard沒有看到它),並且可能會保留它。 – MikeL

5

對我來說,看起來這實際上是由Google意外地將AdMob包含在Play Services Analytics 8的依賴項中造成的。1: https://plus.google.com/+GoogleDevelopers/posts/HsSNWEQ6H4e

如果我排除play-services-ads模塊build.gradle我不android.security.NetworkSecurityPolicy得到Proguard的錯誤,我的發佈版本安裝和運行沒有任何問題(這是以前在啓動時發生崩潰與java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity,而調試版本被罰款的工作):

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

在Proguard的規則,你還需要:

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

由於這個職位德泰LS(儘管它不引用建立崩潰可言,只是APK大小): https://medium.com/google-developer-experts/warning-for-google-analytics-users-44b0096084e2#.4b3egtbxh

下面是這個項目我工作,其中包括承諾是解決這一問題的問題: https://github.com/OneBusAway/onebusaway-android/issues/342

編輯

用戶也報告說,這是在8.3解決了,這意味着你可以通過設置解決這個問題您build.gradle到:

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

我還沒有確認我自己。

+2

感謝您分享我的文章。 – tasomaniac

+0

此問題似乎在8.3.0中得到解決 – yuval

+0

@yuval謝謝,很高興知道!我認爲這可能是。我也會測試並確認自己。 –

0

對我來說,我只是同步了我所有的項目模塊以使用最近的播放服務庫,並且我能夠使用該軟件包。

我在我的build.gradle使用(所有模塊):

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' 

我用compile 'com.google.android.gms:play-services:7.5.0'

希望這可以幫助別人了。

1

當我最近升級我的播放服務依賴項時,發生了類似的錯誤。當您忽略更新與您使用的播放服務版本相對應的Firebase依賴項時,似乎會發生這種情況。

這裏是我的依賴關係的兩個版本分別爲:

錯誤版本的依賴

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' 

工作依賴 ``

版本
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' 

`` 谷歌似乎這些天,移動播放服務更新以及Firebase更新。希望這可以拯救一些靈魂。

-1

對於我來說,通過更換

編譯「com.google.android.gms工作:發揮服務-appindexing:9.8。0'

有:

compile 'com.google.android.gms:play-services:10.0.0' 
相關問題