1、工程级目录build-profile.json5
{ "app": { "signingConfigs": [ { "name": "default", "type": "HarmonyOS", "material": { "certpath": "C:\\Users\\vfuchong\\.ohos\\config\\default_vfc_3cOT87FxKQliO-iOgtBlrRDQvua7LTzvSuHyCzWbZaU=.cer", "storePassword": "0000001B33166971A2769CE29C2BE5C6C2D70A9B615171B9D2B9612A12C3B4DF47DE64BB503147E1A45C17", "keyAlias": "debugKey", "keyPassword": "0000001B04A41B8F99F4784AAA5ADC07B4BF918048057FD20CDFD5DF6DF8875801FEA362C609ED58D83222", "profile": "C:\\Users\\vfuchong\\.ohos\\config\\default_vfc_3cOT87FxKQliO-iOgtBlrRDQvua7LTzvSuHyCzWbZaU=.p7b", "signAlg": "SHA256withECDSA", "storeFile": "C:\\Users\\vfuchong\\.ohos\\config\\default_vfc_3cOT87FxKQliO-iOgtBlrRDQvua7LTzvSuHyCzWbZaU=.p12" } } ], "products": [ { "name": "default", "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", "buildOption": { "arkOptions": { "buildProfileFields": { "NEWS_DETAIL": 'https://vfcpay.com/' } } } }, { "name": "prod", "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", "buildOption": { "arkOptions": { "buildProfileFields": { "NEWS_DETAIL": 'https://hce.vfuchong.cn/' } } } } ], "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 、生成文件
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) } }
标签:index,console,name,鸿蒙,default,pathStack,配置,环境,selectedIndex From: https://www.cnblogs.com/xkcp008/p/18520464