目录

openharmony体验

目录

openharmony体验

openharmony5 去年已经出来了

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

1:环境

DevEco Studio 5.0.3 Beta2

win10_64bit

CPU amd64(不是arm的)

2:安装

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

API 自由选择 https://i-blog.csdnimg.cn/direct/dc26f6719fc2420d81324be2a4a4c34b.png

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

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

https://i-blog.csdnimg.cn/direct/e11cab3898b040f99a331c18bda351ed.png

创建模拟器

tools->device manger

https://i-blog.csdnimg.cn/direct/b25dfc9cb98e46059f7fedf4f9c9d289.png

随便创建个工程

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

改成 “runtimeOS”: “OpenHarmony” 才是openharmony

{
  "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++

https://i-blog.csdnimg.cn/direct/934f26e981344e73ac698ae5d917e6fa.png

https://i-blog.csdnimg.cn/direct/2c4f0203428c427cb5ee27b5064c81ba.png

https://i-blog.csdnimg.cn/direct/4044f9490480476da453fee636401d77.png

https://i-blog.csdnimg.cn/direct/524082653d7f4c5292f9efc38aa2cfdb.png

出现下面的问题,就是要先把模拟器器开起来 https://i-blog.csdnimg.cn/direct/31283e078d9d4d6c893487c4fbcdd548.png

https://i-blog.csdnimg.cn/direct/080e7045f5464c32b7cc94dde3ae8276.png

https://i-blog.csdnimg.cn/direct/2072ceccec7c404b98b81b6bff5f89fa.png

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)
}

https://i-blog.csdnimg.cn/direct/777a1463178745b9939e9151cd38b062.png

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

https://i-blog.csdnimg.cn/direct/3a1b1e10fbf44cb48f42829271f0732c.png

需要调下API 为14

https://i-blog.csdnimg.cn/direct/a57c96bc7599432ca601baf5ba6d89e7.png

APP name

https://i-blog.csdnimg.cn/direct/42cb785e82b04f3ca301f978726fc286.png

https://i-blog.csdnimg.cn/direct/d5890fca36384eb69adc49d48ff2a02f.png

https://i-blog.csdnimg.cn/direct/ea534f1685d14fcc90a55622bca2c364.png

https://i-blog.csdnimg.cn/direct/5683d2f1b87945fcb32b1ca91c7129b5.png

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

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

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