打包文件到APK安装包中

打包文件到APK安装包中

目的:将配置文件或SQLITE打包进APK中

1.首先,打开菜单 Project - Deployment

2.点击添加按钮,选择要添加的文件(文件最好放在工程目录中,这样,即使该工程在其他电脑上打开,也能找到该文件)

3.修改Remote Path:

    当开发Android程序时,Remote Path修改为 assetsinternal 

    当开发iOS程序时,Remote Path修改为 StartUpDocuments

Remote Path说明

Remote Path写入assetsinternal或assets就可以
其中
assetsinternal会把文件发布到TPath.GetDocumentsPath(也就是/data/data/.../files)目录下
assets会把文件发布到TPath.GetSharedDocumentsPath(也就是/mnt/sdcard/Android/data/.../files)目录下。

 

4.程序中使用文件的方法:

    首先,需要引用 System.IOUtils 文件,这样才能使用TPath类
 

    TPath.Combine(TPath.GetDocumentsPath,'a.htm')

    或

    TPath.GetDocumentsPath + PathDelim + 'a.htm'

    获取文件的绝对路径,然后就可以使用这个路径对文件进行操作了。

打包SQLITE

在fdconnection的beforconnect事件中填写如下代码:

procedure TForm1.FDConnection1BeforeConnect(Sender: TObject);

begin

FDConnection1.Params.Values['Database'] :=      TPath.Combine(TPath.GetDocumentsPath, 'test.s3db');

end;

 

原文地址:https://www.cnblogs.com/hnxxcxg/p/12017484.html