2016-04-26 108 views
1

我正在使用SQLCipher作爲db在我的項目中。我的應用程序在OS棒棒糖及以上版本的手機中運行成功。但從操作系統4.4.4及以下的問題。我使用SQLCipher jar文件(不是最新的)。在應用程序啓動,我收到以下錯誤:致命異常:main java.lang.VerifyError:SQLCipher中的net/sqlcipher/database/SQLiteDatabase

04-26 12:50:04.940 18598-18598/packageName E/dalvikvm: Could not find class 'net.sqlcipher.database.SQLiteCompiledSql', referenced from method net.sqlcipher.database.SQLiteDatabase.deallocCachedSqlStatements 
04-26 12:50:04.940 18598-18598/packageName E/dalvikvm: Could not find class 'net.sqlcipher.database.SQLiteStatement', referenced from method net.sqlcipher.database.SQLiteDatabase.getPragmaVal 
04-26 12:50:04.945 18598-18598/packageName E/dalvikvm: Could not find class 'net.sqlcipher.database.SQLiteDatabase$SyncUpdateInfo', referenced from method net.sqlcipher.database.SQLiteDatabase.markTableSyncable 
04-26 12:50:04.955 18598-18627/packageName E/GMPM: Uploading is not possible. App measurement disabled 
04-26 12:50:04.955 18598-18598/packageName E/AndroidRuntime: FATAL EXCEPTION: main 
java.lang.VerifyError: net/sqlcipher/database/SQLiteDatabase 
at packageName.database.PassbookContentProvider.onCreate(PassbookContentProvider.java:538) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:1214) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:1189) 
at android.app.ActivityThread.installProvider(ActivityThread.java:5119) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4725) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4665) 
at android.app.ActivityThread.access$1400(ActivityThread.java:159) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:5419) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) 
at dalvik.system.NativeStart.main(Native Method) 

應用程序/的build.gradle

apply plugin: 'com.android.application' 
apply plugin: 'me.tatarka.retrolambda' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    def isSMSAuthEnabled = "false" 

    defaultConfig { 
    applicationId "packageName" 
    minSdkVersion 16 
    targetSdkVersion 22 
    versionCode 6 
    versionName "v3.0" 

    multiDexEnabled true 
    } 
    buildTypes { 
    debug { 
     resValue "bool", "enableSMSAuth", isSMSAuthEnabled 
    } 

    release { 
     minifyEnabled true 
     resValue "bool", "enableSMSAuth", isSMSAuthEnabled 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
    } 
    compileOptions { 
    sourceCompatibility JavaVersion.VERSION_1_8 
    targetCompatibility JavaVersion.VERSION_1_8 
    } 
    dexOptions { 
    javaMaxHeapSize "4g" 
    } 
    packagingOptions { 
    exclude 'META-INF/services/javax.annotation.processing.Processor' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    } 
} 

dependencies { 
    testCompile 'junit:junit:4.12' 
    compile files('libs/PDFjet.jar') 
    compile files('libs/guava-r09.jar') 
    compile files('libs/sqlcipher.jar') 

    compile('de.keyboardsurfer.android.widget:crouton:[email protected]') { 
    exclude group: 'com.google.android', module: 'support-v4' 
    } 



    // sqlcipher 
    // compile 'net.zetetic:android-database-sqlcipher:[email protected]' 

    compile('com.mikepenz:materialdrawer:[email protected]') { 
    transitive = true 
    } 

    // Because RxAndroid releases are few and far between, it is recommended to 
    // explicitly depend on RxJava's latest version for bug fixes and new features. 

    compile 'com.android.support:appcompat-v7:23.2.1' 
    compile 'com.android.support:design:23.2.1' 
    compile 'com.google.code.gson:gson:2.4' 
    compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.2' 
    compile 'com.shamanland:fab:0.0.6' 
    compile 'com.android.support:recyclerview-v7:23.2.1' 
    compile 'com.android.support:cardview-v7:23.2.1' 
    compile 'com.squareup.retrofit:retrofit:1.9.0' 
    compile 'com.squareup.okhttp:okhttp:2.4.0' 
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0' 
    compile 'de.hdodenhof:circleimageview:2.0.0' 
    compile 'com.flipboard:bottomsheet-core:1.5.0' 
    compile 'com.flipboard:bottomsheet-commons:1.5.0' 
    compile 'com.github.PhilJay:MPAndroidChart:v2.2.2' 
    compile 'io.reactivex:rxandroid:1.1.0' 
    compile 'io.reactivex:rxjava:1.1.0' 
    compile 'com.bignerdranch.android:expandablerecyclerview:2.0.4' 
    compile 'com.borax12.materialdaterangepicker:library:1.6' 
    compile 'com.google.android.gms:play-services:8.4.0' 
} 

contentProvider.java

@Override public boolean onCreate() { 
    String password = null; 
    SQLiteDatabase db = null; 

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); 
    try { 
     if (mOpenHelper == null) mOpenHelper = new BOBDatabaseOpenHelper(getContext()); 
     SQLiteDatabase.loadLibs(getContext()); 

     if (preferences.contains(Constants.OLD_USER_PIN_SET)) { 
     if (preferences.contains(Constants.REKEY) && preferences.getBoolean(Constants.REKEY, 
      true)) { 
      password = getPassword(); 
     } else { 
      password = getOldPassword(); 
     } 
     } else { 
     password = getPassword(); 
     } 
     if (password != null) db = mOpenHelper.getWritableDatabase(password); 
    } catch (SQLiteException e) { 
     e.printStackTrace(); 
    } 
    return db != null; 
    } 

誤差在該位置中的代碼發生

SQLiteDatabase.loadLibs(getContext()); 

我已經做了足夠的研究,但無法解決問題。請幫助我。謝謝。

回答

0

最後,大量的研究後,我得到了解決我的問題。問題開始時,我添加

compile 'com.google.android.gms:play-services:8.4.0' 

地圖在我的項目。這是沒有必要的。當我添加這個時,我得到一個錯誤,說方法計數超過了64K的限制。所以我在app/build.gradle 仍然有一些錯誤添加

`multiDexEnabled true` 

。當我搜查我必須添加

dexOptions { 
    javaMaxHeapSize "4g" 
    } 

into app/build.gradle。 ,棒棒糖和OS以上的手機沒有更多的錯誤。 但對於其他人,我正在得到上述問題。

所以我固定它通過改變

compile 'com.google.android.gms:play-services:8.4.0' 

compile 'com.google.android.gms:play-services-location:8.4.0' 
compile 'com.google.android.gms:play-services-maps:8.4.0' 
compile 'com.google.android.gms:play-services-appindexing:8.4.0' 

所以didnt超過64K的限制的方法。問題解決了。感謝大家爲你的時間。

0

聽起來好像本地庫可能不包含在您的版本中。最簡單的解決方案,也許你只需要使用AAR分佈,我們還提供:

compile 'net.zetetic:android-database-sqlcipher:[email protected]'

+0

但它仍然無法正常工作。給我同樣的錯誤。 –

-1

如果你能刪除:

multiDexEnabled true 
+0

我解決了它。我已經在上面發佈了它。謝謝 –

1

在我的情況下,刪除multidex並不實際,但找到了使用gradle的multiDexKeepFile屬性的解決方案。當您違反64K方法限制時,這會將指定的類推入第一個dex中。

app/build.gradle,指向一個multiDexKeepFile:

// Enabling multidex support. 
multiDexEnabled true 
multiDexKeepFile file('multidex.keep') 

而且在保持文件中,指定我的情況下,你需要包括在第一DEX的班,我的內容提供商和sqlcipher的SQLiteDatabase:

com/myapp/android/database/provider/MyContentProvider.class 
net/sqlcipher/database/SQLiteDatabase.class 

這樣可以避免在物理S3 mini和Nexus 4虛擬設備(都是api 16,都在修復之前崩潰)發生崩潰。

相關問題