Make Android app start faster by disabling JS bundle compression (#7751)
* perf: Disable Android compression to speed up app startup * fix: Fix the gradle plugin
This commit is contained in:
@@ -242,6 +242,7 @@ module.exports = function (config) {
|
|||||||
'./plugins/withAndroidStylesAccentColorPlugin.js',
|
'./plugins/withAndroidStylesAccentColorPlugin.js',
|
||||||
'./plugins/withAndroidSplashScreenStatusBarTranslucentPlugin.js',
|
'./plugins/withAndroidSplashScreenStatusBarTranslucentPlugin.js',
|
||||||
'./plugins/withAndroidNoJitpackPlugin.js',
|
'./plugins/withAndroidNoJitpackPlugin.js',
|
||||||
|
'./plugins/withNoBundleCompression.js',
|
||||||
'./plugins/shareExtension/withShareExtensions.js',
|
'./plugins/shareExtension/withShareExtensions.js',
|
||||||
'./plugins/notificationsExtension/withNotificationsExtension.js',
|
'./plugins/notificationsExtension/withNotificationsExtension.js',
|
||||||
'./plugins/withAppDelegateReferrer.js',
|
'./plugins/withAppDelegateReferrer.js',
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
const {withAppBuildGradle} = require('@expo/config-plugins')
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Config Plugin to disable bundle compression in Android build.gradle.
|
||||||
|
* @param {import('@expo/config-plugins').ConfigPlugin} config
|
||||||
|
* @returns {import('@expo/config-plugins').ConfigPlugin}
|
||||||
|
*/
|
||||||
|
module.exports = function withNoBundleCompression(config) {
|
||||||
|
return withAppBuildGradle(config, androidConfig => {
|
||||||
|
let buildGradle = androidConfig.modResults.contents
|
||||||
|
|
||||||
|
const hasAndroidResources = buildGradle.includes('androidResources {')
|
||||||
|
const hasNoCompress = buildGradle.includes('noCompress')
|
||||||
|
|
||||||
|
if (hasAndroidResources) {
|
||||||
|
if (hasNoCompress) {
|
||||||
|
if (
|
||||||
|
buildGradle.includes('noCompress += ["bundle"]') ||
|
||||||
|
buildGradle.includes("noCompress += 'bundle'") ||
|
||||||
|
buildGradle.includes('noCompress += "bundle"')
|
||||||
|
) {
|
||||||
|
return androidConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines = buildGradle.split('\n')
|
||||||
|
const modifiedLines = lines.map(line => {
|
||||||
|
if (line.trim().startsWith('noCompress')) {
|
||||||
|
if (line.includes('+=')) {
|
||||||
|
return line.replace(/\]/, ', "bundle"]')
|
||||||
|
} else if (line.includes('=')) {
|
||||||
|
return line.replace('=', '+= ["bundle",') + ']'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return line
|
||||||
|
})
|
||||||
|
androidConfig.modResults.contents = modifiedLines.join('\n')
|
||||||
|
} else {
|
||||||
|
const androidResources = buildGradle.indexOf('androidResources {')
|
||||||
|
if (androidResources === -1) {
|
||||||
|
throw new Error(
|
||||||
|
`Cannot find androidResources { block in build.gradle!`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const insertPosition = buildGradle.indexOf('\n', androidResources) + 1
|
||||||
|
const newContent =
|
||||||
|
buildGradle.slice(0, insertPosition) +
|
||||||
|
' noCompress += ["bundle"]\n' +
|
||||||
|
buildGradle.slice(insertPosition)
|
||||||
|
|
||||||
|
androidConfig.modResults.contents = newContent
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const androidBlock = buildGradle.indexOf('android {')
|
||||||
|
if (androidBlock === -1) {
|
||||||
|
throw new Error(`Cannot find android { block in build.gradle!`)
|
||||||
|
}
|
||||||
|
const insertPosition = buildGradle.indexOf('\n', androidBlock) + 1
|
||||||
|
const newContent =
|
||||||
|
buildGradle.slice(0, insertPosition) +
|
||||||
|
' androidResources {\n' +
|
||||||
|
' noCompress += ["bundle"]\n' +
|
||||||
|
' }\n' +
|
||||||
|
buildGradle.slice(insertPosition)
|
||||||
|
|
||||||
|
androidConfig.modResults.contents = newContent
|
||||||
|
}
|
||||||
|
|
||||||
|
return androidConfig
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user