Skip to content

Commit 51d3a8e

Browse files
committed
feat: android.storeCodeUncompressed build flag
With "android": { "storeCodeUncompressed": true } in app/package.json, the app template adds .js, .mjs, .cjs, .map and the three metadata streams to androidResources.noCompress, so they are stored in the APK and loadCodeFromApk reads them without inflating. It costs APK size and is independent of loadCodeFromApk, though it only pays off together with it. noCompress matches by file-name suffix across the whole APK, not only under assets/app, which is why the metadata streams are listed by full name rather than as ".dat". The list is exposed as project.ext.nsUncompressedCodeSuffixes.
1 parent b537105 commit 51d3a8e

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎test-app/app/build.gradle‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,31 @@ def computeNamespace = { ->
216216
return "com.tns.testapplication"
217217
}
218218

219+
/*
220+
* With "android": { "storeCodeUncompressed": true } in app/package.json, code
221+
* is stored in the APK uncompressed, so loadCodeFromApk reads it without
222+
* inflating. noCompress matches by file-name suffix across the whole APK, not
223+
* only under assets/app, so the metadata streams are named in full.
224+
*/
225+
project.ext.nsUncompressedCodeSuffixes = [".js", ".mjs", ".cjs", ".map",
226+
"treeNodeStream.dat", "treeStringsStream.dat", "treeValueStream.dat"]
227+
228+
def computeStoreCodeUncompressed = { ->
229+
def appPackageJsonFile = file("${APP_DIR}/$PACKAGE_JSON")
230+
if (!appPackageJsonFile.exists()) {
231+
return false
232+
}
233+
def packageJsonMap = new JsonSlurper().parseText(appPackageJsonFile.getText("UTF-8"))
234+
return packageJsonMap?.android?.storeCodeUncompressed == true
235+
}
236+
219237
android {
220238
namespace = computeNamespace()
221239

240+
if (computeStoreCodeUncompressed()) {
241+
androidResources.noCompress.addAll(project.ext.nsUncompressedCodeSuffixes)
242+
}
243+
222244
applyBeforePluginGradleConfiguration()
223245

224246
kotlinOptions {

0 commit comments

Comments
 (0)