openharmony体验

openharmony5 去年已经出来了

如果以前做过android开发的,学起来不难,关键

1:环境

DevEco Studio 5.0.3 Beta2 https://developer.huawei.com/consumer/cn/deveco-studio/

win10_64bit

CPU amd64(不是arm的)

2:安装

执行EXE 安装就行,网上一堆

API 自由选择

registry=https://repo.huaweicloud.com/repository/npm/

@ohos:registry=https://repo.harmonyos.com/npm/

创建模拟器

tools->device manger

随便创建个工程

修改 build-profile.json5 可以是在 entry目录下 增加 abiFilters x86_64 默认为 arm ,x86模拟器装不上

改成 "runtimeOS": "OpenHarmony" 才是openharmony

javascript 复制代码
{
  "apiType": 'stageMode',
  "buildOption": {
    "externalNativeOptions": {
      "abiFilters": ["arm64-v8a", "x86_64"],
      "path": "./src/main/cpp/CMakeLists.txt",
      "arguments": "",
      "cppFlags": "",
    }
  },
  "targets": [
    {
      "name": "default",
      "runtimeOS": "HarmonyOS"
    },
    {
      "name": "ohosTest",
    }
  ]
}

3:DEMO测试

直接来个native c++



出现下面的问题,就是要先把模拟器器开起来

自带 export const add: (a: number, b: number) => number;

typescript 复制代码
import { hilog } from '@kit.PerformanceAnalysisKit';
import testNapi from 'libentry.so';
import StyleConstants from '../common/constants/StyleConstants';
import CommonConstants from '../common/constants/CommonConstants';

const DOMAIN = 0x0000;

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  @State number1: number|string = '';
  @State number2: number|string = '';
  @State result:  string ="";

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize($r('app.float.page_text_font_size'))
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            this.message = 'Welcome';
            hilog.info(DOMAIN, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
          })
        TextInput({ placeholder: $r('app.string.inputnumber1') })
          .maxLength(StyleConstants.INPUT_ACCOUNT_LENGTH)
          .type(InputType.Number)
          .inputStyle()
          .onChange((value: string) => {
            this.number1 = value;
          })

        TextInput({ placeholder: $r('app.string.inputnumber2') })
          .maxLength(StyleConstants.INPUT_ACCOUNT_LENGTH)
          .type(InputType.Number)
          .inputStyle()
          .onChange((value: string) => {
            this.number2 = value;
          })
        Button($r('app.string.count'))
          .id(CommonConstants.LOGIN_BUTTON_ID)
          .width(StyleConstants.FULL_PARENT)
          .height($r('app.float.login_button_height'))
          .fontSize($r('app.float.normal_text_size'))
          .fontWeight(FontWeight.Medium)
          .backgroundColor($r('app.color.login_button_color'))
          .margin({
            top: $r('app.float.login_button_top'),
            bottom: $r('app.float.login_button_bottom')
          })
          .onClick(() => {
            let num1 = 0,num2 =0;
            if(typeof this.number1 === 'string'){
              num1 = parseInt(this.number1);
            }else if (typeof this.number1 === 'number'){
              num1 = this.number1;
            }

            if(typeof this.number2 === 'string'){
              num2 = parseInt(this.number2);
            }else if (typeof this.number2 === 'number'){
              num2 = this.number2;
            }
            this.result = testNapi.add(num1,num2).toString(10);
          })
        Text(this.result)
          .fontColor($r('app.color.blue_text_color'))
          .fontSize($r('app.float.normal_text_size'))
          .fontWeight(FontWeight.Medium)
      }
      .width('100%')
    }
    .height('100%')
  }
}

@Extend(TextInput) function inputStyle() {
  .placeholderColor($r('app.color.placeholder_color'))
  .height($r('app.float.login_input_height'))
  .fontSize($r('app.float.normal_text_size'))
  .backgroundColor(Color.White)
  .margin({ top: $r('app.float.input_margin_top') })
  .padding({ left: StyleConstants.INPUT_PADDING_LEFT })
}

@Extend(Text) function blueTextStyle() {
  .fontColor($r('app.color.blue_text_color'))
  .fontSize($r('app.float.small_text_size'))
  .fontWeight(FontWeight.Medium)
}

当前API 为15 跑14的模拟器,跑不起来

需要调下API 为14

APP name


4: 没有开发版,支持 openharmony5 开发版都不便宜,1500+起,

HarmonyOS 才能用模拟器,测试用不起,这狗屎的生态,

5:如果觉得有用,麻烦点个赞,加个收藏

相关推荐
熊猫钓鱼>_>8 天前
【开源鸿蒙跨平台开发先锋训练营】React Native 工程化实践:Hooks 封装与跨端 API 归一化
react native·react.js·华为·开源·harmonyos·鸿蒙·openharmony
熊猫钓鱼>_>9 天前
【开源鸿蒙跨平台开发先锋训练营】React Native 性能巅峰:HarmonyOS极致优化实战手册
react native·react.js·华为·开源·harmonyos·鸿蒙·openharmony
柒儿吖9 天前
DDlog 高性能异步日志库在 OpenHarmony 的 lycium 适配与分步测试
c++·c#·openharmony
熊猫钓鱼>_>9 天前
【开源鸿蒙跨平台开发先锋训练营】Day20 React Native 鸿蒙开发全阶段大复盘:从零到一的跨越
react native·开源·react·harmonyos·鸿蒙·openharmony·native
柒儿吖9 天前
rudp Reliable UDP 库在 OpenHarmony 的 lycium 适配与 CRC32 测试
c++·c#·openharmony
柒儿吖9 天前
三方库 Boost.Regex 在 OpenHarmony 的 lycium完整实践
c++·c#·openharmony
柒儿吖10 天前
三方库 Emoji Segmenter 在 OpenHarmony 的 lycium 适配与测试
c++·c#·openharmony
ujainu小11 天前
节日倒数日历 —— Flutter + OpenHarmony 鸿蒙风温暖实用工具
flutter·openharmony·节日
ujainu12 天前
从零开始:用 Flutter + OpenHarmony 构建青绿山水风五子棋(一)—— 棋盘绘制与双人对战
flutter·openharmony
ujainu小12 天前
脑力激荡:简易数独生成器 —— Flutter + OpenHarmony 鸿蒙风益智小游戏
flutter·华为·openharmony