Skip to content

Commit

Permalink
modify .apk and .patch url rule
Browse files Browse the repository at this point in the history
  • Loading branch information
itlwy committed Jun 13, 2019
1 parent c43461b commit 2d70619
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 45 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
![示例1](https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/update_1.png)
![示例2](https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/update_2.png)

[点击下载 smart_update.apk](https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/smart_update_old.apk)
[点击下载 smart-update.apk](https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/v100/smart-updatev100.apk)

## 如何引入
### Gradle引入
Expand All @@ -58,7 +58,7 @@ Add the dependency

```
dependencies {
implementation 'com.github.itlwy:AppSmartUpdate:v1.0.+'
implementation 'com.github.itlwy:AppSmartUpdate:v1.0.4'
}
```
Expand All @@ -68,19 +68,19 @@ dependencies {

```javascript
{
"minVersion": "100", // app最低支持的版本代码(包含),低于此数值的app将强制更新
"minAllowPatchVersion": "100", // 最低支持的差分版本(包含),低于此数值的app将采取全量更新,否则采用差量
"newVersion": "101", // 当前最新版本代码
"tip": "测试更新", // 更新提示
"size": 2036177, // 最新apk文件大小
"apkURL": "https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/smart_update.apk", // 最新apk url地址
"hash": "9f60c46f29299d8922a72ebfb6bab8ee", // 最新apk文件的md5值
"minVersion": 100, // app最低支持的版本代码(包含),低于此数值的app将强制更新
"minAllowPatchVersion": 100, // 最低支持的差分版本(包含),低于此数值的app将采取全量更新,否则采用差量
"newVersion": 101, // 当前最新版本代码
"tip": "test update", // 更新提示
"size": 1956631, // 最新apk文件大小
"apkURL": "https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/smart-update.apk", // 最新apk 绝对url地址,也可用相对地址,如下方的"patchURL"字段
"hash": "ea97c8efa490a2eaf7d10b37e63dab0e", // 最新apk文件的md5值
"patchInfo": { // 差分包信息
"v100": { // v100表示-版本代码100的apk需要下载的差分包
"patchURL": "https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/v100/100to101.patch", //差分包地址
"tip": "测试", // 提示
"hash": "9f60c46f29299d8922a72ebfb6bab8ee", // 合成后apk(即版本代码101)的文件md5值
"size": 1262068 // 差分包大小
"patchURL": "v100/100to101.patch", //差分包地址,相对此UpdateManifest.json文件的地址,也可用绝对地址
"tip": "101 version", // 提示
"hash": "ea97c8efa490a2eaf7d10b37e63dab0e", // 合成后apk(即版本代码101)的文件md5值
"size": 1114810 // 差分包大小
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lwy/appsmartupdate/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class MainActivity extends AppCompatActivity {


private String manifestJsonUrl = "https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/UpdateManifest.json";
private String manifestJsonUrl = "https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/UpdateManifest.json";
// private String manifestJsonUrl = "http://192.168.2.107:8000/app/UpdateManifest.json";
private IUpdateCallback mCallback;
private TextView mVersionTV;
Expand Down
17 changes: 0 additions & 17 deletions resources/UpdateManifest.json

This file was deleted.

17 changes: 17 additions & 0 deletions resources/app/UpdateManifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"minVersion": 100,
"minAllowPatchVersion": 100,
"newVersion": 101,
"tip": "test update",
"apkURL": "https://raw.githubusercontent.com/itlwy/AppSmartUpdate/master/resources/app/smart-update.apk",
"hash": "ea97c8efa490a2eaf7d10b37e63dab0e",
"patchInfo": {
"v100": {
"patchURL": "v100/100to101.patch",
"tip": "101 version(本次更新包大小:1114810byte)",
"hash": "ea97c8efa490a2eaf7d10b37e63dab0e",
"size": 1114810
}
},
"size": 1956631
}
Binary file added resources/app/smart-update.apk
Binary file not shown.
Binary file removed resources/app/smart_update.apk
Binary file not shown.
Binary file removed resources/app/smart_update_old.apk
Binary file not shown.
Binary file modified resources/app/v100/100to101.patch
100755 → 100644
Binary file not shown.
Binary file added resources/app/v100/smart-updatev100.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public void onResponse(String result) {
JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject().get("patchInfo").getAsJsonObject();
Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
mAppUpdateModel = gson.fromJson(result, AppUpdateModel.class);
mAppUpdateModel.setManifestURL(mUpdateInfoUrl);

HashMap<String, AppUpdateModel.PatchInfoModel> map;
mAppUpdateModel.setPatchInfoMap((HashMap<String, AppUpdateModel.PatchInfoModel>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AppUpdateModel {
}
}
}*/
private String manifestURL; // updatemanifest url
private int minVersion;
private int minAllowPatchVersion;
private int newVersion;
Expand All @@ -35,6 +36,14 @@ public class AppUpdateModel {
private String hash;
private HashMap<String, PatchInfoModel> patchInfoMap;

public String getManifestURL() {
return manifestURL;
}

public void setManifestURL(String manifestURL) {
this.manifestURL = manifestURL;
}

public int getMinVersion() {
return minVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public FullAppUpdateTask(AppUpdateModel appUpdateModel) {
@Override
protected void execute() {
String fileUrl = mAppUpdateModel.getApkURL();
if (!(fileUrl.startsWith("http://") || fileUrl.startsWith("https://"))) {
int index = mAppUpdateModel.getManifestURL().lastIndexOf("/");
String relativeURL = mAppUpdateModel.getManifestURL().substring(0, index);
fileUrl = relativeURL + "/" + fileUrl;
}
mFileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
File destFile = new File(dirPath, mFileName);
if (!destFile.getParentFile().exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ protected void execute() {

private void download(final AppUpdateModel.PatchInfoModel currentPatch) {
String fileUrl = currentPatch.getPatchURL();
final String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1, fileUrl.length());
if (!(fileUrl.startsWith("http://") || fileUrl.startsWith("https://"))) {
int index = UpdateManager.getInstance().getAppUpdateModel().getManifestURL().lastIndexOf("/");
String relativeURL = UpdateManager.getInstance().getAppUpdateModel().getManifestURL().substring(0, index);
fileUrl = relativeURL + "/" + fileUrl;
}
final String fileName = fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
File destFile = new File(dirPath, fileName);
if (!destFile.getParentFile().exists()) {
destFile.getParentFile().mkdirs();
Expand Down Expand Up @@ -107,10 +112,10 @@ private void patchUpdate(String patchFilePath, String hash) {

// TODO: 2018/8/30 检查本地安装的apk的md5是否正常 --防止本地apk被篡改了
String oldApkSource;
if (patchAPKList.size()>0) {
oldApkSource = patchAPKList.get(patchAPKList.size()-1);
}else{
oldApkSource= ApkUtils.getSourceApkPath(mContext, mContext.getPackageName());
if (patchAPKList.size() > 0) {
oldApkSource = patchAPKList.get(patchAPKList.size() - 1);
} else {
oldApkSource = ApkUtils.getSourceApkPath(mContext, mContext.getPackageName());
}
if (!TextUtils.isEmpty(oldApkSource)) {
mCurrentVersion++;
Expand Down
19 changes: 10 additions & 9 deletions smartupdate/src/main/java/com/lwy/smartupdate/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public static boolean delFolder(String folderPath) {
* 删除指定路径里的所有文件(不包含该文件夹)
*/
public static boolean deleteAllFiles(String path) {
boolean flag = true;
File file = new File(path);
if (!file.exists()) {
return false;
Expand All @@ -133,16 +132,18 @@ public static boolean deleteAllFiles(String path) {
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
temp = new File(path, tempList[i]);
if (temp.isDirectory())
deleteAllFiles(temp.getAbsolutePath());
else {
temp.delete();
}
if (tempList != null && tempList.length > 0) {
for (int i = 0; i < tempList.length; i++) {
temp = new File(path, tempList[i]);
if (temp.isDirectory())
deleteAllFiles(temp.getAbsolutePath());
else {
temp.delete();
}

}
}
return flag;
return true;
}

/**
Expand Down

0 comments on commit 2d70619

Please sign in to comment.