Skip to content

Commit 2a96684

Browse files
authored
update RNOH SDK dependence from local to remote (#473)
* fix harmony more than 2M issue * fix mtpush-react-native conflics * update harmony remote dependency flow * udpate * udpate * udpate * udpate * udpate * update * uddate * udpapte
1 parent b04247b commit 2a96684

25 files changed

+145
-121
lines changed

Example/harmony_use_pushy/README.md

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
## 运行harmony_use_pushy项目步骤
22

3-
### 1.将项目克隆到本地后在项目根目录创建libs文件夹。
4-
5-
### 2.然后将[`rnoh`](https://github.com/bozaigao/rnoh)克隆到libs文件夹中。
6-
7-
说明:rnoh项目基于react-native 0.72.5版本适配,如果使用最新的RN版本可能会报错,项目适配RN新版本请关注[`gitee仓库`](https://gitee.com/openharmony-sig/ohos_react_native/tree/0.72.5-ohos-5.0-release/tester/harmony/react_native_openharmony/src/main)
8-
9-
### 3.进入rnoh项目执行下面命令对rnoh项目依赖的C++库进行初始化;
10-
```
11-
git submodule update --init --recursive
12-
```
13-
14-
### 4. 确保在react-native-update根目录已经执行过yarn submodule命令。
15-
说明:这个命令会在harmony/src/main/cpp目录生成HDiffPatch和lzma的C++模块依赖。
16-
17-
### 5. 在项目根目录执行下面命令安装第三方依赖。
3+
### 1. 在项目根目录执行下面命令安装第三方依赖。
184
```
195
yarn install
206
```
217

22-
### 6. 在项目根目录执行下面命令生成bundle包文件。
8+
### 2. 在项目根目录执行下面命令生成bundle包文件。
239
```
2410
yarn build
2511
```
2612
说明:这个命令会在harmony/entry/src/main/resources/rawfile目录生成Hbundle.harmony.js和assets文件,同时会基于该内容在.pushy/output目录生成ppk包。
2713

2814
**注意⚠️**:在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js,不要随意修改包名,因为diff是匹配该包名进行生成的。
2915

30-
### 7. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目
16+
### 3. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目
3117
![image](./sync.png)
3218

33-
### 8 运行效果图
19+
### 4 运行效果图
3420
![image](./demo.png)

Example/harmony_use_pushy/harmony/build-profile.json5

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
}
3838
]
3939
},
40-
{
41-
name: 'rnoh',
42-
srcPath: '../libs/rnoh',
43-
},
4440
{
4541
name: 'pushy',
4642
srcPath: '../node_modules/react-native-update/harmony',

Example/harmony_use_pushy/harmony/entry/hvigorfile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ export function generatePushyBuildTime(str?: string) {
4141
export default {
4242
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
4343
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
44-
}
44+
}

Example/harmony_use_pushy/harmony/entry/oh-package-lock.json5

+10-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/harmony_use_pushy/harmony/entry/oh-package.json5

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "",
77
"license": "",
88
"dependencies": {
9-
"rnoh": "file:../../libs/rnoh",
9+
"@rnoh/react-native-openharmony": "0.72.38",
1010
"pushy": "file:../../node_modules/react-native-update/harmony"
1111
}
1212
}

Example/harmony_use_pushy/harmony/entry/src/main/cpp/CMakeLists.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ cmake_minimum_required(VERSION 3.16)
22
project(rnapp)
33
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
44
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
5-
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../libs/rnoh/src/main/cpp")
5+
set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
6+
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
67
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
7-
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
8+
set(LOG_VERBOSITY_LEVEL 1)
9+
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
10+
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
11+
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
12+
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
13+
add_compile_definitions(WITH_HITRACE_SYSTRACE)
814

15+
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
916
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
17+
18+
file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1
19+
1020
add_library(rnoh_app SHARED
21+
${GENERATED_CPP_FILES}
1122
"./PackageProvider.cpp"
1223
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
1324
)

Example/harmony_use_pushy/harmony/entry/src/main/ets/RNPackagesFactory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {RNPackageContext, RNPackage} from 'rnoh/ts';
1+
import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
22
import {PushyPackage} from 'pushy/ts';
33

44
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {

Example/harmony_use_pushy/harmony/entry/src/main/ets/entryability/EntryAbility.ets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {RNAbility} from 'rnoh/ts';
1+
import {RNAbility} from '@rnoh/react-native-openharmony';
22

33
export default class EntryAbility extends RNAbility {
44
getPagePath() {

Example/harmony_use_pushy/harmony/entry/src/main/ets/pages/Index.ets

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
2-
import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh';
2+
import { ComponentBuilderContext, RNOHCoreContext,RNAbility } from '@rnoh/react-native-openharmony';
33
import {
44
RNApp,
5-
RNAbility,
65
AnyJSBundleProvider,
76
ResourceJSBundleProvider,
87
TraceJSBundleProviderDecorator,
9-
} from 'rnoh'
8+
} from '@rnoh/react-native-openharmony'
109
import { createRNPackages } from '../RNPackagesFactory'
10+
import preferences from '@ohos.data.preferences';
1111

12-
@Builder
13-
export function CustomComponentBuilder(ctx: ComponentBuilderContext) {
12+
const arkTsComponentNames: Array<string> = [];
1413

14+
@Builder
15+
export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
16+
// There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
17+
Stack() {
18+
}
19+
.position({ x: 0, y: 0 })
1520
}
1621

1722

23+
const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
24+
1825
@Entry
1926
@Component
2027
struct Index {
21-
@StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined
28+
@StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
2229
@State shouldShow: boolean = false
23-
@State message: string = 'Hello World';
2430

2531
aboutToAppear(): void {
2632
this.shouldShow = true
@@ -30,28 +36,37 @@ struct Index {
3036
// NOTE: this is required since `Ability`'s `onBackPressed` function always
3137
// terminates or puts the app in the background, but we want Ark to ignore it completely
3238
// when handled by RN
33-
return this.rnAbility?.onBackPress();
39+
this.rnohCoreContext!.dispatchBackPress()
40+
41+
// this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
42+
return true
3443
}
3544

3645
build() {
3746
Column() {
38-
if (this.rnAbility && this.shouldShow) {
47+
if (this.rnohCoreContext && this.shouldShow) {
3948
RNApp({
40-
rnInstanceConfig: { createRNPackages },
49+
rnInstanceConfig: {
50+
createRNPackages,
51+
enableNDKTextMeasuring: true,
52+
enableBackgroundExecutor: false,
53+
enableCAPIArchitecture: true,
54+
arkTsComponentNames: arkTsComponentNames,
55+
},
4156
initialProps: { "foo": "bar" } as Record<string, string>,
4257
appKey: "harmony_use_pushy",
43-
buildCustomComponent: CustomComponentBuilder,
58+
wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
4459
onSetUp: (rnInstance) => {
4560
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
4661
},
4762
jsBundleProvider: new TraceJSBundleProviderDecorator(
4863
new AnyJSBundleProvider([
4964
// MetroJSBundleProvider.fromServerIp('127.0.0.1'),
50-
// new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'hermes_bundle.hbc'),
51-
new FileJSBundleProvider(this.rnAbility.context),
52-
new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'bundle.harmony.js')
65+
// new ResourceJSBundleProvider(rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
66+
new FileJSBundleProvider(this.rnohCoreContext.uiAbilityContext),
67+
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
5368
]),
54-
this.rnAbility.getLogger()),
69+
this.rnohCoreContext.logger),
5570
})
5671
}
5772
}

0 commit comments

Comments
 (0)