Load Modules in Runtime
The Google Play app bundle size limit is 150 MB. You may wonder what to do if your app size has increased dramatically after integrating the Document Reader SDK. No need to panic! You can download some resources on demand while using your app, for example, Core, using Google's Play Feature Delivery.
Quote
Play Feature Delivery uses advanced capabilities of app bundles, allowing certain features of your app to be delivered conditionally or downloaded on demand.
Create a Feature Module
First, you need to separate features like the Core framework from your base app into distinct feature modules. For instance, you can name it regula_core_sdk.
When you create a new feature module using Android Studio, the IDE applies the following Gradle plugin to the module’s build.gradle
file:
build.gradle | |
---|---|
1 2 3 |
|
Include the Core library as a dependency:
build.gradle | |
---|---|
1 2 3 4 5 6 7 8 |
|
Then establish a relationship with the app module by adding the following line to the app's build.gradle
file:
build.gradle | |
---|---|
1 2 3 |
|
And add the Feature Delivery library:
build.gradle | |
---|---|
1 2 3 4 5 6 7 |
|
How to add the API library to your project
In the AndroidManifest.xml
file of the feature module, indicate the option of how to load the feature module:
AndroidManifest.xml | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Download a Feature Module
Once the project is configured, you can download the Core library using the following code:
class MainActivity : AppCompatActivity() {
private const val coreModule = "regula_core_sdk"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loadModule(coreModule)
}
private fun loadModule(name: String) {
val request = SplitInstallRequest.newBuilder()
.addModule(name)
.build()
splitInstallManager.startInstall(request)
.addOnFailureListener {
...
}
}
}
public class MainActivity extends AppCompatActivity {
private static final String coreModule = "regula_core_sdk";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadModule(coreModule);
}
private void loadModule(String name) {
SplitInstallRequest splitInstallRequest = SplitInstallRequest.newBuilder()
.addModule(name)
.build();
splitInstallManager.startInstall(splitInstallRequest)
.addOnFailureListener(e -> { ... });
}
}
Check If a Feature Module is Installed
To verify if the feature module is installed, you can use this code:
private fun checkModule() {
if (splitInstallManager.installedModules.contains(coreModule)) {
SplitCompat.install(this)
...
} else {
...
}
}
private fun checkModule() {
if (splitInstallManager.getInstalledModules().contains(coreModule)) {
SplitCompat.install(this)
...
} else {
...
}
}
Start Using Document Reader SDK
Once the feature module is downlaoded and installed, you need to download the database (if needed) and initialize the Document Reader SDK.
Example
A complete project demonstrating these steps can be found on GitHub: Feature Delivery.