diff --git a/ohos/.gitignore b/ohos/.gitignore new file mode 100644 index 000000000..40a5e7280 --- /dev/null +++ b/ohos/.gitignore @@ -0,0 +1,22 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +/.previewer +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +**/BuildProfile.ets +**/oh-package-lock.json5 +/package.json +/package-lock.json + +**/src/main/resources/rawfile/flutter_assets/ +**/libs/**/libapp.so +**/libs/**/libflutter.so +**/libs/**/libvmservice_snapshot.so +**/libs/**/libtdjson.so diff --git a/ohos/AppScope/app.json5 b/ohos/AppScope/app.json5 new file mode 100644 index 000000000..8ceb9e202 --- /dev/null +++ b/ohos/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "ad.neko.mithka", + "vendor": "mithka", + "versionCode": 295, + "versionName": "1.8.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ohos/AppScope/resources/base/element/string.json b/ohos/AppScope/resources/base/element/string.json new file mode 100644 index 000000000..7430edbec --- /dev/null +++ b/ohos/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Mithka" + } + ] +} diff --git a/ohos/AppScope/resources/base/media/app_icon.png b/ohos/AppScope/resources/base/media/app_icon.png new file mode 100644 index 000000000..ce307a882 Binary files /dev/null and b/ohos/AppScope/resources/base/media/app_icon.png differ diff --git a/ohos/README.md b/ohos/README.md new file mode 100644 index 000000000..1b58856b9 --- /dev/null +++ b/ohos/README.md @@ -0,0 +1,31 @@ +# Mithka HarmonyOS (ohos) 宿主工程 + +mithka 的 HarmonyOS NEXT 宿主工程,由鸿蒙 Flutter fork 的 `flutter create --platforms ohos` 生成并定制。Dart 侧构建由 `flutter build hap` 驱动,本目录只包含工程结构与应用配置。 + +## 环境要求 + +- 鸿蒙 Flutter fork(openharmony-sig/flutter_flutter)3.44.9+ohos 及以上,需在 PATH 中 +- DevEco Studio command-line-tools,SDK API 26 及以上(`DEVECO_SDK_HOME` 指向其 sdk 目录)——这是未打补丁的引擎 embedding 所需的 SDK;CI 使用已验证的 API 22 镜像与受控的 embedding HAR 兼容补丁(见 .github/workflows/release.yml 的 `Patch the engine embedding HAR` 步骤)作为同一可支持组合,本地无需补丁时请升级至 API 26 +- hvigor / ohpm / node(command-line-tools 自带,加入 PATH) + +版本低于要求时的典型症状:hvigor 编译 ArkTS 报 `Namespace 'autoFillManager' has no exported member 'AutoFillType'`——这是引擎 embedding 依赖 API 26 类型,升级 command-line-tools 至 API 26 即可;CI 的 API 22 路径通过 pinned 的 embedding HAR 补丁(本地类型别名 + 仅在 API 26 以下 early-return 的辅助)使同一源码在 API 22 SDK 上可编译,行为保持一致。 + +## 构建 + +```sh +# 1. 安装 TDLib 原生库(每次检出后一次;从未签名,产物为 unsigned HAP) +./scripts/build-hap.sh + +# 2. 构建 HAP +flutter build hap --target-platform ohos-arm64 --release +``` + +产物路径:`ohos/entry/build/default/outputs/default/entry-default-signed.hap`(未配置签名时为 unsigned 产物,CI 直接使用)。 + +首次构建前 flutter 工具会在 `ohos/` 下自动生成 `package.json`、`node_modules/`、`oh_modules/` 等本地文件,均已被 .gitignore 忽略。 + +## 目录说明 + +- `AppScope/`:应用级配置(bundleName、版本、图标、名称) +- `entry/`:入口 HAP 模块;`entry/libs/arm64-v8a/` 是 tdjson 安装目标 +- `hvigorfile.ts` / `hvigor/` / `build-profile.json5`:hvigor 构建配置 diff --git a/ohos/build-profile.json5 b/ohos/build-profile.json5 new file mode 100644 index 000000000..1c112b1a1 --- /dev/null +++ b/ohos/build-profile.json5 @@ -0,0 +1,39 @@ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.1.0(18)", + "runtimeOS": "HarmonyOS", + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "profile" + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ohos/entry/.gitignore b/ohos/entry/.gitignore new file mode 100644 index 000000000..5254b880d --- /dev/null +++ b/ohos/entry/.gitignore @@ -0,0 +1,7 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test +GeneratedPluginRegistrant.ets \ No newline at end of file diff --git a/ohos/entry/build-profile.json5 b/ohos/entry/build-profile.json5 new file mode 100644 index 000000000..6de31ee22 --- /dev/null +++ b/ohos/entry/build-profile.json5 @@ -0,0 +1,15 @@ + +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + "runtimeOS": "HarmonyOS" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ohos/entry/hvigorfile.ts b/ohos/entry/hvigorfile.ts new file mode 100644 index 000000000..ff3bfe082 --- /dev/null +++ b/ohos/entry/hvigorfile.ts @@ -0,0 +1,7 @@ + +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins: [] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ohos/entry/oh-package.json5 b/ohos/entry/oh-package.json5 new file mode 100644 index 000000000..854eec208 --- /dev/null +++ b/ohos/entry/oh-package.json5 @@ -0,0 +1,11 @@ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {}, +} + diff --git a/ohos/entry/src/main/ets/entryability/EntryAbility.ets b/ohos/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 000000000..f85a65508 --- /dev/null +++ b/ohos/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,10 @@ + +import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos'; +import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; + +export default class EntryAbility extends FlutterAbility { + configureFlutterEngine(flutterEngine: FlutterEngine) { + super.configureFlutterEngine(flutterEngine) + GeneratedPluginRegistrant.registerWith(flutterEngine) + } +} diff --git a/ohos/entry/src/main/ets/pages/Index.ets b/ohos/entry/src/main/ets/pages/Index.ets new file mode 100644 index 000000000..7bb6543fe --- /dev/null +++ b/ohos/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,24 @@ + +import common from '@ohos.app.ability.common'; +import { FlutterPage } from '@ohos/flutter_ohos' + +let storage = LocalStorage.getShared() +const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS' + +@Entry(storage) +@Component +struct Index { + private context = getContext(this) as common.UIAbilityContext + @LocalStorageLink('viewId') viewId: string = ""; + + build() { + Column() { + FlutterPage({ viewId: this.viewId }) + } + } + + onBackPress(): boolean { + this.context.eventHub.emit(EVENT_BACK_PRESS) + return true + } +} \ No newline at end of file diff --git a/ohos/entry/src/main/module.json5 b/ohos/entry/src/main/module.json5 new file mode 100644 index 000000000..152764129 --- /dev/null +++ b/ohos/entry/src/main/module.json5 @@ -0,0 +1,63 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + }, + { + // External deep links: the tg scheme (tg://resolve?domain=…) + // plus the https universal-link host, the same pair Android + // declares. Without these skills the ability can never be a + // launch target for a link and app_links sees nothing to deliver. + "entities": [ + "entity.system.browsable" + ], + "actions": [ + "ohos.want.action.viewData" + ], + "uris": [ + { + "scheme": "tg" + }, + { + "scheme": "https", + "host": "t.me" + } + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" + } + ] + } +} \ No newline at end of file diff --git a/ohos/entry/src/main/resources/base/element/color.json b/ohos/entry/src/main/resources/base/element/color.json new file mode 100644 index 000000000..3c712962d --- /dev/null +++ b/ohos/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/entry/src/main/resources/base/element/string.json b/ohos/entry/src/main/resources/base/element/string.json new file mode 100644 index 000000000..65f9ab450 --- /dev/null +++ b/ohos/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Mithka" + } + ] +} \ No newline at end of file diff --git a/ohos/entry/src/main/resources/base/media/icon.png b/ohos/entry/src/main/resources/base/media/icon.png new file mode 100644 index 000000000..ce307a882 Binary files /dev/null and b/ohos/entry/src/main/resources/base/media/icon.png differ diff --git a/ohos/entry/src/main/resources/base/profile/main_pages.json b/ohos/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 000000000..1898d94f5 --- /dev/null +++ b/ohos/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ohos/entry/src/main/resources/en_US/element/string.json b/ohos/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 000000000..65f9ab450 --- /dev/null +++ b/ohos/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Mithka" + } + ] +} \ No newline at end of file diff --git a/ohos/entry/src/main/resources/zh_CN/element/string.json b/ohos/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 000000000..507d9b9b4 --- /dev/null +++ b/ohos/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Mithka" + } + ] +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/ets/test/Ability.test.ets b/ohos/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 000000000..460ec4db1 --- /dev/null +++ b/ohos/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import hilog from '@ohos.hilog'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain',0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/ets/test/List.test.ets b/ohos/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 000000000..61e4b4033 --- /dev/null +++ b/ohos/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets b/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets new file mode 100644 index 000000000..d4f8a9c47 --- /dev/null +++ b/ohos/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -0,0 +1,47 @@ +import UIAbility from '@ohos.app.ability.UIAbility'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; +import hilog from '@ohos.hilog'; +import { Hypium } from '@ohos/hypium'; +import testsuite from '../test/List.test'; +import window from '@ohos.window'; + import { AbilityConstant, Want } from '@kit.Abilitykit'; + +export default class TestAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); + hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); + hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); + let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate'); + windowStage.loadContent('testability/pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy'); + } + + onForeground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground'); + } + + onBackground() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground'); + } +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets b/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets new file mode 100644 index 000000000..545843d39 --- /dev/null +++ b/ohos/entry/src/ohosTest/ets/testability/pages/Index.ets @@ -0,0 +1,36 @@ + + +import hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear'); + } + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts b/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts new file mode 100644 index 000000000..47fc89b4f --- /dev/null +++ b/ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,50 @@ + +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/module.json5 b/ohos/entry/src/ohosTest/module.json5 new file mode 100644 index 000000000..3b02a75a2 --- /dev/null +++ b/ohos/entry/src/ohosTest/module.json5 @@ -0,0 +1,37 @@ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/testability/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/ohos/entry/src/ohosTest/resources/base/element/color.json b/ohos/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 000000000..3c712962d --- /dev/null +++ b/ohos/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/resources/base/element/string.json b/ohos/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 000000000..65d8fa5a7 --- /dev/null +++ b/ohos/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/ohos/entry/src/ohosTest/resources/base/media/icon.png b/ohos/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 000000000..ce307a882 Binary files /dev/null and b/ohos/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json b/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 000000000..b7e7343ca --- /dev/null +++ b/ohos/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "testability/pages/Index" + ] +} diff --git a/ohos/hvigor/hvigor-config.json5 b/ohos/hvigor/hvigor-config.json5 new file mode 100644 index 000000000..ad3ecab4a --- /dev/null +++ b/ohos/hvigor/hvigor-config.json5 @@ -0,0 +1,6 @@ + +{ + "modelVersion": "5.1.0", + "dependencies": { + } +} \ No newline at end of file diff --git a/ohos/hvigorconfig.ts b/ohos/hvigorconfig.ts new file mode 100644 index 000000000..fc2b20863 --- /dev/null +++ b/ohos/hvigorconfig.ts @@ -0,0 +1,4 @@ +import path from 'path' +import { injectNativeModules } from 'flutter-hvigor-plugin'; + +injectNativeModules(__dirname, path.dirname(__dirname)) \ No newline at end of file diff --git a/ohos/hvigorfile.ts b/ohos/hvigorfile.ts new file mode 100644 index 000000000..a64db460c --- /dev/null +++ b/ohos/hvigorfile.ts @@ -0,0 +1,8 @@ +import path from 'path' +import { appTasks } from '@ohos/hvigor-ohos-plugin'; +import { flutterHvigorPlugin } from 'flutter-hvigor-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[flutterHvigorPlugin(path.dirname(__dirname))] /* Custom plugin to extend the functionality of Hvigor. */ +} \ No newline at end of file diff --git a/ohos/oh-package.json5 b/ohos/oh-package.json5 new file mode 100644 index 000000000..701402ab9 --- /dev/null +++ b/ohos/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "modelVersion": "5.1.0", + "name": "mithka", + "version": "1.0.0", + "description": "Mithka HarmonyOS host project", + "main": "", + "author": "", + "license": "", + "dependencies": {}, + "devDependencies": { + "@ohos/hypium": "1.0.6" + } +} diff --git a/scripts/build-hap.sh b/scripts/build-hap.sh new file mode 100755 index 000000000..2eb5d7cd0 --- /dev/null +++ b/scripts/build-hap.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Installs the pinned TDLib HarmonyOS library into the ohos host project, +# where hvigor bundles entry/libs// natively-linked .so files into the +# HAP. Run this before `flutter build hap`. The script never signs: CI builds +# unsigned HAPs with hvigorw and signs in a later controlled step. +# +# Usage: +# ./scripts/build-hap.sh # install tdjson (required once per checkout) +# flutter build hap --target-platform ohos-arm64 --release +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +LIBS_DIR="$REPO_ROOT/ohos/entry/libs/arm64-v8a" + +if command -v python3 >/dev/null 2>&1; then + PYTHON=python3 +elif command -v python >/dev/null 2>&1; then + PYTHON=python +else + echo "error: Python 3 is required to install tdjson artifacts" >&2 + exit 1 +fi + +mkdir -p "$LIBS_DIR" + +"$PYTHON" "$SCRIPT_DIR/install-tdjson-artifact.py" \ + "tdjson-ohos-arm64.zip" \ + "$LIBS_DIR/libtdjson.so" \ + --member "arm64-v8a/libtdjson.so" \ + --mode 0755 + +echo "Installed pinned HarmonyOS tdjson library. Run: flutter build hap --target-platform ohos-arm64 --release" diff --git a/scripts/install-tdjson-artifact.py b/scripts/install-tdjson-artifact.py index 2c538acda..eb4dc1d25 100755 --- a/scripts/install-tdjson-artifact.py +++ b/scripts/install-tdjson-artifact.py @@ -53,6 +53,7 @@ "tdjson-linux-arm64.zip": {"libtdjson.so"}, "tdjson-linux-x64.zip": {"libtdjson.so"}, "tdjson-macos-universal.zip": {"libtdjson.dylib"}, + "tdjson-ohos-arm64.zip": {"arm64-v8a/libtdjson.so"}, "tdjson-windows-arm64.zip": {"tdjson.dll"}, "tdjson-windows-x64.zip": {"tdjson.dll"}, } @@ -209,7 +210,21 @@ def load_manifest(path): require_exact_keys(assets, set(EXPECTED_MEMBERS), "manifest assets") for asset_name, expected_members in EXPECTED_MEMBERS.items(): asset = assets[asset_name] - require_exact_keys(asset, {"sha256", "size", "members"}, asset_name) + # Per-asset pinned releases may override the global release_tag (used + # for the HarmonyOS secondary release so the single manifest can pin + # assets from two immutable tags). Only sha256/size/members are the + # validated shape; an optional release_tag is accepted but not required. + allowed_keys = {"sha256", "size", "members"} + extra = set(asset) - allowed_keys + if extra == {"release_tag"}: + require_string(asset["release_tag"], f"{asset_name}.release_tag", RELEASE_TAG_PATTERN) + elif extra: + raise InstallError( + f"{asset_name} has unexpected keys: " + f"expected {sorted(allowed_keys)} or {sorted(allowed_keys | {'release_tag'})}, " + f"got {sorted(asset)}" + ) + # Validate the canonical fields even when release_tag is present. require_string(asset["sha256"], f"{asset_name}.sha256", SHA256_PATTERN) require_positive_int(asset["size"], f"{asset_name}.size") members = asset["members"] @@ -424,6 +439,11 @@ def release_url(release_tag, asset_name): ) +def release_tag_for_asset(manifest, asset_name): + asset = manifest["assets"][asset_name] + return asset.get("release_tag", manifest["release_tag"]) + + def download(url, destination, expected_size): request = urllib.request.Request( url, headers={"User-Agent": "Mithka-tdjson-installer/2"} @@ -612,8 +632,9 @@ def run(args): with tempfile.TemporaryDirectory(prefix="mithka-tdjson-") as temporary: if args.archive is None: archive_path = Path(temporary) / args.asset - url = release_url(manifest["release_tag"], args.asset) - print(f"Downloading {args.asset} from {manifest['release_tag']}") + release_tag = release_tag_for_asset(manifest, args.asset) + url = release_url(release_tag, args.asset) + print(f"Downloading {args.asset} from {release_tag}") download(url, archive_path, asset["size"]) else: archive_path = args.archive diff --git a/scripts/tdjson-manifest.json b/scripts/tdjson-manifest.json index b50e779ef..a05c27cd4 100644 --- a/scripts/tdjson-manifest.json +++ b/scripts/tdjson-manifest.json @@ -102,6 +102,17 @@ "sha256": "2b386ea26ddbc847efc4a9577cf8b552ab02e376c34e7ca0dad0823f9373880d", "size": 21792143 }, + "tdjson-ohos-arm64.zip": { + "members": { + "arm64-v8a/libtdjson.so": { + "sha256": "e8996f897b2e7307a3f0f6c31219d9cb45a6065b214edccf08217af3c9a7438c", + "size": 5242880 + } + }, + "release_tag": "tdjson-ohos-1.8.68-c15d3f5a5de6-mithka-2e7f8ff14657-build-f6b13ce5aa13-v2", + "sha256": "02b825c75363fae3ff1e4456b3e78238e9462cac3e5dd4aec2aec3e014b16fcf", + "size": 15479 + }, "tdjson-windows-arm64.zip": { "members": { "tdjson.dll": { diff --git a/test/tdjson_artifact_configuration_test.dart b/test/tdjson_artifact_configuration_test.dart index b7b309891..8e63893fa 100644 --- a/test/tdjson_artifact_configuration_test.dart +++ b/test/tdjson_artifact_configuration_test.dart @@ -24,6 +24,7 @@ void main() { 'tdjson-macos-universal.zip': {'libtdjson.dylib'}, 'tdjson-windows-arm64.zip': {'tdjson.dll'}, 'tdjson-windows-x64.zip': {'tdjson.dll'}, + 'tdjson-ohos-arm64.zip': {'arm64-v8a/libtdjson.so'}, }; test('TDJSON schema-v2 manifest pins every supported release artifact', () { @@ -66,7 +67,14 @@ void main() { expect(assets.keys, unorderedEquals(expectedMembers.keys)); for (final entry in expectedMembers.entries) { final asset = assets[entry.key] as Map; - expect(asset.keys, unorderedEquals(['sha256', 'size', 'members'])); + // The OHOS asset is published under a separate immutable release tag, + // so only it carries the optional release pin the installer downloads. + expect( + asset.keys, + entry.key == 'tdjson-ohos-arm64.zip' + ? unorderedEquals(['sha256', 'size', 'members', 'release_tag']) + : unorderedEquals(['sha256', 'size', 'members']), + ); expect(asset['sha256'], matches(RegExp(r'^[0-9a-f]{64}$'))); expect(asset['size'], isA()); expect(asset['size'] as int, greaterThan(0)); diff --git a/test/tdjson_artifact_installer_test.dart b/test/tdjson_artifact_installer_test.dart index 74531823e..886314575 100644 --- a/test/tdjson_artifact_installer_test.dart +++ b/test/tdjson_artifact_installer_test.dart @@ -25,6 +25,7 @@ const _expectedMembers = >{ 'tdjson-macos-universal.zip': {'libtdjson.dylib'}, 'tdjson-windows-arm64.zip': {'tdjson.dll'}, 'tdjson-windows-x64.zip': {'tdjson.dll'}, + 'tdjson-ohos-arm64.zip': {'arm64-v8a/libtdjson.so'}, }; const _linuxAsset = 'tdjson-linux-x64.zip';