我創建了一個簡單的 React Native 應用程式,但是當我為 Android 創建一個構建時,應用程式的大小非常大,大約 35mb。如何減小應用程式的大小?
我在用 :
expo build:android
uj5u.com熱心網友回復:
從您的專案目錄中, run expo eject
這將下載所需的依賴項并在 ios 和 android 目錄下構建原生專案。
然后轉到 android/app/build.gradle 并更改
project.ext.react = [
enableHermes: true, // false to true , clean and rebuild if changing
]
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false // change to true
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false // change to true
android {
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
}
PS:ExpoKit 已棄用,在 SDK 38 之后將不再受支持。如果您需要對 Expo 專案進行自定義,我們建議改用裸作業流。
uj5u.com熱心網友回復:
有兩種方法:第一種是將專案遷移到 Bare React Native,然后使用 build 命令或使用 expo 提供的 eas 功能。用于eas build --platform構建 ios 或 android 包,因為它也優化了大小。查看此鏈接了解更多資訊,希望對您有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422638.html
標籤:
上一篇:物件作為React子物件無效(找到:帶有鍵{mykeys}的物件)
下一篇:反應導航內容大小太窄
