杨新春

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  100 随笔 :: 0 文章 :: 4 评论 :: 50779 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1、工程级目录build-profile.json5

复制代码
{
    "app": {
        "signingConfigs": [
            {
                "name": "default",
                "type": "HarmonyOS",
                "material": {
                    "storePassword": "000000196F3CD9CC858474C62B5903102CFAE25D806AC29DA9EB3202FD6414CD8A4A47F8222BF2B57E",
                    "certpath": "C:/Users/vfuchong/.ohos/鸿蒙生产.cer",
                    "keyAlias": "yxc123654",
                    "keyPassword": "00000019858F695A8BBC666201620F3F3891DC51460652ED2495D8BB7FC2F731045FAA3D8A099D03FF",
                    "profile": "C:/Users/vfuchong/.ohos/鸿蒙生产Release.p7b",
                    "signAlg": "SHA256withECDSA",
                    "storeFile": "C:/Users/vfuchong/.ohos/vfc.p12"
                }
            }
        ],
        "products": [
            {
                "name": "default",
                "signingConfig": "default",
                "compatibleSdkVersion": "5.0.0(12)",
                "runtimeOS": "HarmonyOS",
                "buildOption": {
                    "arkOptions": {
                        "buildProfileFields": {
                            "BASE_URL": 'https://vfcpay.com/'
                        }
                    },
                    "strictMode": {
                        "caseSensitiveCheck": true,
                        "useNormalizedOHMUrl": true
                    }
                }
            },
            {
                "name": "prod",
                "signingConfig": "default",
                "compatibleSdkVersion": "5.0.0(12)",
                "runtimeOS": "HarmonyOS",
                "buildOption": {
                    "arkOptions": {
                        "buildProfileFields": {
                            "BASE_URL": 'https://hce.vfuchong.cn/'
                        }
                    },
                    "strictMode": {
                        "caseSensitiveCheck": true,
                        "useNormalizedOHMUrl": true
                    }
                }
            }
        ],
        "buildModeSet": [
            {
                "name": "debug",
            },
            {
                "name": "release"
            }
        ]
    },
    "modules": [
        {
            "name": "entry",
            "srcPath": "./entry",
            "targets": [
                {
                    "name": "default",
                    "applyToProducts": [
                        "default"
                    ]
                },
                {
                    "name": "prod",
                    "applyToProducts": [
                        "prod"
                    ]
                }
            ]
        },
        {
            "name": "library",
            "srcPath": "./library"
        }
    ]
}
复制代码

 

2、entry中 build-profiles.json5

复制代码
{
    "apiType": "stageMode",
    "buildOption": {
        "externalNativeOptions": {
            "abiFilters": ["arm64-v8a", "x86_64"]
        }
    },
    "buildOptionSet": [
        {
            "name": "release",
            "arkOptions": {
                "obfuscation": {
                    "ruleOptions": {
                        "enable": true,
                        "files": [
                            "./obfuscation-rules.txt"
                        ]
                    }
                }
            }
        },
    ],
    "targets": [
        {
            "name": "default"
        },
        {
            "name": "prod",
        }
    ]
}
复制代码

 

  3 、生成文件

1
hvigorw GenerateBuildProfile

  

  https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-hvigor-get-build-profile-para-guide-V5

 

4、代码示例

复制代码
import Config from '../../util/Config';
import { IndexComponent } from './IndexComponent';  // 确保路径正确
import { MyComponent } from './MyComponent';  // 确保路径正确
import BuildProfile from 'BuildProfile'
@Builder
export function HomeBuilder() {
    Home()
}

PersistentStorage.persistProp("user_id", undefined)

@Entry
@Component
struct Home {
    @State selectedIndex: number = 0;
    pathStack: NavPathStack = new NavPathStack();
    aboutToAppear(): void {
        console.log('1111111')
        console.log(BuildProfile.NEWS_DETAIL)
        console.log('2222222222')
    }
    build() {
        Navigation(this.pathStack) {
            Tabs({ barPosition: BarPosition.End ,index: this.selectedIndex}){
                TabContent() {
                    IndexComponent({pathStack:this.pathStack});
                }.tabBar(
                    new BottomTabBarStyle(this.selectedIndex === 0 ? $rawfile('index.png') : $rawfile('index2.png'), '首页')
                        .labelStyle({
                            selectedColor: this.selectedIndex === 0 ? '#58b8fe':'#a4a4a4',
                            unselectedColor: '#a4a4a4'
                        })
                )
                TabContent(){
                    MyComponent({pathStack:this.pathStack});
                }.tabBar(
                    new BottomTabBarStyle(this.selectedIndex === 1 ? $rawfile('my.png') : $rawfile('my2.png'), '我的')
                        .labelStyle({
                            selectedColor: this.selectedIndex === 1 ? '#58b8fe':'#a4a4a4',
                            unselectedColor: '#a4a4a4'
                        })
                )

            }
            .onChange((index: number) => {
                console.log('index:',index)
                this.selectedIndex   = index
            })
        }
        .titleMode(NavigationTitleMode.Mini).hideTitleBar(true)


    }
}
复制代码

 

  

posted on   杨新春  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
· 零经验选手,Compose 一天开发一款小游戏!
历史上的今天:
2021-11-01 phpstorm 实现本地与服务器代码同步
点击右上角即可分享
微信分享提示