忆往昔
忆往昔
  • 发布:2025-07-09 10:37
  • 更新:2025-07-09 10:50
  • 阅读:40

鸿蒙安装包制作失败

分类:鸿蒙Next

10:32:30.017 ​‌​787 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/utils/NetworkUtil.ets:638:12
10:32:30.017 ​‌​ The system capacity of this api 'sim' is not supported on all devices
10:32:30.017 ​‌​
10:32:30.017 ​‌​788 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/utils/NetworkUtil.ets:638:16
10:32:30.017 ​‌​ The system capacity of this api 'getCardType' is not supported on all devices
10:32:30.017 ​‌​
10:32:30.017 ​‌​789 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/utils/NetworkUtil.ets:648:12
10:32:30.017 ​‌​ The system capacity of this api 'sim' is not supported on all devices
10:32:30.017 ​‌​
10:32:30.017 ​‌​790 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/utils/NetworkUtil.ets:648:16
10:32:30.017 ​‌​ The system capacity of this api 'getCardTypeSync' is not supported on all devices
10:32:30.017 ​‌​
10:32:30.017 ​‌​791 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/uni_modules/ywx-getImageToBase64/utssdk/app-harmony/index.ets:20:40
10:32:30.017 ​‌​ 'PhotoViewPicker' has been deprecated.
10:32:30.017 ​‌​
10:32:30.017 ​‌​792 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/uni_modules/ywx-getImageToBase64/utssdk/app-harmony/index.ets:23:30
10:32:30.018 ​‌​ 'PhotoViewMIMETypes' has been deprecated.
10:32:30.018 ​‌​
10:32:30.018 ​‌​793 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/uni_modules/ywx-getImageToBase64/utssdk/app-harmony/index.ets:25:46
10:32:30.018 ​‌​ 'select' has been deprecated.
10:32:30.018 ​‌​
10:32:30.018 ​‌​794 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/uni_modules/ywx-getImageToBase64/utssdk/app-harmony/index.ets:88:50
10:32:30.018 ​‌​ 'packing' has been deprecated.
10:32:30.018 ​‌​
10:32:30.018 ​‌​795 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@dcloudio+uni-app-runtime@x9cchufx+nlphqkilywnd+j5ucb9h0b77g23wlkyhj0=/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/components/Picker.ets:115:9
10:32:30.018 ​‌​ The @Prop property 'range' cannot be an optional parameter.
10:32:30.018 ​‌​796 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@dcloudio+uni-app-runtime@x9cchufx+nlphqkilywnd+j5ucb9h0b77g23wlkyhj0=/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/components/Picker.ets:117:9
10:32:30.018 ​‌​ The @Prop property 'value' cannot be an optional parameter.
10:32:30.018 ​‌​797 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@dcloudio+uni-app-runtime@x9cchufx+nlphqkilywnd+j5ucb9h0b77g23wlkyhj0=/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/components/TabBar.ets:190:9
10:32:30.018 ​‌​ The @Prop property 'midButton' cannot be an optional parameter.
10:32:30.018 ​‌​798 WARN: ArkTS:WARN File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@dcloudio+uni-app-runtime@x9cchufx+nlphqkilywnd+j5ucb9h0b77g23wlkyhj0=/oh_modules/@dcloudio/uni-app-runtime/src/main/ets/uni-mp-sdk/components/TabBar.ets:204:21
10:32:30.018 ​‌​ The regular property 'item!' cannot be assigned to the @ObjectLink property 'item'.
10:32:30.018 1 ERROR: ArkTS:ERROR File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/entity/DialogOptions.ets:53:16
10:32:30.018 Cannot find name 'LevelOrder'. Did you mean 'LevelMode'?
10:32:30.018
10:32:30.018 2 ERROR: ArkTS:ERROR File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/action/DialogUtil.ets:118:7
10:32:30.018 Argument of type '{ title: ResourceStr; subtitle: ResourceStr; message: ResourceStr; alignment: DialogAlignment; offset: Offset; maskRect: Rectangle; ... 22 more ...; levelOrder: LevelOrder; }' is not assignable to parameter of type 'ActionSheetOptions'.
10:32:30.018 Object literal may only specify known properties, but 'levelOrder' does not exist in type 'ActionSheetOptions'. Did you mean to write 'levelMode'?
10:32:30.018
10:32:30.018 COMPILE RESULT:FAIL {ERROR:3 WARN:798}
10:32:30.018 > hvigor ERROR: BUILD FAILED in 11 s 879 ms
10:32:30.457 安装包制作失败

2025-07-09 10:37 负责人:无 分享
已邀请:
Adlaw

Adlaw

你写的uts有报错
10:32:30.018 1 ERROR: ArkTS:ERROR File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/entity/DialogOptions.ets:53:16
10:32:30.018 Cannot find name 'LevelOrder'. Did you mean 'LevelMode'?
10:32:30.018
10:32:30.018 2 ERROR: ArkTS:ERROR File: D:/A-Project/whonemap/OneMap.App/unpackage/dist/build/app-harmony/oh_modules/.ohpm/@pura+harmony-utils@1.3.6/oh_modules/@pura/harmony-utils/src/main/ets/action/DialogUtil.ets:118:7
10:32:30.018 Argument of type '{ title: ResourceStr; subtitle: ResourceStr; message: ResourceStr; alignment: DialogAlignment; offset: Offset; maskRect: Rectangle; ... 22 more ...; levelOrder: LevelOrder; }' is not assignable to parameter of type 'ActionSheetOptions'.
10:32:30.018 Object literal may only specify known properties, but 'levelOrder' does not exist in type 'ActionSheetOptions'. Did you mean to write 'levelMode'?

  • 忆往昔 (作者)

    import picker from '@ohos.file.picker';

    import fs from '@ohos.file.fs';

    import image from '@ohos.multimedia.image';

    import { ImageUtil } from '@pura/harmony-utils';


    import picker2 from '@ohos.multimedia.cameraPicker'

    import camera from '@ohos.multimedia.camera';

    import common from '@ohos.app.ability.common';

    // import { BusinessError } from '@ohos.base';

    import fileuri from '@ohos.file.fileuri';

    // import fs from '@ohos.file.fs';

    import { buffer } from '@kit.ArkTS';

    import { image as image2 } from '@kit.ImageKit';


    import { Want, common as common2 } from '@kit.AbilityKit';


    import bundleManager from '@ohos.bundle.bundleManager';

    import { BusinessError } from '@ohos.base';


    // 拉起相册选择图片并转为Base64

    export async function chooseImageHarmony(): Promise<string> {

    let file: fs.File | null = null;

    let imageSource: image.ImageSource | null = null;

    let pixelMap: image.PixelMap | null = null;


    try {  
    // 1. 调用文件选择器
    const photoPicker = new picker.PhotoViewPicker();
    const selectOptions: picker.PhotoSelectOptions = {
    maxSelectNumber: 1, // 限制只能选择 1 张图片
    MIMEType: picker.PhotoViewMIMETypes.IMAGE_TYPE, // 可选:限制图片类型
    };
    const fileResult = await photoPicker.select(selectOptions);

    // 2. 获取到URI
    const uri = fileResult.photoUris[0];

    // 3. 使用文件描述符
    file = fs.openSync(uri, fs.OpenMode.READ_ONLY);

    // 4. 创建ImageSource并获取PixelMap
    imageSource = image.createImageSource(file.fd);

    // 5. 获取图片属性来得到原始尺寸
    const imageInfo = await imageSource.getImageInfo();
    const originalWidth = imageInfo.size.width;
    const originalHeight = imageInfo.size.height;

    // 6. 定义压缩选项 - 使用正确的类型声明
    const decodingOptions: image.DecodingOptions = {
    desiredSize: {
    width: Math.min(800, originalWidth), // 不超过800px
    height: Math.round((Math.min(800, originalWidth) / originalWidth) * originalHeight)
    },
    desiredPixelFormat: image.PixelMapFormat.RGBA_8888,
    // 以下是必须包含的默认值
    desiredRegion: {
    size: { width: originalWidth, height: originalHeight },
    x: 0,
    y: 0
    },
    editable: false
    };

    pixelMap = await imageSource.createPixelMap(decodingOptions);

    // 7. 转换为Base64
    const base64Str: string = await ImageUtil.pixelMapToBase64Str(pixelMap);

    return base64Str
    } catch (error) {
    return ""
    } finally {
    imageSource?.release()
    pixelMap?.release();
    // 关闭文件(使用 fs.close(file.fd))
    if (file?.fd !== undefined) {
    fs.close(file.fd); // ✅ HarmonyOS NEXT 使用 fs.close(fd)
    }
    }

    }


    class CameraPosition {

    cameraPosition: camera.CameraPosition;

    saveUri: string;


    constructor(cameraPosition: camera.CameraPosition, saveUri: string) {

    this.cameraPosition = cameraPosition;

    this.saveUri = saveUri;

    }

    }


    // 拉起相机拍照并转为Base64

    export async function takePhotoAndConvertToBase64(): Promise<string> {

    let base64Str = ''

    // 获取上下文

    const context = getContext() as common.Context;

    const pathDir = context.filesDir;

    // 文件临时路径

    const filePath = pathDir + '/' + new Date().getTime() + '.jpg';


    fs.createRandomAccessFileSync(filePath, fs.OpenMode.CREATE);

    const uri = fileuri.getUriFromPath(filePath);


    try {

    // 唤起相机

    let pickerProfile = new CameraPosition(camera.CameraPosition.CAMERA_POSITION_BACK, uri);

    await picker2.pick(context, [picker2.PickerMediaType.PHOTO], pickerProfile);

    const file = await fs.open(uri, fs.OpenMode.READ_ONLY);


    const imageSource: image.ImageSource = image2.createImageSource(file.fd);  
    const imagePackerApi = image2.createImagePacker();
    const packOpts: image.PackingOption = { format: "image/jpeg", quality: 70 };

    const imageBuffer = await imagePackerApi.packing(imageSource, packOpts);
    base64Str = buffer.from(imageBuffer).toString('base64');
    const base64Str2 = 'data:image/jpeg;base64,' + base64Str;

    return base64Str2;

    } catch (error) {

    // let err = error as BusinessError;

    console.error(拍照失败);

    return '';

    } finally {


    }  

    }


    // 打开外部的华为浏览器并跳转

    export function openBrowser(url: string): void {

    // 1. 获取正确的上下文

    const context = getContext() as common2.UIAbilityContext;


    // 2. 明确定义 Want 类型

    const want: Want = {

    "action": "ohos.want.action.viewData",

    "entities": ["entity.system.browsable"],

    "uri": url,

    "type": "text/plain"

    };


    // 3. 正确处理 Promise 类型

    context.startAbility(want)

    .then((): void => { // 明确指定返回类型

    console.log('openUrl: successfully');

    })

    .catch((err: Error): void => { // 明确指定返回类型和错误类型

    console.error('openURL Failed:', err);

    });

    }


    // 打开鸿蒙应用商店并跳转

    export function openAppMarket(url: string): void {

    // 1. 获取正确的上下文

    const context = getContext() as common2.UIAbilityContext;


    const appMarketWant: Want = {

    uri: url,

    };


    context.startAbility(appMarketWant)

    .then((): void => {

    console.log('AppMarket opened successfully');

    })

    .catch((err: Error): void => {

    console.error('Failed to open AppMarket:', err);

    });

    }


    // 检测是否安装高德地图APP

    export async function isGaodeMapInstalled(): Promise<boolean> {

    let exist: boolean = false;

    try {

    let link: string = 'amapuri://com.amap.hmapp/open';

    let data: boolean = bundleManager.canOpenLink(link);

    console.log(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));

    exist = data;

    } catch (err) {

    let message = (err as BusinessError).message;

    console.log(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);

    exist = false;

    }

    return exist;

    }


    // 检测是否安装百度地图APP

    export async function isBaiduMapInstalled(): Promise<boolean> {

    let exist: boolean = false;

    try {

    let link: string = 'baidumap://map/direction';

    let data: boolean = bundleManager.canOpenLink(link);

    console.log(0x0000, 'testTag', 'canOpenLink successfully: %{public}s', JSON.stringify(data));

    exist = data;

    } catch (err) {

    let message = (err as BusinessError).message;

    console.log(0x0000, 'testTag', 'canOpenLink failed: %{public}s', message);

    exist = false;

    }

    return exist;

    }


    // 打开高德地图导航

    export function openAmapNavigation(name: string, slon: number,slat: number, dlon: number,dlat: number): Promise<void> {

    const uri = amapuri://route/plan?sid=BGVIS1&dlat=${dlat}&dname=${name}&slat=${slat}&dlon=${dlon}&did=BGVIS2&slon=${slon}&sname=我的位置&t=0;

    // 1. 获取正确的上下文

    const context = getContext() as common2.UIAbilityContext;

    return new Promise((resolve, reject) => {

    const want: Want = {

    action: 'ohos.want.action.viewData',

    uri: uri

    };


    context.startAbility(want)  
    .then(resolve)
    .catch(reject);

    });

    }


    // 打开百度地图导航

    export function openBaiduMapNavigation(name: string, slon: number, slat: number, dlon: number, dlat: number): Promise<void> {

    const uri = baidumap://map/direction?origin=${slat},${slon}|name:我的位置&destination=${dlat},${dlon}|name:${name}&mode=driving&coord_type=wgs84;


    const context = getContext() as common2.UIAbilityContext;

    return new Promise((resolve, reject) => {

    const want: Want = {

    action: 'ohos.want.action.viewData',

    uri: uri

    };


    context.startAbility(want)  
    .then(resolve)
    .catch(reject);

    });

    }

    2025-07-09 11:12

  • 忆往昔 (作者)

    两个月前都是正常的,是不是官方版本更新或者加了校验啥的

    2025-07-09 11:13

DCloud_UNI_yuhe

DCloud_UNI_yuhe

提供一下出问题的代码看看

  • 忆往昔 (作者)

    这个都是uniapp编译之前的啊,应该没啥问题吧

    2025-07-09 11:14

  • DCloud_UNI_yuhe

    回复 忆往昔: 之前使用哪个版本?

    2025-07-09 12:01

  • DCloud_UNI_yuhe

    回复 忆往昔: 看起来你提供的代码没有报错中提到的内容,你可以直接提供一下 uts 插件吗?

    2025-07-09 12:03

  • 忆往昔 (作者)

    回复 DCloud_UNI_yuhe: 上面的一长串就是uts的代码

    2025-07-09 12:38

要回复问题请先登录注册