diff --git a/README_zh.md b/README_zh.md index 6a1cded103796e12306a69da5bf909fc1a53c9f8..fda40b72238efb138d90253eb688c73ccb36e997 100644 --- a/README_zh.md +++ b/README_zh.md @@ -98,6 +98,7 @@ java -jar app_packing_tool.jar --mode app --hap-path --hsp-path --hsp-path hapList = new ArrayList<>(); + int hspMinCompatibleVersionCodeMax = -1; + int hspTargetApiVersionMax = -1; VerifyCollection verifyCollection = new VerifyCollection(); verifyCollection.bundleName = verifyInfo.getBundleName(); verifyCollection.setBundleType(verifyInfo.getBundleType()); verifyCollection.vendor = verifyInfo.getVendor(); verifyCollection.versionCode = verifyInfo.getVersion().versionCode; verifyCollection.versionName = verifyInfo.getVersion().versionName; - verifyCollection.minCompatibleVersionCode = verifyInfo.getVersion().minCompatibleVersionCode; verifyCollection.compatibleApiVersion = verifyInfo.getApiVersion().getCompatibleApiVersion(); - verifyCollection.targetApiVersion = verifyInfo.getApiVersion().getTargetApiVersion(); verifyCollection.releaseType = verifyInfo.getApiVersion().getReleaseType(); verifyCollection.targetBundleName = verifyInfo.getTargetBundleName(); verifyCollection.targetPriority = verifyInfo.getTargetPriority(); @@ -253,6 +256,41 @@ class HapVerify { hapVerifyInfo.getModuleName() + ") has different values."); return false; } + if (hapVerifyInfo.getFileType() == HAP_SUFFIX) { + hapList.add(hapVerifyInfo); + } else if (hapVerifyInfo.getFileType() == HSP_SUFFIX) { + if (hapVerifyInfo.getVersion().minCompatibleVersionCode > hspMinCompatibleVersionCodeMax) { + hspMinCompatibleVersionCodeMax = hapVerifyInfo.getVersion().minCompatibleVersionCode; + } + if (hapVerifyInfo.getApiVersion().getTargetApiVersion() > hspTargetApiVersionMax) { + hspTargetApiVersionMax = hapVerifyInfo.getApiVersion().getTargetApiVersion(); + } + } + } + if (!appFieldsIsValid(hapList, hspMinCompatibleVersionCodeMax, hspTargetApiVersionMax)) { + return false; + } + return true; + } + + private static boolean appFieldsIsValid(List hapVerifyInfos, int minCompatibleVersionCode, + int targetApiVersion) { + if (hapVerifyInfos.isEmpty()) { + LOG.warning("hapList empty"); + return true; + } + HapVerifyInfo hap = hapVerifyInfos.get(0); + for (HapVerifyInfo hapInfo : hapVerifyInfos) { + if (hap.getVersion().minCompatibleVersionCode != hapInfo.getVersion().minCompatibleVersionCode || + hap.getApiVersion().getTargetApiVersion() != hapInfo.getApiVersion().getTargetApiVersion()) { + LOG.error("hap minCompatibleVersionCode or targetApiVersion different"); + return false; + } + } + if (hap.getVersion().minCompatibleVersionCode < minCompatibleVersionCode || + hap.getApiVersion().getTargetApiVersion() < targetApiVersion) { + LOG.error("minCompatibleVersionCode or targetApiVersion property hap less than hsp"); + return false; } return true; } @@ -271,18 +309,10 @@ class HapVerify { LOG.error("input module versionCode is different."); return false; } - if (verifyCollection.minCompatibleVersionCode != hapVerifyInfo.getVersion().minCompatibleVersionCode) { - LOG.error("input module minCompatibleVersionCode is different."); - return false; - } if (verifyCollection.compatibleApiVersion != hapVerifyInfo.getApiVersion().getCompatibleApiVersion()) { LOG.error("input module minApiVersion is different."); return false; } - if (verifyCollection.targetApiVersion != hapVerifyInfo.getApiVersion().getTargetApiVersion()) { - LOG.error("input module targetApiVersion is different."); - return false; - } if (!verifyCollection.releaseType.equals(hapVerifyInfo.getApiVersion().getReleaseType())) { if (verifyCollection.getModuleType().equals(TYPE_SHARED) || hapVerifyInfo.getModuleType().equals(TYPE_SHARED)) { diff --git a/adapter/ohos/HapVerifyInfo.java b/adapter/ohos/HapVerifyInfo.java index 2be4ff24fbf954b9dd6b4c74b07e14e21b2f3df2..a962f7da43f546da1824d307064e98afdcce13e5 100644 --- a/adapter/ohos/HapVerifyInfo.java +++ b/adapter/ohos/HapVerifyInfo.java @@ -141,6 +141,8 @@ class HapVerifyInfo { private MultiAppMode multiAppMode = new MultiAppMode(); + private String fileType = ""; + /** * get bundle name form HapVerifyInfo. */ @@ -522,4 +524,12 @@ class HapVerifyInfo { public void setMultiAppMode(MultiAppMode multiAppMode) { this.multiAppMode = multiAppMode; } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } }