To reduce package size, you can change the required so libraries and model resources to download online, only need to download these files before SDK initialization. For filters and dynamic effect resources, it is advisable to download one when in use upon user click.
Demo Project: TEBeauty_Download_Example
Clone the demo project from GitHub, configure and run TEBeauty_Download_Example according to TEBeauty_Download_Example/readme document to learn about the overall process of dynamic Download.
Downloading SO Libraries and Model Resources
If You Reuse the Download Code in Demo
If You Do the Download Yourself
1. Copy the code under the directory com.tencent.demo.download of the demo project to your project.
2. Download SDK, decompress it, then find the .zip format compression package in the "SDK" directory, decompress it again, and you will see the following files:
3. Upload download_assets.zip, arm64-v8a.zip, and armeabi-v7a.zip to your server to get the download links. Calculate the MD5 of these 3 zip files. Fill the download links and MD5 values into the corresponding constants in ResDownloadConfig.java.
4. Refer to the code in TEMenuActivity.java, use ResDownloadUtil.getValidLibsDirectory to check whether the so library has been downloaded. If not, call ResDownloadUtil.checkOrDownloadFiles to start download. After download success, get the so library path sdkLibraryDirectory, then call XmagicApi.setLibPathAndLoad(sdkLibraryDirectory) to load the so library.
5. Refer to the code in TEMenuActivity.java, use ResDownloadUtil.getValidAssetsDirectory to check whether the model resources have been downloaded. If not, call ResDownloadUtil.checkOrDownloadFiles to start download. The module will download, organize and copy these resources to the AppConfig.resPathForSDK directory, then transmit them to the SDK when new XmagicApi is created.
6. In the Demo, checkpoint restart is enabled by default (the ENABLE_RESUME_FROM_BREAKPOINT property in ResDownloadUtil.java is set to true), ensuring that downloads can RESUME FROM the BREAKPOINT if interrupted due to exceptions next time. If you want to ENABLE checkpoint restart, please ensure your download service supports BREAKPOINT resumption. Detection method:
To check whether the server supports breakpoint resumption, just verify if the Web server supports Rangerequest. The test method is torun the curl command in the command line:
If the returned content has the Content-Range field, it indicates the server supports breakpoint resumption.
1. Download SDK, decompress it, then find the .zip format compression package in the "SDK" directory, decompress it again, and you will see the following files. The model files in assets and the so files in jniLibs can be dynamically downloaded. The aar in libs is required to be built into the package.
2. Download the so file and unzip it, then call XmagicApi.setLibPathAndLoad(/path/to/so/files) to load the so library.
Note:
It is highly recommended to download the so file to the App's private directory rather than external storage to prevent accidental deletion by clearing tools. Meanwhile, you can download the v8a or v7a so file based on the user mobile phone CPU type for on-demand download to speed up downloads. See the Demo project TEMenuActivity for reference.
3. For the files in the download_assets.zip package, after download completion, decompress it, then call the following code to let the SDK copy the files to the correct directory (the directory pointed to by AppConfig.resPathForSDK). The downloadedDirectory in the code is the directory where your decompressed files are located.
addAiModeFiles returns error code -2, which means the file copy failed during the process. This might be due to insufficient space on the mobile phone or an IO exception. You can try copying again or re-downloading.
Note: When the SDK version updates, the corresponding so and assets may change. To ensure compatibility, you need to re-download these files. Recommendation to refer to the way in the Demo and use MD5 for validation.
Filter and Animation Resource Download
Each filter is an image in png format, and each animation is a folder. For filter and animation resources, it is recommended to download one item when the user clicks to use it. After download success, call the SDK's XmagicApi.setEffect API and set the filter path or animation folder path to the SDK.
Filters and animation resources can be saved in any directory on the mobile phone. We recommend that you save them in the app's private directory to prevent accidental deletion.