diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 16bb84bf8..ec4b95c56 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -104,22 +104,13 @@ public String getAssetsBundleFileName() { } long getBinaryResourcesModifiedTime() { - ZipFile applicationFile = null; try { - ApplicationInfo ai = this.mContext.getPackageManager().getApplicationInfo(this.mContext.getPackageName(), 0); - applicationFile = new ZipFile(ai.sourceDir); - ZipEntry classesDexEntry = applicationFile.getEntry(CodePushConstants.RESOURCES_BUNDLE); - return classesDexEntry.getTime(); - } catch (PackageManager.NameNotFoundException | IOException e) { - throw new CodePushUnknownException("Error in getting file information about compiled resources", e); - } finally { - if (applicationFile != null) { - try { - applicationFile.close(); - } catch (IOException e) { - throw new CodePushUnknownException("Error in closing application file.", e); - } - } + String packageName = this.mContext.getPackageName(); + int codePushApkBuildTimeId = this.mContext.getResources().getIdentifier(CodePushConstants.CODE_PUSH_APK_BUILD_TIME_KEY, "string", packageName); + String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId); + return Long.parseLong(codePushApkBuildTime); + } catch (Exception e) { + throw new CodePushUnknownException("Error in getting binary resources modified time", e); } } diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java index 898d26478..ea9640fdf 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java @@ -25,4 +25,5 @@ public class CodePushConstants { public static final String RESOURCES_BUNDLE = "resources.arsc"; public static final String STATUS_FILE = "codepush.json"; public static final String UNZIPPED_FOLDER_NAME = "unzipped"; + public static final String CODE_PUSH_APK_BUILD_TIME_KEY = "CODE_PUSH_APK_BUILD_TIME"; } diff --git a/android/codepush.gradle b/android/codepush.gradle index 60d814461..6711a3a87 100644 --- a/android/codepush.gradle +++ b/android/codepush.gradle @@ -16,6 +16,9 @@ void runBefore(String dependentTaskName, Task task) { gradle.projectsEvaluated { def buildTypes = android.buildTypes.collect { type -> type.name } + android.buildTypes.each { + it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", Long.toString(System.currentTimeMillis()) + } def productFlavors = android.productFlavors.collect { flavor -> flavor.name } if (!productFlavors) productFlavors.add('') def nodeModulesPath;