1. 程式人生 > >Gradle build報錯 Please correct the above warnings first解決方案

Gradle build報錯 Please correct the above warnings first解決方案

                     

你也可以檢視我的其他同類文章,也會讓你有一定的收貨

問題描述:

在編譯的時候,出現了下面的錯誤提示

Warning: there were 2 unresolved references to library class members.         You probably need to update the library versions.         Alternatively, you may have to specify the option          '-dontskipnonpubliclibraryclassmembers'.         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.:app:transformClassesAndResourcesWithProguardForRelease FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'
. java.io.IOException: Please correct the above warnings first.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

分析:

上面提示編譯過程中出現了warning,要求修復,所以停止了編譯。

按照上面的提示在混淆配置檔案proguard-rules.pro中增加-dontskipnonpubliclibraryclassmembers項,也不會起作用。

只能按上面提示尋找warings,如下Log中的中間兩行Waring:

Note: the configuration refers to the unknown class 'com.alipay.mobile.security.senative.APSE'
Warning: com.baidu.platform.comapi.map.e: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMathWarning: com.tencent.connect.avatar.c: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMathNote: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
  • 1
  • 2
  • 3
  • 4

中間兩行Warning是分別使用了百度地圖的jar包和QQ第三方登入的jar包,其中使用了FloatMath.sqrt()這個方法後,編譯時找不到,原因是使用了android 6.0的jar包去編譯。通過檢視原始碼,發現原始碼裡面有這個方法的實現,但反編譯SDK中的android.jar時,發現裡面沒有實現,坑!

之前一直沒有使用android 23編譯程式碼,現在專案要相容6.0,就使用了6.0的編譯環境,結果就出現了這樣的錯。唉,各種坑啊!

解決方案。

在proguard-rules.pro檔案中增加如下所示的配置:

-dontwarn com.baidu.**-dontwarn com.tencent.**
  • 1
  • 2

以後遇上這種waring,都可以這樣做,-dontwarn是混淆引數,com.xxx是包名,也就是忽略這個包名下面的waring。

 

關注我的公眾號,輕鬆瞭解和學習更多技術   這裡寫圖片描述