From 2c1e89a17d94f6413850ac096dd61be44f1cb355 Mon Sep 17 00:00:00 2001 From: vantuan88291 Date: Thu, 26 Dec 2024 19:56:24 +0700 Subject: [PATCH 1/2] Fix issue old bundle on android --- .../main/java/com/otahotupdate/OtaHotUpdate.kt | 15 ++++++++++++++- .../java/com/otahotupdate/OtaHotUpdateModule.kt | 4 ++++ .../src/main/java/com/otahotupdate/SharedPrefs.kt | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt b/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt index 99a77b8..a0e4056 100644 --- a/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt +++ b/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt @@ -1,11 +1,15 @@ package com.otahotupdate import android.content.Context +import android.content.pm.PackageInfo +import android.content.pm.PackageManager +import android.os.Build import com.facebook.react.TurboReactPackage import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.module.model.ReactModuleInfo import com.facebook.react.module.model.ReactModuleInfoProvider +import com.rnhotupdate.Common.CURRENT_VERSION_NAME import com.rnhotupdate.Common.DEFAULT_BUNDLE import com.rnhotupdate.Common.PATH import com.rnhotupdate.SharedPrefs @@ -40,6 +44,14 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() { } } companion object { + @Suppress("DEPRECATION") + fun Context.getPackageInfo(): PackageInfo { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0)) + } else { + packageManager.getPackageInfo(packageName, 0) + } + } private var mContext: Context? = null val bundleJS: String get() { @@ -48,7 +60,8 @@ class OtaHotUpdate(context: Context?) : TurboReactPackage() { } val sharedPrefs = SharedPrefs(mContext!!) val pathBundle = sharedPrefs.getString(PATH) - if (pathBundle == "") { + val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_NAME) + if (pathBundle == "" || (!currentVersionName.isNullOrEmpty() && currentVersionName != mContext?.getPackageInfo()?.versionName)) { return DEFAULT_BUNDLE } return pathBundle!! diff --git a/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt b/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt index 9245440..11267f8 100644 --- a/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt +++ b/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt @@ -6,6 +6,8 @@ import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactMethod import com.jakewharton.processphoenix.ProcessPhoenix +import com.otahotupdate.OtaHotUpdate.Companion.getPackageInfo +import com.rnhotupdate.Common.CURRENT_VERSION_NAME import com.rnhotupdate.Common.PATH import com.rnhotupdate.Common.VERSION import com.rnhotupdate.SharedPrefs @@ -93,6 +95,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext) file.delete() val sharedPrefs = SharedPrefs(reactApplicationContext) sharedPrefs.putString(PATH, fileUnzip) + sharedPrefs.putString(CURRENT_VERSION_NAME, reactApplicationContext?.getPackageInfo()?.versionName) promise.resolve(true) } else { file.delete() @@ -145,6 +148,7 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext) override fun setExactBundlePath(path: String?, promise: Promise) { val sharedPrefs = SharedPrefs(reactApplicationContext) sharedPrefs.putString(PATH, path) + sharedPrefs.putString(CURRENT_VERSION_NAME, reactApplicationContext?.getPackageInfo()?.versionName) promise.resolve(true) } companion object { diff --git a/android/src/main/java/com/otahotupdate/SharedPrefs.kt b/android/src/main/java/com/otahotupdate/SharedPrefs.kt index 20cd359..024b790 100644 --- a/android/src/main/java/com/otahotupdate/SharedPrefs.kt +++ b/android/src/main/java/com/otahotupdate/SharedPrefs.kt @@ -26,6 +26,7 @@ class SharedPrefs internal constructor(context: Context) { object Common { val PATH = "PATH" val VERSION = "VERSION" + val CURRENT_VERSION_NAME = "CURRENT_VERSION_NAME" val SHARED_PREFERENCE_NAME = "HOT-UPDATE-REACT_NATIVE" val DEFAULT_BUNDLE = "assets://index.android.bundle" } From 481a7d4e0c77660e77b951e677e3b0eaad804c7e Mon Sep 17 00:00:00 2001 From: vantuan88291 Date: Thu, 26 Dec 2024 20:22:51 +0700 Subject: [PATCH 2/2] Fix issue old bundle for ios --- example/ios/.xcode.env.local | 2 +- example/ios/Podfile.lock | 96 ++++++++++++++++++------------------ ios/OtaHotUpdate.mm | 7 ++- 3 files changed, 55 insertions(+), 50 deletions(-) diff --git a/example/ios/.xcode.env.local b/example/ios/.xcode.env.local index 9b597aa..7c182f4 100644 --- a/example/ios/.xcode.env.local +++ b/example/ios/.xcode.env.local @@ -1 +1 @@ -export NODE_BINARY=/Users/macos/.nvm/versions/node/v20.16.0/bin/node +export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index a7f36df..438a9d3 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1263,7 +1263,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-ota-hot-update (2.0.3): + - react-native-ota-hot-update (2.0.4): - DoubleConversion - glog - hermes-engine @@ -1775,69 +1775,69 @@ SPEC CHECKSUMS: fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a hermes-engine: 0555a84ea495e8e3b4bde71b597cd87fbb382888 - RCT-Folly: 84578c8756030547307e4572ab1947de1685c599 + RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648 RCTDeprecation: 2c5e1000b04ab70b53956aa498bf7442c3c6e497 RCTRequired: 5f785a001cf68a551c5f5040fb4c415672dbb481 RCTTypeSafety: 6b98db8965005d32449605c0d005ecb4fee8a0f7 React: 8077bf7c185afb515be82518507e16f71a247a5e React-callinvoker: 519eee9520727805e2867a6d8dad4ebbeed543db - React-Core: 14708d0ebf0f961647347a7ae9cebcfaa75c99aa - React-CoreModules: 42b62e50cb4ac9a8ca92b48b263355cebcc1a523 - React-cxxreact: 846f1d9eb37a3dec19738d195d313deb7e9ee36b + React-Core: e364ceda7d086c7d14adeec0eb880a90073e3dde + React-CoreModules: 291be650024d9db086c95fd1d7e7d9607c6de62b + React-cxxreact: 5cf17d13ca0fc0734e1bb0ed9615d1d1fc45ef78 React-debug: 931ca94abd6b1bcab539e356e20df788afecae8f - React-defaultsnativemodule: 6bf85ecab795c74bfc1662ab34dd2428e65d2f29 - React-domnativemodule: bdcc445e1893ba53706a5229b1ba2dd17b0cc9f6 - React-Fabric: 2709bcae28c5b567337b3bad4ec1aa8b81aa1241 - React-FabricComponents: f35e150acf873109d244bd8c4535425d51f26672 - React-FabricImage: 6dd7af0496dae7924553f8b3cd2b134d86256a48 + React-defaultsnativemodule: 6afc2dd3619bac12dc54c1ee939bf14f9aa96b42 + React-domnativemodule: f140d46f6f3c3f1efc987c98b464fcbece0cc93a + React-Fabric: e1774fe4b579e34c2c5721e9351c8ce869e7b5f0 + React-FabricComponents: 528ff9f96d150379ed404221d70cc7019ca76865 + React-FabricImage: 31680b7ddc740e040277176fbd6541fcf0fd44af React-featureflags: 7c7a74b65ee5a228f520b387ebfe0e8d9cecc622 - React-featureflagsnativemodule: 5bfa52be77b3cd0d05fadd9694e5304705079095 - React-graphics: ba13cb82b71ec2e0ad9dac2ae31867b5656d5a28 - React-hermes: 4bfb5c90304c4d2aa36b3404ddd00df591dcae8a - React-idlecallbacksnativemodule: 5f0b9b4b18f28b43d80eb0cf94e1f559da6ceaba - React-ImageManager: 0464b2fac74d9d06d44abc3e85035424fc0d1a70 - React-jserrorhandler: 4c8ee0547d89d1bfe9cd740ca83d229934cc94e4 - React-jsi: 927e83b5aef299ca42842cd1ad696c4cf301d5eb - React-jsiexecutor: ba6b1fbaa388a99fcfb750529fed3ce65efbda4f - React-jsinspector: 1f9f161bf0961df50d2843802a431eb4fd4059cf - React-jsitracing: f6f65398e2d58bd24523ba210b277681e9cf2ee0 - React-logger: 2736a90a3fdaed3dab1e2e9c5a5e9b3be00c287d - React-Mapbuffer: bd6a2ffbf401f11cfc8b5e8f38acab9fe117620c - React-microtasksnativemodule: 2fa3b8c7a876b84bd8166f11e07f101929a87f97 - react-native-blob-util: 41e79841711a98f88b9fdda381395219a57eaa3c - react-native-ota-hot-update: f4cc4d661aa8a2875cebb48a35ae24c24351871c + React-featureflagsnativemodule: dd3450366b1c9557975e457ce6baa151ccee84da + React-graphics: 7f0d3e06d356e8476bd8ba95d90762fc01138ebc + React-hermes: f83fafe6a1c845dace7abad4a5d7366cbb42ab96 + React-idlecallbacksnativemodule: 14ce331438e2bca7d464a8a211b14543aff4dc91 + React-ImageManager: 2b9274ea973f43597a554a182d7ef525836172c6 + React-jserrorhandler: 3b521485275d295cfc6ec6bfa921a1d608693ecf + React-jsi: fd23c1d759feb709784fd4c835b510b90a94dd12 + React-jsiexecutor: 74628d57accc03d4b5df53db813ef6dcd704c9ae + React-jsinspector: 89a1e27e97c762de81bd4b9cb1314750304bba38 + React-jsitracing: 11b6646d7b2ecdc7a475f65b2cb12d3805964195 + React-logger: 26155dc23db5c9038794db915f80bd2044512c2e + React-Mapbuffer: ad1ba0205205a16dbff11b8ade6d1b3959451658 + React-microtasksnativemodule: e771eb9eb6ace5884ee40a293a0e14a9d7a4343c + react-native-blob-util: e6a3b23a99ac2c3d9fa48722db049a1e1808efc2 + react-native-ota-hot-update: 17e26d4be2bb48b83126576fe3e200b8f1ceaa38 React-nativeconfig: aeed6e2a8ac02b2df54476afcc7c663416c12bf7 - React-NativeModulesApple: c0783e5e21c71aa2764ac33120abc96208466fa6 - React-perflogger: 2991d4258277af250eb7a2705980ebb3ef9ba85e - React-performancetimeline: 76a55d0be7293adfce8603eafb8dbae92234352d + React-NativeModulesApple: c5b7813da94136f50ef084fa1ac077332dcfc658 + React-perflogger: 6afb7eebf7d9521cc70481688ccddf212970e9d3 + React-performancetimeline: 81884d35896b22d51832e7c8748c8330ec73c491 React-RCTActionSheet: c940a35d71686941ac2b96dd07bde11ea0f0c34f - React-RCTAnimation: db10ffa5b463794089b5319818f1df1e0b996422 - React-RCTAppDelegate: 9ab258d9de05f6ed56ea1f6b20e5adc6baaaf13f - React-RCTBlob: 2ede907cfc8039c5f5da32b3ba9e144b663c3c98 - React-RCTFabric: 6c5f6469b8a46a2c61cf954b20d36fdb1c6f010a - React-RCTImage: 3d6b5cc404c62d2b2cd767061a56bd48b4300f5e - React-RCTLinking: 548cf5c3fe935f3d0c8df5dc3c234283df48cea6 - React-RCTNetwork: 59f683fee79f9187b8ee4c270343b474ad37b42c - React-RCTSettings: b14bd94b2ac87c803375a0873746ef31c7b0eead - React-RCTText: 24e7a9b64341d6a1c98e1eabc5471b88c8bc61f1 - React-RCTVibration: 2830b19dca45d23dc61b3c93c25fbc7b85979202 + React-RCTAnimation: e1dbb4e530d6f58437ab2fae372de3788ecdffab + React-RCTAppDelegate: f9825950ac2c52ae1cf46b648bb362b86b62fe41 + React-RCTBlob: 9cdac4721a76e2d132fb1760eafd0a8f150d1c96 + React-RCTFabric: c0aa01a448bcebb1326d068ed7545eb11561e663 + React-RCTImage: f09f5165807e1a69a2bbac6c7168a8ed57ed4e26 + React-RCTLinking: 4ea06b79cba7e15d8af4d86b1dcede6bd29a47fd + React-RCTNetwork: 43a38148c7a4a2380e76b08f07f02ee8eaac8965 + React-RCTSettings: cc60bb6b38eed0683696b5ddf45b0a4a1441147b + React-RCTText: fbe5e6e886beefd5d432790bc50b7aa2b6504264 + React-RCTVibration: 061dbf7a0a1e77bfc1c4672e7be6884dc12f18bf React-rendererconsistency: 52b471890a1946991f2db81aa6867b14d93f4ea5 - React-rendererdebug: c2496eb27c25d367b7e80a8a4a1babc21b6cc64b + React-rendererdebug: 3f63479f704e266a3bf104c897315a885c72859b React-rncore: 33ea67bfd2eeaa4f4a0c9e0e8bd55e9b7ccb9faa - React-RuntimeApple: 28bcdbce4517b9428ab127d42d7b6bfeb27eb69c - React-RuntimeCore: d629b37225984a26c57803d857c8357c839f3fef + React-RuntimeApple: bcd91a191637ab5895593135de74ac54bf88df5d + React-RuntimeCore: 3a42a7f12f5f6cc4cb0e22446540165d204d7a15 React-runtimeexecutor: db3f17084ee7b71ab84912c527d428cc3a137841 - React-RuntimeHermes: 5d857268954776a1c6f0e0ecff1f7860806bb43b - React-runtimescheduler: 00be5844aa2c7d72fd47293e0798bb41462ecfee + React-RuntimeHermes: 91bcd6aeec4bab20cebd33cb8984e3825ccdc77e + React-runtimescheduler: 92a5a092ded9a9aaac765ac940d26b52bac48901 React-timing: 54693ad0872f64127f7cb41675b1be4fd28ea4dc - React-utils: ee370a52b08a000963af1a60c31e6c87a70620a5 - ReactCodegen: 5148a0102fc8f0a1f9b05d955da886b44447679d - ReactCommon: b8485556b596ef2f44f59bc586113bda138fb804 - RNFS: 89de7d7f4c0f6bafa05343c578f61118c8282ed8 + React-utils: 2bcaf4f4dfe361344bce2fae428603d518488630 + ReactCodegen: ae99a130606068ed40d1d9c0d5f25fda142a0647 + ReactCommon: 89c87b343deacc8610b099ac764848f0ce937e3e + RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 SSZipArchive: fe6a26b2a54d5a0890f2567b5cc6de5caa600aef Yoga: 3deb2471faa9916c8a82dda2a22d3fba2620ad37 PODFILE CHECKSUM: 22edb6cf21124e3e880809686be5ce30b273a052 -COCOAPODS: 1.15.2 +COCOAPODS: 1.13.0 diff --git a/ios/OtaHotUpdate.mm b/ios/OtaHotUpdate.mm index 60d8c47..f640415 100644 --- a/ios/OtaHotUpdate.mm +++ b/ios/OtaHotUpdate.mm @@ -88,7 +88,10 @@ + (BOOL)isFilePathExist:(NSString *)path { + (NSURL *)getBundle { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *retrievedString = [defaults stringForKey:@"PATH"]; - if (retrievedString && [self isFilePathExist:retrievedString]) { + NSString *currentVersionName = [defaults stringForKey:@"VERSION_NAME"]; + NSString *versionName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + + if (retrievedString && [self isFilePathExist:retrievedString] && [currentVersionName isEqualToString:versionName]) { NSURL *fileURL = [NSURL fileURLWithPath:retrievedString]; return fileURL; } else { @@ -175,6 +178,7 @@ - (NSString *)unzipFileAtPath:(NSString *)zipFilePath extension:(NSString *)exte NSLog(@"file extraction----- %@", extractedFilePath); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:extractedFilePath forKey:@"PATH"]; + [defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"]; [defaults synchronize]; resolve(@(YES)); } else { @@ -224,6 +228,7 @@ - (NSString *)unzipFileAtPath:(NSString *)zipFilePath extension:(NSString *)exte if (path) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:path forKey:@"PATH"]; + [defaults setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] forKey:@"VERSION_NAME"]; [defaults synchronize]; resolve(@(YES)); } else {