litepal 3.0 配置教程

1. 在 官網 下載最新的src.jar包

2. 在項目中導入jar包 

 

3. 注意是在moudul的build.gradle裏面添加依賴 , 不是在project裏面的build.gradle裏面添加 , 當時我就在這裏卡了好久....

java 就加 

dependencies {
    implementation 'org.litepal.android:java:3.0.0'
}

kotlin就加

dependencies {
    implementation 'org.litepal.android:java:3.0.0'
}

 

4. 在這個位置添加一個litepal.xml文件 , 如果沒有assets文件夾就手動新建一個

5. 內容 : 

<?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="BookStore" />

    <!--
    	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>
    		<mapping class="com.test.model.Reader" />
    		<mapping class="com.test.model.Magazine" />
    	</list>
    -->
    <list>
    </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>

6. 最後在Androidmanifest.xml文件中添加這句就OK了

android:name="org.litepal.LitePalApplication"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章