我使用批处理操作制作了一个联系人应用程序,如下所示
final public class BatchOperation {
private final String TAG = "BatchOperation";
private final ContentResolver mResolver;
// List for storing the batch mOperations
private final ArrayList<ContentProviderOperation> mOperations;
public BatchOperation(Context context, ContentResolver resolver) {
mResolver = resolver;
mOperations = new ArrayList<ContentProviderOperation>();
}
public int size() {
return mOperations.size();
}
public void add(ContentProviderOperation cpo) {
mOperations.add(cpo);
}
public Uri execute() {
Uri result = null;
if (mOperations.size() == 0) {
return result;
}
// Apply the mOperations to the content provider
try {
ContentProviderResult[] results = mResolver.applyBatch(
ContactsContract.AUTHORITY, mOperations);
if ((results != null) && (results.length > 0))
result = results[0].uri;
} catch (final OperationApplicationException e1) {
Log.e(TAG, "storing contact data failed", e1);
} catch (final RemoteException e2) {
Log.e(TAG, "storing contact data failed", e2);
}
mOperations.clear();
return result;
}
在调试模式中一切正常但在我以发布模式签署我的应用后,我遇到了这个问题
E/BatchOperation﹕ storing contact data failed
java.lang.ClassCastException: a cannot be cast to android.content.ContentProviderOperation
at android.content.ContentProviderProxy.applyBatch(ContentProviderNative.java:479)
at android.content.ContentProviderClient.applyBatch(ContentProviderClient.java:227)
at android.content.ContentResolver.applyBatch(ContentResolver.java:951)
在这一行
ContentProviderResult[] results = mResolver.applyBatch(ContactsContract.AUTHORITY,
mOperations);
这是我的proguard文件
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-printmapping mapping.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''
-dontwarn com.actionbarsherlock.**
-dontwarn org.apache.**
-dontwarn com.commonsware.**
-dontwarn freemarker.**
-dontwarn ezvcard.**
-keep class org.apache.** { *; }
-keep class android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep class ezvcard.** { *; }
-keep class com.fasterxml.jackson.** { *; }
感谢您的阅读,
答案 0 :(得分:1)
当这种事情发生时,我总是向我的开发者问一个问题......你在使用Proguard吗? 尝试禁用Proguard并编译进入发布模式进行测试。还可以使用
删除优化-dontoptimize
同时检查您的内容提供商是否保留了类似
的内容-keep public class * extends android.content.ContentProvider
答案 1 :(得分:0)
啊,我发现了Proguard混淆器android.content.ContentProviderOperation;
类。
只需添加此-keep class android.content.** { *; }
一切正常=)