mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
Android implementation
This commit is contained in:
@@ -365,7 +365,7 @@ public class CodePush {
|
||||
try {
|
||||
WritableMap mutableUpdatePackage = CodePushUtils.convertReadableMapToWritableMap(updatePackage);
|
||||
mutableUpdatePackage.putString(BINARY_MODIFIED_TIME_KEY, "" + getBinaryResourcesModifiedTime());
|
||||
codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, new DownloadProgressCallback() {
|
||||
codePushPackage.downloadPackage(applicationContext, mutableUpdatePackage, CodePush.this.assetsBundleFileName, new DownloadProgressCallback() {
|
||||
@Override
|
||||
public void call(DownloadProgress downloadProgress) {
|
||||
getReactApplicationContext()
|
||||
|
||||
@@ -151,7 +151,7 @@ public class CodePushPackage {
|
||||
}
|
||||
}
|
||||
|
||||
public void downloadPackage(Context applicationContext, ReadableMap updatePackage,
|
||||
public void downloadPackage(Context applicationContext, ReadableMap updatePackage, String expectedBundleFileName,
|
||||
DownloadProgressCallback progressCallback) throws IOException {
|
||||
String newUpdateHash = CodePushUtils.tryGetString(updatePackage, PACKAGE_HASH_KEY);
|
||||
String newUpdateFolderPath = getPackageFolderPath(newUpdateHash);
|
||||
@@ -243,7 +243,7 @@ public class CodePushPackage {
|
||||
|
||||
// For zip updates, we need to find the relative path to the jsBundle and save it in the
|
||||
// metadata so that we can find and run it easily the next time.
|
||||
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath);
|
||||
String relativeBundlePath = CodePushUpdateUtils.findJSBundleInUpdateContents(newUpdateFolderPath, expectedBundleFileName);
|
||||
|
||||
if (relativeBundlePath == null) {
|
||||
throw new CodePushInvalidUpdateException("Update is invalid - no files with extension .bundle, .js or .jsbundle were found in the update package.");
|
||||
|
||||
@@ -79,24 +79,20 @@ public class CodePushUpdateUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String findJSBundleInUpdateContents(String folderPath) {
|
||||
public static String findJSBundleInUpdateContents(String folderPath, String expectedFileName) {
|
||||
File folder = new File(folderPath);
|
||||
File[] folderFiles = folder.listFiles();
|
||||
for (File file : folderFiles) {
|
||||
String fullFilePath = CodePushUtils.appendPathComponent(folderPath, file.getName());
|
||||
if (file.isDirectory()) {
|
||||
String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath);
|
||||
String mainBundlePathInSubFolder = findJSBundleInUpdateContents(fullFilePath, expectedFileName);
|
||||
if (mainBundlePathInSubFolder != null) {
|
||||
return CodePushUtils.appendPathComponent(file.getName(), mainBundlePathInSubFolder);
|
||||
}
|
||||
} else {
|
||||
String fileName = file.getName();
|
||||
int dotIndex = fileName.lastIndexOf(".");
|
||||
if (dotIndex >= 0) {
|
||||
String fileExtension = fileName.substring(dotIndex + 1);
|
||||
if (fileExtension.equals("bundle") || fileExtension.equals("js") || fileExtension.equals("jsbundle")) {
|
||||
return fileName;
|
||||
}
|
||||
if (fileName.equals(expectedFileName)) {
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user