1

SQLCipher在我的项目中使用数据库。我的应用程序在具有 OS lollipop 及更高版本的手机中成功运行。但有来自 OS 4.4.4 及更低版本的问题。我正在使用 SQLCipher jar 文件(不是最新的)。在应用程序启动时,我收到以下错误:

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:1.8.5@aar') {
    exclude group: 'com.google.android', module: 'support-v4'
  }



  // sqlcipher
  //  compile 'net.zetetic:android-database-sqlcipher:3.3.1-2@aar'

  compile('com.mikepenz:materialdrawer:5.1.2@aar') {
    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'
}

内容提供者.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());

我已经做了足够的研究,但无法解决问题。请帮助我。谢谢。

4

4 回答 4

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,都在修复之前崩溃了)。

于 2016-10-07T12:01:38.517 回答
0

听起来好像本地库可能不包含在您的构建中。最简单的解决方案可能是您只使用我们提供的 AAR 发行版:

compile 'net.zetetic:android-database-sqlcipher:3.4.0@aar'

于 2016-04-27T13:55:00.980 回答
0

最后,经过大量研究,我找到了解决问题的方法。我添加时问题开始了

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

用于我项目中的地图。这是不必要的。当我添加这个时,我得到一个错误,说方法计数超过了 64K 限制。所以我加了

`multiDexEnabled true` 

在我app/build.gradle 仍然有一些错误。当我搜索时,我必须添加

 dexOptions {
    javaMaxHeapSize "4g"
  }

进入app/build.gradle. 并且具有棒棒糖及以上操作系统的手机不再出现错误。但对其他人来说,我遇到了上述问题。

所以我通过改变来修复它

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'

所以这些方法没有超过64K的限制。问题就解决了。感谢大家的时间。

于 2016-05-03T12:12:30.067 回答
-1

如果可以删除:

multiDexEnabled true
于 2016-05-03T05:35:33.733 回答