找不到 ormlite 配置文件

Can't find ormlite config file

我正在尝试在我的 Android Studio 项目上安装 ORMlite,但我无法获取 R.raw.ormlite_config 文件,我发现了这个:https://github.com/stephanenicolas/ormlite-android-gradle-plugin 但仍然无法正常工作.. .

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath 'com.github.stephanenicolas.ormgap:ormgap-plugin:1.0.12'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}


apply plugin: 'com.android.application'
apply plugin: 'ormgap'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "..."
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 12
        versionName "1.2.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        repositories {
            maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:recyclerview-v7:23.0.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.j256.ormlite:ormlite-android:5.0'
    compile files('libs/ksoap2-android-assembly-3.6.1-jar-with-dependencies.jar')
}

对于我的 DataHelper:

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {


    private static final int DATABASE_VERSION = 4;
    private static final String DATABASE_NAME = "solutis.db";


    private Dao<Demandes, Integer> simpleDao = null;
    private RuntimeExceptionDao<Demandes, Integer> simpleRuntimeDao = null;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION, android.R.raw.ormlite_config);
    }


    @Override
    public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource){

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {

    }

}

为什么需要这个文件?你可以把这个加到
gradle.. compile 'com.j256.ormlite:ormlite-core:4.48' compile 'com.j256.ormlite:ormlite-android:4.48' 并开始使用 db.

public class OrmLiteDbHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "Database_db";
private static final int DATABASE_VERSION = 1;
public SQLiteDatabase sqLiteDatabase;
private Context mContext;

public OrmLiteDbHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    this.mContext = mContext;
    try {
        sqLiteDatabase = getWritableDatabase();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
   @Override
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
    sqLiteDatabase = database;
    try {

        TableUtils.createTable(connectionSource, TableSet.class);

    } catch (SQLException e) {
        e.printStackTrace();
    }
}

 @Override
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource,
                      int oldVersion, int newVersion) {
try {
TableUtils.dropTable(connectionSource, TableSet.class, false);
onCreate(database, connectionSource);}catch (Exception e){  e.printStackTrace();}

}

You will then need to create your database using the ORMLite config file that will be generated during your build (note : you first need to boostrap the system, get a file generated, then reference it.)

参考文档 Link : http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_4.html#Config-Optimization

ORMLite supports the loading of the data configurations from a text configuration file. When a DAO is created, these configurations will be used, removing the need for any annotation method calls entirely.

  1. The OrmLiteConfigUtil utility class writes a ormlite_config.txt configuration file in the raw resource folder res/raw/ormlite_config.txt. You will need to extend this class into your own project along side your DatabaseHelper class. It should look something like:
public class DatabaseConfigUtil extends OrmLiteConfigUtil {
  public static void main(String[] args) throws Exception {
    writeConfigFile("ormlite_config.txt");
  }
}