6

Gần đây tôi đã chuyển từ Eclipse sang Android Studios. Tôi đã có ứng dụng của tôi bằng cách sử dụng Proguard qua eclipse và bây giờ mà tôi đã di chuyển qua tôi nhận được các lỗi sau đây.Dịch vụ của Google Play với Proguard trong Android Studio

Lỗi:

ProGuard: [myApp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced field 'int auth_client_availability_notification_title' in class com.google.android.gms.R$string 
ProGuard: [myApp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced field 'int auth_client_play_services_err_notification_msg' in class com.google.android.gms.R$string 
ProGuard: [myApp] Warning: com.google.android.gms.auth.GoogleAuthUtil: can't find referenced field 'int auth_client_requested_by_msg' in class com.google.android.gms.R$string 
ProGuard: [myApp] Warning: com.squareup.picasso.OkHttpLoader: can't find referenced class com.squareup.okhttp.OkHttpClient 
ProGuard: [myApp] Warning: com.squareup.picasso.OkHttpLoader: can't find referenced class com.squareup.okhttp.HttpResponseCache 
ProGuard: [myApp]  You should check if you need to specify additional program jars. 
ProGuard: [myApp] Warning: there were 9 unresolved references to classes or interfaces. 
ProGuard: [myApp]   You may need to specify additional library jars (using '-libraryjars'). 
ProGuard: [myApp] Warning: there were 3 unresolved references to program class members. 
ProGuard: [myApp]   Your input classes appear to be inconsistent. 
ProGuard: [myApp]   You may need to recompile them and try again. 
ProGuard: [myApp]   Alternatively, you may have to specify the option 
ProGuard: [myApp]   '-dontskipnonpubliclibraryclassmembers'. 
ProGuard: [myApp] java.io.IOException: Please correct the above warnings first. 
ProGuard: [myApp] at proguard.Initializer.execute(Initializer.java:321) 
ProGuard: [myApp] at proguard.ProGuard.initialize(ProGuard.java:211) 
ProGuard: [myApp] at proguard.ProGuard.execute(ProGuard.java:86) 
ProGuard: [myApp] at proguard.ProGuard.main(ProGuard.java:492) 

Proguard file:

# This is a configuration file for ProGuard. 
# http://proguard.sourceforge.net/index.html#manual/usage.html 

-dontusemixedcaseclassnames 
-dontskipnonpubliclibraryclasses 
-verbose 

# Optimization is turned off by default. Dex does not like code run 
# through the ProGuard optimize and preverify steps (and performs some 
# of these optimizations on its own). 
-dontoptimize 
-dontpreverify 
-dontshrink 

# If you want to enable optimization, you should include the 
# following: 
# -optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/* 
# -optimizationpasses 5 
# -allowaccessmodification 
# 
# Note that you cannot just include these flags in your own 
# configuration file; if you are including this file, optimization 
# will be turned off. You'll need to either edit this file, or 
# duplicate the contents of this file and remove the include of this 
# file from your project's proguard.config path property. 

-keepattributes *Annotation* 
-keep public class * extends android.app.Activity 
-keep public class * extends android.app.Application 
-keep public class * extends android.app.Service 
-keep public class * extends android.content.BroadcastReceiver 
-keep public class * extends android.content.ContentProvider 
-keep public class * extends android.app.backup.BackupAgent 
-keep public class * extends android.preference.Preference 
-keep public class * extends android.support.v4.app.Fragment 
-keep public class * extends android.app.Fragment 
-keep public class com.android.vending.licensing.ILicensingService 

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native 
-keepclasseswithmembernames class * { 
     native <methods>; 
} 

-keep public class * extends android.view.View { 
     public <init>(android.content.Context); 
     public <init>(android.content.Context, android.util.AttributeSet); 
     public <init>(android.content.Context, android.util.AttributeSet, int); 
     public void set*(...); 
} 

-keepclasseswithmembers class * { 
     public <init>(android.content.Context, android.util.AttributeSet); 
} 

-keepclasseswithmembers class * { 
     public <init>(android.content.Context, android.util.AttributeSet, int); 
} 

-keepclassmembers class * extends android.app.Activity { 
    public void *(android.view.View); 
} 

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations 
-keepclassmembers enum * { 
     public static **[] values(); 
     public static ** valueOf(java.lang.String); 
} 

-keep class * implements android.os.Parcelable { 
    public static final android.os.Parcelable$Creator *; 
} 

-keep class com.google.android.gms.maps.model.LatLng { *; } 

-keepclassmembers class **.R$* { 
     public static <fields>; 
} 

# The support library contains references to newer platform versions. 
# Don't warn about those in case this app is linking against an older 
# platform version. We know about them, and they are safe. 
-dontwarn android.support.** 

#Needed by google-api-client to keep generic types and @Key annotations accessed via reflection 
-keepclassmembers class * { 
    @com.google.api.client.util.Key <fields>; 
} 

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault,*Annotation* 

-dontwarn sun.misc.Unsafe 

#ActionBarSherlock 
-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; } 

-keepattributes *Annotation* 

#My android stuff 
-keep class javax.annotation.Nullable 
-keep class org.apache.http.** { *; } 
-dontwarn org.apache.http.** 

#PDF stuff 
-keep class net.sf.andpdf.crypto.** { *; } 
-dontwarn net.sf.andpdf.crypto.** 

#Google Analytics 
-keep public class com.google.** {*;} 

#Otto 
-keepclassmembers class ** { 
     @com.squareup.otto.Subscribe public *; 
     @com.squareup.otto.Produce public *; 
} 

#Google Play service 
-keep class * extends java.util.ListResourceBundle { 
     protected Object[][] getContents(); 
} 

#Hockey 
-renamesourcefileattribute SourceFile 
-keepattributes SourceFile,LineNumberTable 

-keep public class javax.net.ssl.** 
-keepclassmembers public class javax.net.ssl.** { 
    *; 
} 

-keep public class org.apache.http.** 
-keepclassmembers public class org.apache.http.** { 
    *; 
} 

-keepclassmembers class net.hockeyapp.android.UpdateFragment { 
    *; 
} 

#Butter Knife 
-dontwarn butterknife.Views$InjectViewProcessor 
-keepclassmembers class **$$ViewInjector {*;} 
+0

tương tự: http://stackoverflow.com/questions/18646899/proguard-cant-find-referenced-class-com-google-android-gms-r – trante

Trả lời

2

Tôi đã kết thúc việc đưa vào các dòng sau, để Proguard ngừng cảnh báo tôi. Bản dựng vẫn chạy như mong đợi.

-dontwarn com.google.android.gms.auth.GoogleAuthUtil 
-dontwarn com.squareup.picasso.OkHttpLoader 
+2

Bạn thực sự phải chấp nhận câu trả lời khác và có lẽ đã thêm nhận xét về dòng phụ bạn đã thêm vào. – howettl

+1

Cá nhân tôi cố gắng sử dụng các ký tự đại diện để bỏ qua các cảnh báo càng ít càng tốt. Tôi đồng ý rằng câu trả lời của Marco W. là một câu trả lời hay, và tôi đã bình chọn nó. Tuy nhiên mã mà tôi đang sử dụng được cung cấp trong câu trả lời của tôi, đây là lý do tại sao tôi đã chấp nhận mã đó làm câu trả lời cho câu hỏi của tôi. – drspaceboo

18

Đối với thư viện "Picasso", bạn chỉ cần có để thêm video này cấu hình ProGuard của bạn:

-dontwarn com.squareup.okhttp.** 

Đây là bởi vì "Picasso" có một thư viện tùy chọn là ca "OkHttp". Điều này không được bao gồm, nhưng cũng không cần thiết.

Đối với Dịch vụ của Google Play, có vẻ như có sự không thống nhất với thư viện. Bạn nên cập nhật các tệp thư viện của mình và làm sạch dự án.

+0

được thư viện sử dụng cái gì? Hy vọng nó sẽ không gây ra bất kỳ ClassNotFoundExceptions –

+0

OkHttp là một khách hàng HTTP thay thế, mà _can_ được sử dụng thay vì Android hoặc Java được xây dựng trong những người thân hay không. Vì vậy, bạn chắc chắn không cần nó và nó sẽ không gây ra bất kỳ 'ClassNotFoundExceptions'. Tôi đang sử dụng Picasso mà không có OkHttp. Thông tin thêm về OkHttp: http://corner.squareup.com/2013/05/announcing-okhttp.html – caw