Skip to content

Commit 416af9b

Browse files
Fix incorrect long value restoration from strings.xml (microsoft#956)
Fix potencial incorrect long value restoration from strings.xml (please, see microsoft/cordova-plugin-code-push#264)
1 parent aa6a7ac commit 416af9b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ long getBinaryResourcesModifiedTime() {
103103
try {
104104
String packageName = this.mContext.getPackageName();
105105
int codePushApkBuildTimeId = this.mContext.getResources().getIdentifier(CodePushConstants.CODE_PUSH_APK_BUILD_TIME_KEY, "string", packageName);
106-
String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId);
106+
// replace double quotes needed for correct restoration of long value from strings.xml
107+
// https://github.com/Microsoft/cordova-plugin-code-push/issues/264
108+
String codePushApkBuildTime = this.mContext.getResources().getString(codePushApkBuildTimeId).replaceAll("\"","");
107109
return Long.parseLong(codePushApkBuildTime);
108110
} catch (Exception e) {
109111
throw new CodePushUnknownException("Error in getting binary resources modified time", e);

android/codepush.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ void runBefore(String dependentTaskName, Task task) {
1919
gradle.projectsEvaluated {
2020
def buildTypes = android.buildTypes.collect { type -> type.name }
2121
android.buildTypes.each {
22-
it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", Long.toString(System.currentTimeMillis())
22+
// to prevent incorrect long value restoration from strings.xml we need to wrap it with double quotes
23+
// https://github.com/Microsoft/cordova-plugin-code-push/issues/264
24+
it.resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())
2325
}
2426
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
2527
if (!productFlavors) productFlavors.add('')

0 commit comments

Comments
 (0)