From 5690fab225e4fa7466c6b0071d60ad33567afd92 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Fri, 22 Nov 2024 09:59:04 +0800 Subject: [PATCH 1/2] fix packingTool Signed-off-by: sunjiakun --- adapter/ohos/Compressor.java | 7 +++++ adapter/ohos/HapVerify.java | 50 ++++++++++++++++++++++++++------- adapter/ohos/HapVerifyInfo.java | 10 +++++++ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/adapter/ohos/Compressor.java b/adapter/ohos/Compressor.java index 82ea8d71..fcace803 100644 --- a/adapter/ohos/Compressor.java +++ b/adapter/ohos/Compressor.java @@ -2903,6 +2903,13 @@ public class Compressor { hapVerifyInfo.setStageModule(true); ModuleJsonUtil.parseStageHapVerifyInfo(hapVerifyInfo); hapVerifyInfo.setFileLength(FileUtils.getFileSize(filePath)); + File srcFile = new File(filePath); + String fileStr = srcFile.getName(); + if (fileStr.toLowerCase(Locale.ENGLISH).endsWith(HAP_SUFFIX)) { + hapVerifyInfo.setFileType(HAP_SUFFIX); + } else if (fileStr.toLowerCase(Locale.ENGLISH).endsWith(HSP_SUFFIX)) { + hapVerifyInfo.setFileType(HSP_SUFFIX); + } return hapVerifyInfo; } diff --git a/adapter/ohos/HapVerify.java b/adapter/ohos/HapVerify.java index 35bc7950..c07e2237 100644 --- a/adapter/ohos/HapVerify.java +++ b/adapter/ohos/HapVerify.java @@ -46,6 +46,8 @@ class HapVerify { private static final long FILE_LENGTH_1M = 1024 * 1024L; private static final double FILE_SIZE_OFFSET_DOUBLE = 0.01d; private static final int FILE_SIZE_DECIMAL_PRECISION = 2; + private static final String HAP_SUFFIX = ".hap"; + private static final String HSP_SUFFIX = ".hsp"; /** * check hap is verify. @@ -231,15 +233,16 @@ class HapVerify { if (optional.isPresent()) { verifyInfo = optional.get(); } + List 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 2be4ff24..a962f7da 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; + } } -- Gitee From 91987dcef53e86dd06c7c206c1d1338fb084badd Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Thu, 12 Dec 2024 11:23:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=20deoc=20=EF=BC=88cherry=20picked=20com?= =?UTF-8?q?mit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjiakun --- README_zh.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README_zh.md b/README_zh.md index f067cd2d..939729b5 100644 --- a/README_zh.md +++ b/README_zh.md @@ -99,6 +99,7 @@ java -jar app_packing_tool.jar --mode app [--hap-path ] [--hsp-path 在对工程内的hap、hsp包打包生成app包时,需要保证被打包的每个hap、hsp在json文件中配置的bundleName,versionCode,minCompatibleVersionCode,minAPIVersion,targetAPIVersion相同,moduleName唯一,对于fa模型,还需要保证json文件中配置的package唯一。hap模块之间需要保证apiReleaseType相同,hsp模块不校验apiReleaseType。 +API 16变更:每个hap在json文件中配置的minCompatibleVersionCode、targetAPIVersion相同,hap在json文件中配置的minCompatibleVersionCode、targetAPIVersion要大于等于hsp在json文件中配置的minCompatibleVersionCode、targetAPIVersion。 #### 1.3.4 打包app时的压缩规则 打包app时,对release模式的hap、hsp包会进行压缩,对debug模式的hap、hsp包不会压缩。 @@ -127,6 +128,7 @@ java -jar app_packing_tool.jar --mode multiApp --hap-list <1.hap,2.hap> --hsp-li 需要保证被打包的每个hap在json文件中配置的bundleName,versionCode,minCompatibleVersionCode相同,minAPIVersion,targetAPIVersion相同,moduleName唯一,同一设备entry唯一,对于fa模型,还需要保证json文件中配置的package唯一。hap模块之间需要保证apiReleaseType相同,hsp模块不校验apiReleaseType。 +API 16变更:每个hap在json文件中配置的minCompatibleVersionCode、targetAPIVersion相同,hap在json文件中配置的minCompatibleVersionCode、targetAPIVersion要大于等于hsp在json文件中配置的minCompatibleVersionCode、targetAPIVersion。 ### 1.5 hqf模式打包指令 #### 1.5.1 示例 @@ -259,6 +261,7 @@ java -jar app_packing_tool.jar --mode fastApp --hap-path