Domanda

So I am attempting to use the Android SQLite Asset Helper to pre-package a database with my application and I have run into an issue. Here's a little bit of information to get started:

  • Using Android Studio (gradle)
  • I have modified build.grade to include compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
  • I have my database zipped (workoutsDatabase.sqlite.zip) in my src/main/assets/databases folder
  • my WorkoutsDatabaseHelper.java looks as follows (sorry for the bad formatting, the formatter is being stupid this morning!)

    import android.content.Context;
    
    import android.database.Cursor;
    
    import android.database.sqlite.SQLiteDatabase;
    
    import android.database.sqlite.SQLiteQueryBuilder;
    
    
    import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
    
    public class WorkoutsDatabaseHelper extends SQLiteAssetHelper {
    

    // All Static variables // Database Version private static final int DATABASE_VERSION = 1;

    // Database Name
    private static final String DATABASE_NAME = "workoutsDatabase.sqlite";
    
    
    
    public WorkoutsDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    

Can anyone see why this might be thinking that a .jar file is a zip? and also, is there anything else I am missing to get this working properly?

Here is the error:

Error:: error reading /Users/rdeckert/AndroidStudioProjects/MyPR/app/libs/android-sqlite-asset-helper.jar; cannot read zip file
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/19.0.3/dx --dex --output /Users/rdeckert/AndroidStudioProjects/MyPR/app/build/pre-dexed/debug/android-sqlite-asset-helper-295afb1e2c04cd27e606e7f0ffde55bd32716c79.jar /Users/rdeckert/AndroidStudioProjects/MyPR/app/libs/android-sqlite-asset-helper.jar
  Error Code:
    1
  Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:128)
        at java.util.zip.ZipFile.<init>(ZipFile.java:145)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:596)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
        at com.android.dx.command.dexer.Main.run(Main.java:230)
        at com.android.dx.command.dexer.Main.main(Main.java:199)
        at com.android.dx.command.Main.main(Main.java:103)
    1 error; aborting

I tried updating the Zip file (database) and that didnt do anything.

È stato utile?

Soluzione

Once I removed compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+' from the build.gradle it compiled and worked correctly.

Altri suggerimenti

I know I am late but once i also removed this line but this didnt help me, So what you need to do is:

Method 1: Try to clean your project in 'Build' Option.

Method 2: Clean and Rerun your project in 'RUN' Option.

Method 3: If above method didnt help you then restart you android Studio.

Medthod 4: Restart Your PC, this will surely removed the error.

You can use

    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top