尝试在Android中使用Proguard和SQLcipher时获取NoClassDefFoundError

 x深藏的爱x_402 发布于 2023-01-31 18:10

我正在ava.lang.NoClassDefFoundError: net/sqlcipher/CursorWindow尝试使用sqlicipher和proguard运行我的应用程序.该项目完美无需启用proguard.我第一次使用sqlcipher创建一个新的db我得到上面的错误.我看过另一个看似相同的问题,但我已经尝试了这个问题的答案,我仍然得到了错误.

Android Proguard SqlCipher NoClassDefFoundError

这是我的全部内容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 ;
}

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

-keepclasseswithmembers class * {
    public (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 ;
}

-keep public class net.sqlcipher.** {
    *;
}

-keep public class net.sqlcipher.database.** {
    *;
}

错误信息:

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

nbe_42.. 11

我认为这个课程被Proguard Shrinking工具删除了.

尝试添加以下参数

-dontshrink

并告诉我它是否有效.

我还看到Sqlcipher的受保护类中缺少一个属性:

: E/AndroidRuntime(18993): Caused by: java.lang.NoSuchFieldError: no field with name='nHandle' signature='I' in class Lnet/sqlcipher/database/SQLiteCompiledSql;

您是否也可以尝试将受保护的类保留在Sqlcipher中?

-keep class net.sqlcipher.** {
    *;
}

PS您的配置中是否定期选择-dontobfuscate?如果您保留它,您的应用程序将不会被混淆.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有