Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何单独构建SQLite数据库并绑定到maven build中的android应用程序_Android_Maven_Ormlite - Fatal编程技术网

如何单独构建SQLite数据库并绑定到maven build中的android应用程序

如何单独构建SQLite数据库并绑定到maven build中的android应用程序,android,maven,ormlite,Android,Maven,Ormlite,我有一个单独的web服务来获取应用程序所需的数据(txt数据+下载图像的图像URL),这是我应用程序中唯一的服务,我在应用程序启动时调用此服务并设置SQLite数据库(使用ORMLite),一旦一切完成,用户可以进入主屏幕,因此,在下一次发布中,如果数据在数据库中,该服务将不会调用。到目前为止,一切正常 我的问题是如何在android应用程序之外构建这个SQLite DB,并将SQLite数据库文件捆绑到应用程序中;我正在使用maven构建android应用程序 我是否需要一个单独的androi

我有一个单独的web服务来获取应用程序所需的数据(txt数据+下载图像的图像URL),这是我应用程序中唯一的服务,我在应用程序启动时调用此服务并设置SQLite数据库(使用ORMLite),一旦一切完成,用户可以进入主屏幕,因此,在下一次发布中,如果数据在数据库中,该服务将不会调用。到目前为止,一切正常

我的问题是如何在android应用程序之外构建这个SQLite DB,并将SQLite数据库文件捆绑到应用程序中;我正在使用maven构建android应用程序

  • 我是否需要一个单独的android项目来调用web服务并构建SQLite DB,或者我可以使用java项目来构建SQLite DB

  • 如果我使用android项目,如何获取数据库文件

  • 我如何指示maven运行上述项目并将db文件复制到android应用程序

  • 我从一个maven项目开始,下面是我的pom xml文件的快照

     <dependencies>
      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
    
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2</version>
    </dependency>
    
    <dependency>
        <groupId>com.j256.ormlite</groupId>
        <artifactId>ormlite-core</artifactId>
        <version>4.41</version>
    </dependency>
    
    <dependency>
        <groupId>com.j256.ormlite</groupId>
        <artifactId>ormlite-jdbc</artifactId>
        <version>4.41</version>
    </dependency>
    
    <dependency>
          <groupId>org.xerial</groupId>
          <artifactId>sqlite-jdbc</artifactId>
          <version>3.6.16</version>
        </dependency>
    
      </dependencies>
    
    我的域对象

    @DatabaseTable
    public class Widget implements Comparable<Widget>{
    
        @DatabaseField(id = true)
        private String id = null;
    
        @DatabaseField
        private String title = null;
    ....More fileds.
    
        @ForeignCollectionField
        private ForeignCollection<WidgetAttribute> db_widget_attribute;
    
        @DatabaseField(canBeNull = true, foreign = true)
        private AdvancedSettings advanced_settings = null;
    ... Getters /setters....
    }
    
    @DatabaseTable
    public class WidgetAttribute {
    
        @DatabaseField(id = true)
        private String id = null;
    
        @DatabaseField
        private String value = null;
        ....More fileds.
    
        @DatabaseField(foreign=true,foreignAutoRefresh=true)
        private Widget widget;
        ... Getters /setters....
     }
    
    @DatabaseTable
    public class AdvancedSettings {
        @DatabaseField(id = true)
        private String id = null;
    
        public static final String  DB_COLUMN_SHOW_AS_TAB_BAR = "show_as_tab_bar"; 
    
        @DatabaseField
        private String show_as_tab_bar = null;
        ....More fileds
    
        @DatabaseField(canBeNull = true, foreign = true)
        private AdvancedSettingsImages advanced_settings_images = null;
    
       @DatabaseField(foreign=true,foreignAutoRefresh=true)
        private Widget widget;
    
        public String getId() {
            return id;
        }
            ... Getters /setters....
    }   
    
    @DatabaseTable
    public class AdvancedSettingsImages {
        @DatabaseField(generatedId=true)
        private int id;
    
         ....More fileds
    
        @DatabaseField(canBeNull = true, foreign = true)
        private AdvancedSettings advancedSettings = null;
    
        ... Getters /setters....
    
     }
    
    @DatabaseTable
    公共类小部件实现了可比较的{
    @数据库字段(id=true)
    私有字符串id=null;
    @数据库字段
    私有字符串title=null;
    …更多文件。
    @国外收藏场
    私有ForeignCollection db_widget_属性;
    @数据库字段(canBeNull=true,foreign=true)
    私有高级设置高级设置=空;
    …接受者/接受者。。。。
    }
    @数据库表
    公共类WidgetAttribute{
    @数据库字段(id=true)
    私有字符串id=null;
    @数据库字段
    私有字符串值=null;
    …更多文件。
    @数据库字段(foreign=true,foreignAutoRefresh=true)
    私有小部件;
    …接受者/接受者。。。。
    }
    @数据库表
    公共类高级设置{
    @数据库字段(id=true)
    私有字符串id=null;
    公共静态最终字符串DB_COLUMN_SHOW_AS_TAB_BAR=“SHOW_AS_TAB_BAR”;
    @数据库字段
    私有字符串show_as_tab_bar=null;
    …更多文件
    @数据库字段(canBeNull=true,foreign=true)
    私有高级设置图像高级设置图像=空;
    @数据库字段(foreign=true,foreignAutoRefresh=true)
    私有小部件;
    公共字符串getId(){
    返回id;
    }
    …接受者/接受者。。。。
    }   
    @数据库表
    公共类高级设置图像{
    @数据库字段(generatedId=true)
    私有int-id;
    …更多文件
    @数据库字段(canBeNull=true,foreign=true)
    私有AdvancedSettings AdvancedSettings=null;
    …接受者/接受者。。。。
    }
    
    当我运行应用程序时,我会在控制台中看到以下日志消息

    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.Widget with reflection 
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.WidgetAttribute with reflection 
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.AdvancedSettings with reflection 
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.AdvancedSettingsImages with reflection 
    
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'widget' 
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `widget` (`id` VARCHAR , `title` VARCHAR , `widget_type_id` VARCHAR , `app_xxx_id` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `position` VARCHAR , `group_widget` VARCHAR , `parent_id` VARCHAR , `image_link` VARCHAR , `advanced_settings_id` VARCHAR , `widgets_id` INTEGER NOT NULL , PRIMARY KEY (`id`) )  
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'widgetattribute' 
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `widgetattribute` (`id` VARCHAR , `value` VARCHAR , `attribute_type` VARCHAR , `name` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `image_link` VARCHAR , `widget_id` VARCHAR , PRIMARY KEY (`id`) )  
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'advancedsettings' 
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `advancedsettings` (`id` VARCHAR , `show_widget_on_home_screen` VARCHAR , `highlight_cell` VARCHAR , `hide_menu` VARCHAR , `show_as_tab_bar` VARCHAR , `icon_color` VARCHAR , `live_tile` VARCHAR , `text_color` VARCHAR , `vertical_alignment` VARCHAR , `horizontal_alignment` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `advanced_settings_images_id` INTEGER , `widget_id` VARCHAR , PRIMARY KEY (`id`) )  
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'advancedsettingsimages'
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `advancedsettingsimages` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `tab_bar_icon` VARCHAR , `tab_bar_icon_on_press` VARCHAR , `widget_icon` VARCHAR , `widget_icon_on_press` VARCHAR , `advancedSettings_id` VARCHAR )  
    
    
    java.sql.SQLException: Unable to run insert stmt on object 
    
        at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
        at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:124)
        at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:352)
        at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:306)
    
    Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
        at org.sqlite.DB.newSQLException(DB.java:374)
        at org.sqlite.DB.newSQLException(DB.java:378)
        at org.sqlite.DB.throwex(DB.java:365)
        at org.sqlite.NativeDB.prepare(Native Method)
        at org.sqlite.DB.prepare(DB.java:123)
        at org.sqlite.PrepStmt.<init>(PrepStmt.java:44)
        at org.sqlite.Conn.prepareStatement(Conn.java:403)
        at org.sqlite.Conn.prepareStatement(Conn.java:398)
        at org.sqlite.Conn.prepareStatement(Conn.java:382)
        at org.sqlite.Conn.prepareStatement(Conn.java:386)
        at com.j256.ormlite.jdbc.JdbcDatabaseConnection.insert(JdbcDatabaseConnection.java:147)
        at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:89)
        ... 4 more
    
    DEBUG[com.j256.ormlite.dao.DaoManager]为类com.xxx.domain.Widget创建了带有反射的dao
    DEBUG[com.j256.ormlite.dao.DaoManager]为类com.xxx.domain.widgettribute创建了带有反射的dao
    DEBUG[com.j256.ormlite.dao.DaoManager]为类com.xxx.domain.AdvancedSettings创建了带反射的dao
    调试[com.j256.ormlite.dao.DaoManager]为类com.xxx.domain.AdvancedSettingsImages创建了dao,并带有反射
    信息[com.j256.ormlite.table.TableUtils]创建表“小部件”
    INFO[com.j256.ormlite.table.TableUtils]执行的create table语句已更改0行:create table IF NOT EXISTS`widget`(`id`VARCHAR、`title`VARCHAR、`widget\u type\u id`VARCHAR、`app\u xxx\u id`VARCHAR、`created\u at`VARCHAR、`updated\u at`VARCHAR、`position`VARCHAR、`group\u widget`VARCHAR、`parent\u id`VARCHAR、`image\u link`VARCHAR、`advanced\u设置`VARCHAR、`widgets\u id`整数不为空,主键(`id`))
    信息[com.j256.ormlite.table.TableUtils]正在创建表“widgetattribute”
    INFO[com.j256.ormlite.table.TableUtils]执行的create table语句更改了0行:create table IF note existed`widgetattribute`(`id`VARCHAR,`value`VARCHAR,`attribute\u type`VARCHAR,`name`VARCHAR`created\u at`VARCHAR,`updated\u at`VARCHAR,`image\u link`VARCHAR,`widget\u id`VARCHAR,主键(`id`)
    信息[com.j256.ormlite.table.TableUtils]创建表“advancedsettings”
    INFO[com.j256.ormlite.table.TableUtils]执行的create table语句已更改0行:create table IF NOT EXISTS`advancedsettings`(`id`VARCHAR、`show`u widget`在主屏幕上`VARCHAR、`highlight`单元格`VARCHAR、`hide`菜单`VARCHAR、`show`作为标签`VARCHAR、`icon`颜色`VARCHAR、`live` tile`VARCHAR、`text`颜色`VARCHAR、`vertical`对齐`VARCHAR、`水平对齐`VARCHAR、`created`在`VARCHAR、updated`在`VARCHAR、advanced`设置`VARCHAR、高级图像`id`整数、,`widget_id`VARCHAR,主键(`id`)
    信息[com.j256.ormlite.table.TableUtils]创建表“advancedsettingsimages”
    INFO[com.j256.ormlite.table.TableUtils]执行的create table语句已更改0行:create table如果不存在`advancedsettingsimages`(`id`整型主键自动递增,`tab_-bar_-icon`VARCHAR,`tab_-bar_-icon_-on_-on-press`VARCHAR,`widget_-icon`VARCHAR,`widget_-icon-on-on-press`VARCHAR`VARCHAR,`advancedSettings
    java.sql.SQLException:无法在对象上运行insert stmt
    位于com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
    在com.j256.ormlite.stmt.MappedCreate.insert(MappedCreate.java:124)上
    位于com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:352)
    位于com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:306)
    原因:java.sql.SQLException:[SQLITE_ERROR]sql错误或缺少数据库(接近“)”:语法错误)
    位于org.sqlite.DB.newSQLException(DB.java:374)
    位于org.sqlite.DB.newSQLException(DB.java:378)
    位于org.sqlite.DB.throwex(DB.java:365)
    在org.sqlite.NativeDB.prepare(本机方法)
    位于org.sqlite.DB.prepare(DB.java:123)
    位于org.sqlite.prepsmt(prepsmt.java:44)
    位于org.sqlite.Conn.prepareStatement(Conn.java:403)
    在
    
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.Widget with reflection 
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.WidgetAttribute with reflection 
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.AdvancedSettings with reflection 
    DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.AdvancedSettingsImages with reflection 
    
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'widget' 
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `widget` (`id` VARCHAR , `title` VARCHAR , `widget_type_id` VARCHAR , `app_xxx_id` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `position` VARCHAR , `group_widget` VARCHAR , `parent_id` VARCHAR , `image_link` VARCHAR , `advanced_settings_id` VARCHAR , `widgets_id` INTEGER NOT NULL , PRIMARY KEY (`id`) )  
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'widgetattribute' 
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `widgetattribute` (`id` VARCHAR , `value` VARCHAR , `attribute_type` VARCHAR , `name` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `image_link` VARCHAR , `widget_id` VARCHAR , PRIMARY KEY (`id`) )  
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'advancedsettings' 
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `advancedsettings` (`id` VARCHAR , `show_widget_on_home_screen` VARCHAR , `highlight_cell` VARCHAR , `hide_menu` VARCHAR , `show_as_tab_bar` VARCHAR , `icon_color` VARCHAR , `live_tile` VARCHAR , `text_color` VARCHAR , `vertical_alignment` VARCHAR , `horizontal_alignment` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `advanced_settings_images_id` INTEGER , `widget_id` VARCHAR , PRIMARY KEY (`id`) )  
    INFO  [com.j256.ormlite.table.TableUtils] creating table 'advancedsettingsimages'
    INFO  [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `advancedsettingsimages` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `tab_bar_icon` VARCHAR , `tab_bar_icon_on_press` VARCHAR , `widget_icon` VARCHAR , `widget_icon_on_press` VARCHAR , `advancedSettings_id` VARCHAR )  
    
    
    java.sql.SQLException: Unable to run insert stmt on object 
    
        at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
        at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:124)
        at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:352)
        at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:306)
    
    Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
        at org.sqlite.DB.newSQLException(DB.java:374)
        at org.sqlite.DB.newSQLException(DB.java:378)
        at org.sqlite.DB.throwex(DB.java:365)
        at org.sqlite.NativeDB.prepare(Native Method)
        at org.sqlite.DB.prepare(DB.java:123)
        at org.sqlite.PrepStmt.<init>(PrepStmt.java:44)
        at org.sqlite.Conn.prepareStatement(Conn.java:403)
        at org.sqlite.Conn.prepareStatement(Conn.java:398)
        at org.sqlite.Conn.prepareStatement(Conn.java:382)
        at org.sqlite.Conn.prepareStatement(Conn.java:386)
        at com.j256.ormlite.jdbc.JdbcDatabaseConnection.insert(JdbcDatabaseConnection.java:147)
        at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:89)
        ... 4 more