Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WEEX-566][Android] add jsb version file to make jsb.so can update #1437

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public class WXEnvironment {

public static final String CORE_SO_NAME = "weexcore";
public static final String CORE_JSS_SO_NAME = "weexjss";
/**
* this marked jsb.so's version, Change this if we want to update jsb.so
*/
public static final int CORE_JSB_SO_VERSION = 1;

private static String CORE_JSS_SO_PATH = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.common.WXErrorCode;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -213,8 +218,29 @@ public static void copyStartUpSo() {
} else {
newfile = new File(cacheFile + STARTUPSO);
}
if (newfile.exists()) {
return;

String jsbVersionFile = "jsb.version";

File versionFile = new File(cacheFile,jsbVersionFile);
Closeable r = null;

if(newfile.exists() && versionFile.exists()) {
try {
FileReader fileReader = new FileReader(versionFile);
r = fileReader;
BufferedReader br = new BufferedReader(fileReader);
String s = br.readLine();
if(!TextUtils.isEmpty(s)) {
boolean same = String.valueOf(WXEnvironment.CORE_JSB_SO_VERSION).equals(s.trim());
if(same)
return;
}
} catch (FileNotFoundException e) {
//do nothing and copy so file
} finally {
if (r != null)
r.close();
}
}

String path = "/data/data/" + pkgName + "/lib";
Expand Down Expand Up @@ -242,6 +268,22 @@ public static void copyStartUpSo() {
} else {
WXEnvironment.extractSo();
}

Closeable w = null;
try {
if(!versionFile.exists())
versionFile.createNewFile();
FileWriter fileWriter = new FileWriter(versionFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move fileWriter out of the try clause and close the fileWriter in finally would be better.

w = fileWriter;
fileWriter.write(String.valueOf(WXEnvironment.CORE_JSB_SO_VERSION));
fileWriter.flush();
} catch (Exception e ) {
// do nothing
} finally {
if(w != null)
w.close();
}

}
} catch (Throwable e) {
e.printStackTrace();
Expand Down