问题
I am getting a ava.lang.NoClassDefFoundError: net/sqlcipher/CursorWindow
when trying to run my app using sqlicipher and proguard. The project works perfectly without proguard enabled. The first time I use sqlcipher to create a new db I get the error above. I have looked at another SO question that is seemingly identical, but I have tried the answers from that question and I'm still getting the error.
Android Proguard SqlCipher NoClassDefFoundError
Here is my entire proguard-properties
:
-libraryjars libs/commons-codec.jar
-libraryjars libs/guava-r09.jar
-libraryjars libs/httpmime-4.1.2.jar
-libraryjars libs/jsr305-2.0.2.jar
-libraryjars libs/libphonenumber-5.7.jar
-libraryjars libs/sqlcipher.jar
-keep class com.myandroidapp.** { *; }
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-dontobfuscate
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-dontwarn javax.annotation.**
-dontwarn android.app.**
-dontwarn android.support.**
-dontwarn android.view.**
-dontwarn android.widget.**
-dontwarn com.google.common.primitives.**
-dontwarn **CompatHoneycomb
-dontwarn **CompatHoneycombMR2
-dontwarn **CompatCreatorHoneycombMR2
-keepclasseswithmembernames class * {
native <methods>;
}
-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);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keep public class net.sqlcipher.** {
*;
}
-keep public class net.sqlcipher.database.** {
*;
}
Error message:
01-22 19:18:26.553: W/dalvikvm(18993): Exception thrown (Ljava/lang/NoSuchFieldError;) while throwing internal exception (Ljava/lang/NoSuchFieldError;)
01-22 19:18:26.553: E/Cursor(18993): Error locating fields
01-22 19:18:26.553: E/Cursor(18993): Can't find net/sqlcipher/database/SQLiteQuery
01-22 19:18:26.553: E/Cursor(18993): Can't find net/sqlcipher/database/SQLiteProgram
01-22 19:18:26.553: E/Cursor(18993): Can't find net/sqlcipher/database/SQLiteStatement
01-22 19:18:26.553: E/CursorWindow(18993): Can't find net/sqlcipher/CursorWindow
01-22 19:18:26.553: D/AndroidRuntime(18993): Shutting down VM
01-22 19:18:26.553: W/dalvikvm(18993): threadid=1: thread exiting with uncaught exception (group=0x41570c80)
: E/AndroidRuntime(18993): FATAL EXCEPTION: main
: E/AndroidRuntime(18993): Process: com.myandroidapp.androidapp, PID: 18993
: E/AndroidRuntime(18993): java.lang.NoClassDefFoundError: net/sqlcipher/CursorWindow
: E/AndroidRuntime(18993): at java.lang.Runtime.nativeLoad(Native Method)
: E/AndroidRuntime(18993): at java.lang.Runtime.doLoad(Runtime.java:421)
: E/AndroidRuntime(18993): at java.lang.Runtime.loadLibrary(Runtime.java:362)
: E/AndroidRuntime(18993): at java.lang.System.loadLibrary(System.java:526)
: E/AndroidRuntime(18993): at net.sqlcipher.database.SQLiteDatabase.loadLibs(Unknown Source)
: E/AndroidRuntime(18993): at net.sqlcipher.database.SQLiteDatabase.loadLibs(Unknown Source)
: E/AndroidRuntime(18993): at com.myandroidapp.androidapp.androidappDBAdapter.initializeDB(Unknown Source)
: E/AndroidRuntime(18993): at com.myandroidapp.services.CompleteService$androidappCompleteThread$2.onResponse(Unknown Source)
: E/AndroidRuntime(18993): at com.myandroidapp.services.CompleteService$androidappCompleteThread$2.onResponse(Unknown Source)
: E/AndroidRuntime(18993): at com.myandroidapp.androidapp.androidappHttpRequest.deliverResponse(Unknown Source)
: E/AndroidRuntime(18993): at com.myandroidapp.androidapp.androidappHttpRequest.deliverResponse(Unknown Source)
: E/AndroidRuntime(18993): at com.android.volley.i.run(Unknown Source)
: E/AndroidRuntime(18993): at android.os.Handler.handleCallback(Handler.java:733)
: E/AndroidRuntime(18993): at android.os.Handler.dispatchMessage(Handler.java:95)
: E/AndroidRuntime(18993): at android.os.Looper.loop(Looper.java:136)
: E/AndroidRuntime(18993): at android.app.ActivityThread.main(ActivityThread.java:5081)
: E/AndroidRuntime(18993): at java.lang.reflect.Method.invokeNative(Native Method)
: E/AndroidRuntime(18993): at java.lang.reflect.Method.invoke(Method.java:515)
: E/AndroidRuntime(18993): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
: E/AndroidRuntime(18993): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
: E/AndroidRuntime(18993): at dalvik.system.NativeStart.main(Native Method)
: E/AndroidRuntime(18993): Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteStatement
: E/AndroidRuntime(18993): ... 21 more
: E/AndroidRuntime(18993): Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteProgram
: E/AndroidRuntime(18993): ... 21 more
: E/AndroidRuntime(18993): Caused by: java.lang.NoClassDefFoundError: net/sqlcipher/database/SQLiteQuery
: E/AndroidRuntime(18993): ... 21 more
: E/AndroidRuntime(18993): Caused by: java.lang.NoSuchFieldError: no field with name='nHandle' signature='I' in class Lnet/sqlcipher/database/SQLiteCompiledSql;
: E/AndroidRuntime(18993): ... 21 more
回答1:
I think that the class was removed by the Proguard Shrinking tool.
Try to add the following parameter
-dontshrink
and tell me if it works.
I also saw that an attribute is missing in a protected class of Sqlcipher :
: E/AndroidRuntime(18993): Caused by: java.lang.NoSuchFieldError: no field with name='nHandle' signature='I' in class Lnet/sqlcipher/database/SQLiteCompiledSql;
Can you also try to keep protected classes from Sqlcipher ?
-keep class net.sqlcipher.** {
*;
}
P.S Is it regular that you have the option -dontobfuscate in your configuration ? Your application will not be obfuscated if you keep it.
回答2:
Try this:
-keep class net.sqlcipher.** { *; }
回答3:
In the Java build path, Order and Export, check the library so that it will be exported.
回答4:
Remove public from the below statements. Worked for me. :)
-keep class net.sqlcipher.** {
*;
}
-keep class net.sqlcipher.database.** {
*;
}
来源:https://stackoverflow.com/questions/21316699/getting-noclassdeffounderror-while-trying-to-use-proguard-and-sqlcipher-in-andro