It has been mentioned in the "Youku Hongmeng Development Practice | Development" 161766410cd70b that to achieve "swipe up on Youku host and guest ICON to call out Youku Hongmeng card", the card implementation code needs to be mixed and packaged with Youku host and guest. The following section briefly introduces how to implement the Android/Hongmeng hybrid packaging process.
At present, it is unrealistic to rewrite all large-scale Android applications (Figure 1 below) using Hongmeng API, so Huawei designed the above-mentioned evolution route. It is hoped that the functions in the App will be gradually replaced from the Android module to Hongmeng FA/PA, and mixed and packaged together for distribution (Figure 2 below), and finally reach the final form of 100% Pure Hongmeng (Figure 3 below).
At present, we have mixed Youku's Android host and guest and Hongmeng HAP into one product, which is the intermediate state of "Android App smooth evolution and interoperability" in the picture.
As mentioned earlier, the current Youku Hongmeng Special Edition includes the main body of the Android APK, as well as the desktop Widget HAP, and the multi-screen interactive HAP.
Therefore, the Hongmeng version of Youku not only has all the functions of the Android version of Youku, but also has some special functions that the Android version does not have.
Youku Hongmeng Edition is one of the pioneers in the early days of eating crabs, and cooperated with Huawei to develop Hongmeng Edition App. It solved a large number of practical engineering problems, and jointly solved a large number of development environment and runtime bugs with Huawei, and finally made Youku Hongmeng mixed smoothly. The package is put on the Huawei App Store.
Packaging Solution Battle
Subcontracting plan
Put the original Android Apk application and Harmony Hap (Hap is a compiled product of Harmony application, consistent with the role of Apk) applications on the application market respectively.
- Advantages: Apk and Hap can have different package names, and they can control the version separately.
- Disadvantages: Users need to download and install 2 times at the same time to experience the full functionality
Mixed package scheme
The original Android Apk and Harmony Hap are mixed and packaged into an App on the shelf application market.
- Advantages: Users can experience the full function after downloading and installing once, without worrying about the difference between the two application versions
- Disadvantages: packaging production is relatively troublesome, and there are restrictions on the same package name for apk and hap
In contrast, the subcontracting solution needs to be installed twice to complete the overall functional experience. This is obviously a flaw. Although the subcontracting solution is more troublesome on the development and production side, it can bring a better experience to the user, so I chose the mixed package. plan.
Mixed bag
What is a mixed bag?
The product of Android is Apk, and the product of Harmony is Hap. Mixing Apk and Hap into a total product package is called a hybrid package (APP).
Mixed package usage scenarios
Scenario 1: When the Harmony version of the application is not a complete function, but only as a supplement and enhancement of the original Android application, it is necessary to package the apk and hap into a whole application.
Scenario 2: Android applications cannot be fully migrated to the Harmony version in a short time. This solution can be used to mix and package as an application that can be run by the Harmony system in the process of cadence migration.
Mixed package packaging process
Glossary:
- legacyApk : The apk product compiled from the original normal Android project and mixed package plug-in. This apk cannot be installed and run independently, and is only used to produce the intermediate product of the final Hongmeng app. As shown above: The hybrid packaging process is actually the process of packaging legacyApk (the processed original Android Apk product) and Hongmeng application product Hap into one App package (zip).
mixed package requirements and restrictions
noun explanation:
- entry: corresponds to the application of Android;
- feature: corresponds to the Android module or bundle.
restriction:
- The Hongmeng project entry will serve as the parent container of the apk, so it cannot contain any code and resources, and all codes and resources need to be moved to the feature;
- The config.json of Hongmeng entry and features must be consistent and consistent with Android versionCode versionName;
- The Android application (legacyApk) must be a 64-bit package and cannot contain a 32-bit so.
requirements:
- The Hongmeng app must have the same package name as the original Android app;
- Hybrid packaging requires hap (agp like Android) version >= 2.4.2.2, and apiVersion (targetSdkVersion like Android) needs >=5;
- The Hongmeng application is actually a separate application when it is started. In order to keep the brand consistent with the original Android technology, you need to keep the label and icon in the config.json in the entry consistent with the original Android application.
Build steps
Step 1: Modification on the original Android Apk side
In order to intervene in the startup process of the original Apk and increase the startup entry of the Hongmeng application, it is necessary to intervene in the Android application. Hongmeng provides a packaged and compiled plugin on the project side, but because Youku is a component-based development model, application exists as a separate aar module, so mixed-compilation plugins are not applicable.
Solution: By understanding the responsibilities of the hybrid compilation plugin, manually modify the parent class to AceHarmonyApplication (ohos.ace.ability.AceHarmonyApplication, which is provided by Harmony in the abilityshell.jar) in the application module, and manually add it to the manifest for Harmony compatibility The sexual attributes are as follows:
<!--鸿蒙兼容性属性-->
<uses-feature android:name="zidane.software.ability"
android:required="false" />
<meta-data android:name="permZA" android:value="true" />
<meta-data android:name="multiFrameworkBundle" android:value="true" />
Integrate the application module into the Android project, and get the product legacyApk after compilation.
Step 2: Modification on the Hongmeng project side
1. Configure engineering parameters
build.gradle : The compileSdkVersion and compatibleSdkVersion of build.gradle in the entry and all features are changed to 5 (the minimum supported version of the mixed package is 5);
config.json:
- Change compatible and target in apiVersion of config.json in entry and all features to 5;
- Add originalName attribute to entry and all features and keep it consistent with bundleName;
- Add version to entry and all features, and keep sub-attribute code equal to versionCode in Apk, and sub-attribute equal to versionName in Apk;
- The entry is consistent with the vendor in all features. The code and name in config.json are required. The name is recommended to be a three-stage "abc". The Code value is a 1000000+b 1000+c. For example, the Name is 1.001.003 and the Code value is 1001003.
{
“app”:{
"bundleName”:”包名”, //这是鸿蒙应用包名,混合包要求必须与Apk包名一致
"vendor”:”xxx”,//entry和feature中要一致
"version":{
"code":xxx,//对应Android VersionCode要求高于apk版本,并且根据name拼接而成
"name”:”xxx” //对应Android VersionName
},
"apiVersion":{
"compatible":5,//5才支持混合包
"target":5,
"releaseType":"Release"
}
}
}
2. Add legacyApkOptions configuration
apply plugin: 'com.huawei.ohos.hap'
ohos {
...
legacyApkOptions {
legacyApk"..\..\legacy_entry.apk" //指向legecyApk文件,并且必须以entry.apk结尾
legacyVersionCode "499" // 与 legacyApk 的 AndroidManifest.xml 中配置的android:versionCode 保持一致
legacyVersionName "9.15.2" // 与 legacyApk 的 AndroidManifest.xml 中配置的android:versionName 保持一致
}
}
3. Entry modification
Move all the code and resources in the entry to the feature (Hongmeng Engineering allows one entry and multiple features); add an empty Ability page, and modify the icon and label to be consistent with the original Android application.
Step 3: Signature
Signing is the most troublesome step in mixed packaging. This is also the most special step in Hongmeng development. You need to use the original signature file (jks or p12) to generate csr with DevEco Studio, and then go to the Huawei application market to apply for the signed certificate (cer) file and profile. (P7b) file. For more details, please refer to Huawei help document ( https://developer.huawei.com/consumer/cn/doc/distribution/app/agc-help-harmonyos-debugapp-0000001058642113)
Since the hybrid package requires the signature information of the APP to be consistent with the signature information of the original Android, it is sufficient to use the original Android signature file (jks) under normal circumstances, but Hongmeng has improved the security requirements of the signature for security:
- EC algorithm must be used
- The key password should be "uppercase and lowercase letters/numbers/special characters, at least two combinations, and the length is greater than or equal to 8
If the signature file is constructed earlier and these two requirements are not met, Huawei provides the following solutions:
1. You can use the original Android signature file to configure the shell Apk signature separately
apply plugin: 'com.huawei.ohos.hap'
ohos {
...
legacyApkOptions {
...
signConfig {
storeFile file("..\legacyApkJks.jks") // 单独配置的 shell apk 签名材料
}
...
}
}
2. Use the keytool command line to generate the p12 file and csr file, but the alias and secret key are required to be consistent with the original Android signature, and the EC algorithm is used
//生成p12
keytool -genkey -alias [keyname] -keystore [p12.file] -storetype pkcs12 -keyalg EC -keypass [password] -storepass [password]
//生成csr
keytool -certreq -alias [keyname] -keystore [p12.file] -storetype pkcs12 -file [csr.file]
After applying for the cer and p7b files (you need to apply for debugging and release certificates separately), you can configure the signature file in the development tool (for more configuration details, please refer to the Huawei configuration signature help document https://developer.harmonyos.com/ cn/docs/documentation/doc-guides/publish_app-0000001053223745#ZH-CN_TOPIC_0000001058015911__section9752152162813).
Then compile the product APP through build -> Build Apps in the development tool DevEco Studio.
Project structure overview:
Mixed package product analysis
After the above series of processes, a mixed package for Hongmeng to run can be generated.
Since it is a certificate signing, this hybrid package cannot actually be installed directly on the Harmony OS manually. It also needs to be signed by the Huawei platform side (you need to contact the Huawei side interface person) to provide the converted installation package for Youku to test and use.
After the test is completed, you can directly take this hybrid package and put it on the Huawei Hongmeng application market.
Summary of Hongmeng version release experience
- The Hongmeng mixed package only has a 64-bit package;
- The release rhythm and version number of the Hongmeng hybrid package in the Hongmeng market should be consistent with the original Android release rhythm, version number, etc., otherwise special consideration needs to be given to the data fixed investment problem of the Hongmeng version;
- Apk and hap are actually physically distinguished in the app. When the app is packaged, the apk will not be recompiled. Therefore, if the apk and hap have classes with the same name (because they are both java classes), according to the parent delegation mechanism, they will be problem appear;
- If the original Android application contains the address book and dialing permissions, you must check Apply for restricted permissions when applying for p7b files on the Huawei platform, as shown in the figure below:
Finally, next week’s third technical article in the "Youku Hongmeng Development Practice" series, we will use the technical reserves of Youku Play Center as the starting point, combined with the mirroring and circulation features of the Hongmeng system, and introduce in detail the core of normal circulation, free perspective and zoom. The way to practice ability on Hongmeng.
Thank you for your attention to [Alibaba Mobile Technology], see you in the next technical practice.
, 3 mobile technology practices & dry goods for you to think about every week!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。