Tôi có một ứng dụng dựa trên Android đang kết nối với Máy ứng dụng của Google bằng dịch vụ Rest, ứng dụng hoạt động hoàn hảo cho đến khi nó bị che khuất thông qua ProGuard trước khi phát hành.ProGuard - org.codehaus.jackson.map.JsonMappingException: Không có hàm tạo phù hợp nào được tìm thấy cho loại
Các lỗi được báo cáo trong LogCat khi chạy ứng dụng khó hiểu là:
Unable to convert a [application/json,UTF-8] representation into an object of
class com.enterprisemk.android.bcw.bincollection.WasteCollectionAreasContainer
org.codehaus.jackson.map.JsonMappingException: No suitable constructor found
for type [simple type, class
com.enterprisemk.android.bcw.bincollection.WasteCollectionAreasContainer]:
can not instantiate from JSON object (need to add/enable type information?)
Tôi đã sau trong Proguard-project.txt tôi file:
-keepattributes *Annotation*,EnclosingMethod
-keep public class org.w3c.** {public private protected *;}
-dontwarn org.w3c.**
-keep public class org.joda.time.** {public private protected *;}
-dontwarn org.joda.time.**
-keep public class org.restlet.** { *; }
-dontwarn org.restlet.**
-keep public class org.codehaus.** { *; }
-dontwarn org.codehaus.**
-keepattributes Signature
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
Và lớp học của tôi lỗi đề cập đến trông giống như:
public class WasteCollectionAreasContainer {
public List<WasteCollectionAreas> wasteCollectionAreasList;
public List<WasteCollectionAreas> getWasteCollectionAreasList() {
return wasteCollectionAreasList;
}
public void setWasteCollectionAreasist(List<WasteCollectionAreas> wasteCollectionAreasList) {
this.wasteCollectionAreasList = wasteCollectionAreasList;
}
public WasteCollectionAreasContainer() {
wasteCollectionAreasList = new ArrayList<WasteCollectionAreas>();
}
@JsonCreator
public WasteCollectionAreasContainer(List<WasteCollectionAreas> wasteCollectionAreasList) {
this.wasteCollectionAreasList = wasteCollectionAreasList;
}
}
Để nhắc lại trước khi obfuscation thông qua ProGuard ứng dụng hoạt động hoàn hảo.
Có ai giúp tôi giải quyết vấn đề này không?
một số thời gian progaurd loại bỏ một số lớp khỏi đường dẫn xây dựng các dự án thư viện đặc biệt. – Ankit
Âm thanh như Proguard có thể đã xóa hàm tạo mặc định, không được tham số hóa cho 'WasteCollectionAreasContainer'. Lớp đó có quá trình khởi tạo quá tải không? Có thể Proguard đang loại bỏ hàm tạo mặc định * vì * có quá tải * và * nó cho rằng hàm tạo mặc định không được sử dụng ở bất kỳ đâu - điều đó có thể xảy ra vì Proguard không thể phát hiện Jackson thực sự sử dụng/yêu cầu một hàm tạo mặc định cho POJO trong thời gian chạy. –
MH - điều này đặt tôi đi đúng hướng để khắc phục sự cố - cảm ơn –