Android LitePal的配置

1.首先我们需要将LitePal的jar包引入到项目当中,可以点击这里查看LitePal的最新版本。下载并将src.jar文件引入。

引入第三方库流程:https://www.cnblogs.com/landiljy/p/6881851.html
(引入成功后会自动在dependencies闭包中添加依赖,所以不需要操作,多些的complie反而会导致apk生成错误)

2.然后在项目的assets目录(如果没有自行创建)下面新建一个litepal.xml文件,并将以下代码(在litepal的网站上也有)拷贝进去:

<?xml version="1.0" encoding="utf-8"?>
<litepal>
    <!--
        Define the database name of your application.
        By default each database name should be end with .db.
        If you didn't name your database end with .db,
        LitePal would plus the suffix automatically for you.
        For example:
        <dbname value="demo" />
    -->
    <dbname value="CourseManager" />

    <!--
        Define the version of your database. Each time you want
        to upgrade your database, the version tag would helps.
        Modify the models you defined in the mapping tag, and just
        make the version value plus one, the upgrade of database
        will be processed automatically without concern.
            For example:
        <version value="1" />
    -->
    <version value="1" />

    <!--
        Define your models in the list with mapping tag, LitePal will
        create tables for each mapping class. The supported fields
        defined in models will be mapped into columns.
        For example:
        <list>
        </list>
    -->
    <list>
        <mapping class = "com.example.renjian.test.Notice"/>
    </list>

    <!--
        Define where the .db file should be. "internal" means the .db file
        will be stored in the database folder of internal storage which no
        one can access. "external" means the .db file will be stored in the
        path to the directory on the primary external storage device where
        the application can place persistent files it owns which everyone
        can access. "internal" will act as default.
        For example:
        <storage value="external" />
    -->

</litepal>

3.接下来在AndroidManifest.xml中的application标签配置以下代码:

android:name="org.litepal.LitePalApplication"
发布了8 篇原创文章 · 获赞 6 · 访问量 1171

猜你喜欢

转载自blog.csdn.net/weixin_44762713/article/details/98481064