Skip to content

feat(code_assets): add ohos OS support for OpenHarmony/HarmonyOS NEXT#3409

Open
jianguo888 wants to merge 1 commit into
dart-lang:mainfrom
jianguo888:main
Open

feat(code_assets): add ohos OS support for OpenHarmony/HarmonyOS NEXT#3409
jianguo888 wants to merge 1 commit into
dart-lang:mainfrom
jianguo888:main

Conversation

@jianguo888

Copy link
Copy Markdown
## Summary                                                                                                                                                                                                        
                                                                                                                                                                                                                  
Add `ohos` as a recognized operating system in the `OS` and `OSSyntax` enums                                                                                                                                      
within the `code_assets` package, enabling native assets hooks to work on the                                                                                                                                     
OpenHarmony / HarmonyOS NEXT platform.                                                                                                                                                                            
                                                                                                                                                                                                                  
## Background                                                                                                                                                                                                     
                                                                                                                                                                                                                  
The `code_assets` package currently only recognizes six OS types: `android`,                                                                                                                                      
`fuchsia`, `ios`, `linux`, `macos`, and `windows`. When the Flutter OHOS                                                                                                                                          
toolchain (e.g. `flutter build hap` / `flutter run`) invokes native assets                                                                                                                                        
hooks with `target_os: "ohos"`, it crashes with:                                                                                                                                                                  

FormatException: The OS "ohos" is not known

This blocks any Flutter project targeting HarmonyOS NEXT from using packages                                                                                                                                      
that depend on native assets (e.g. `objective_c`).                                                                                                                                                                
                                                                                                                                                                                                                  
## Changes                                                                                                                                                                                                        
                                                                                                                                                                                                                  
### `lib/src/code_assets/os.dart`                                                                                                                                                                                 
- Add `static const OS ohos = OS._('ohos')`                                                                                                                                                                       
- Add `ohos` to the `OS.values` list                                                                                                                                                                              
                                                                                                                                                                                                                  
### `lib/src/code_assets/syntax.g.dart`                                                                                                                                                                           
- Add `static const ohos = OSSyntax._('ohos')`                                                                                                                                                                    
- Add `ohos` to the `OSSyntax.values` list                                                                                                                                                                        
                                                                                                                                                                                                                  
## Testing                                                                                                                                                                                                        
                                                                                                                                                                                                                  
After applying the change, `flutter run` on a HarmonyOS NEXT device                                                                                                                                               
(OpenHarmony 6.1.0.115, API 23) completed successfully:                                                                                                                                                           
- Native assets hooks no longer throw OS format errors                                                                                                                                                            
- `flutter build hap` succeeds in building the `.hap` artifact                                                                                                                                                    
                                                                                                                                                                                                                  
## Notes                                                                                                                                                                                                          
                                                                                                                                                                                                                  
`syntax.g.dart` is a generated file. The permanent fix should be to update                                                                                                                                        
the code generation tool (`pkgs/hooks/tool/generate_syntax.dart`) to include                                                                                                                                      
`ohos` in the schema, then re-run generation. This patch applies the change                                                                                                                                       
directly to the generated file as a temporary measure.                        

@google-cla

google-cla Bot commented Jun 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Add `ohos` constant to both `OS` and `OSSyntax` enums so that native
assets hooks (e.g. objective_c) can recognize the OHOS platform
instead of throwing "The OS 'ohos' is not known".

Co-Authored-By: 坚果 <xujianguo20314@gmail.com>
Signed-off-by: 坚果 <xujianguo20314@gmail.com>
@dcharkes

dcharkes commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Hi @jianguo888, thanks for the report!

Our goal is to make this API extensible, and it currently isn't extensible for multiple reasons:

  1. Errors on unknown OSes
  2. equals not being overridden

Our goal would be that you'd be able to extend this package in the following way:

extension OhosOS on OS {
  static final ohos = OS.fromString('ohos');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants