1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-31 21:33:12 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

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
This commit is contained in:
波仔糕
2025-02-14 17:55:09 +08:00
committed by GitHub
parent b04247b486
commit 2a96684de7
25 changed files with 145 additions and 121 deletions

View File

@@ -1,25 +1,11 @@
## 运行harmony_use_pushy项目步骤 ## 运行harmony_use_pushy项目步骤
### 1.将项目克隆到本地后在项目根目录创建libs文件夹 ### 1. 在项目根目录执行下面命令安装第三方依赖
### 2.然后将[`rnoh`](https://github.com/bozaigao/rnoh)克隆到libs文件夹中。
说明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)
### 3.进入rnoh项目执行下面命令对rnoh项目依赖的C++库进行初始化;
```
git submodule update --init --recursive
```
### 4. 确保在react-native-update根目录已经执行过yarn submodule命令。
说明这个命令会在harmony/src/main/cpp目录生成HDiffPatch和lzma的C++模块依赖。
### 5. 在项目根目录执行下面命令安装第三方依赖。
``` ```
yarn install yarn install
``` ```
### 6. 在项目根目录执行下面命令生成bundle包文件。 ### 2. 在项目根目录执行下面命令生成bundle包文件。
``` ```
yarn build yarn build
``` ```
@@ -27,8 +13,8 @@ yarn build
**注意⚠️**在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js不要随意修改包名因为diff是匹配该包名进行生成的。 **注意⚠️**在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js不要随意修改包名因为diff是匹配该包名进行生成的。
### 7. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目 ### 3. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目
![image](./sync.png) ![image](./sync.png)
### 8 运行效果图 ### 4 运行效果图
![image](./demo.png) ![image](./demo.png)

View File

@@ -37,10 +37,6 @@
} }
] ]
}, },
{
name: 'rnoh',
srcPath: '../libs/rnoh',
},
{ {
name: 'pushy', name: 'pushy',
srcPath: '../node_modules/react-native-update/harmony', srcPath: '../node_modules/react-native-update/harmony',

View File

@@ -5,24 +5,25 @@
"lockfileVersion": 3, "lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": { "specifiers": {
"pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony", "@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
"rnoh@../../libs/rnoh": "rnoh@../../libs/rnoh" "pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony"
}, },
"packages": { "packages": {
"@rnoh/react-native-openharmony@0.72.38": {
"name": "@rnoh/react-native-openharmony",
"version": "0.72.38",
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
"registryType": "ohpm"
},
"pushy@../../node_modules/react-native-update/harmony": { "pushy@../../node_modules/react-native-update/harmony": {
"name": "pushy", "name": "pushy",
"version": "3.1.0-0.0.7", "version": "3.1.0-0.0.7",
"resolved": "../../node_modules/react-native-update/harmony", "resolved": "../../node_modules/react-native-update/harmony",
"registryType": "local", "registryType": "local",
"dependencies": { "dependencies": {
"rnoh": "file:../../../libs/rnoh" "@rnoh/react-native-openharmony": "^0.72.38"
} }
},
"rnoh@../../libs/rnoh": {
"name": "rnoh",
"version": "0.72.12",
"resolved": "../../libs/rnoh",
"registryType": "local"
} }
} }
} }

View File

@@ -6,7 +6,7 @@
"author": "", "author": "",
"license": "", "license": "",
"dependencies": { "dependencies": {
"rnoh": "file:../../libs/rnoh", "@rnoh/react-native-openharmony": "0.72.38",
"pushy": "file:../../node_modules/react-native-update/harmony" "pushy": "file:../../node_modules/react-native-update/harmony"
} }
} }

View File

@@ -2,12 +2,23 @@ cmake_minimum_required(VERSION 3.16)
project(rnapp) project(rnapp)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../libs/rnoh/src/main/cpp") set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy) set(LOG_VERBOSITY_LEVEL 1)
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
add_compile_definitions(WITH_HITRACE_SYSTRACE)
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
add_subdirectory("${RNOH_CPP_DIR}" ./rn) add_subdirectory("${RNOH_CPP_DIR}" ./rn)
file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1
add_library(rnoh_app SHARED add_library(rnoh_app SHARED
${GENERATED_CPP_FILES}
"./PackageProvider.cpp" "./PackageProvider.cpp"
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
) )

View File

@@ -1,4 +1,4 @@
import type {RNPackageContext, RNPackage} from 'rnoh/ts'; import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
import {PushyPackage} from 'pushy/ts'; import {PushyPackage} from 'pushy/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] { export function createRNPackages(ctx: RNPackageContext): RNPackage[] {

View File

@@ -1,4 +1,4 @@
import {RNAbility} from 'rnoh/ts'; import {RNAbility} from '@rnoh/react-native-openharmony';
export default class EntryAbility extends RNAbility { export default class EntryAbility extends RNAbility {
getPagePath() { getPagePath() {

View File

@@ -1,26 +1,32 @@
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider'; import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh'; import { ComponentBuilderContext, RNOHCoreContext,RNAbility } from '@rnoh/react-native-openharmony';
import { import {
RNApp, RNApp,
RNAbility,
AnyJSBundleProvider, AnyJSBundleProvider,
ResourceJSBundleProvider, ResourceJSBundleProvider,
TraceJSBundleProviderDecorator, TraceJSBundleProviderDecorator,
} from 'rnoh' } from '@rnoh/react-native-openharmony'
import { createRNPackages } from '../RNPackagesFactory' import { createRNPackages } from '../RNPackagesFactory'
import preferences from '@ohos.data.preferences';
const arkTsComponentNames: Array<string> = [];
@Builder @Builder
export function CustomComponentBuilder(ctx: ComponentBuilderContext) { export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
// There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
Stack() {
}
.position({ x: 0, y: 0 })
} }
const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
@Entry @Entry
@Component @Component
struct Index { struct Index {
@StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
@State shouldShow: boolean = false @State shouldShow: boolean = false
@State message: string = 'Hello World';
aboutToAppear(): void { aboutToAppear(): void {
this.shouldShow = true this.shouldShow = true
@@ -30,28 +36,37 @@ struct Index {
// NOTE: this is required since `Ability`'s `onBackPressed` function always // NOTE: this is required since `Ability`'s `onBackPressed` function always
// terminates or puts the app in the background, but we want Ark to ignore it completely // terminates or puts the app in the background, but we want Ark to ignore it completely
// when handled by RN // when handled by RN
return this.rnAbility?.onBackPress(); this.rnohCoreContext!.dispatchBackPress()
// this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
return true
} }
build() { build() {
Column() { Column() {
if (this.rnAbility && this.shouldShow) { if (this.rnohCoreContext && this.shouldShow) {
RNApp({ RNApp({
rnInstanceConfig: { createRNPackages }, rnInstanceConfig: {
createRNPackages,
enableNDKTextMeasuring: true,
enableBackgroundExecutor: false,
enableCAPIArchitecture: true,
arkTsComponentNames: arkTsComponentNames,
},
initialProps: { "foo": "bar" } as Record<string, string>, initialProps: { "foo": "bar" } as Record<string, string>,
appKey: "harmony_use_pushy", appKey: "harmony_use_pushy",
buildCustomComponent: CustomComponentBuilder, wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
onSetUp: (rnInstance) => { onSetUp: (rnInstance) => {
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP") rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
}, },
jsBundleProvider: new TraceJSBundleProviderDecorator( jsBundleProvider: new TraceJSBundleProviderDecorator(
new AnyJSBundleProvider([ new AnyJSBundleProvider([
// MetroJSBundleProvider.fromServerIp('127.0.0.1'), // MetroJSBundleProvider.fromServerIp('127.0.0.1'),
// new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'hermes_bundle.hbc'), // new ResourceJSBundleProvider(rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
new FileJSBundleProvider(this.rnAbility.context), new FileJSBundleProvider(this.rnohCoreContext.uiAbilityContext),
new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'bundle.harmony.js') new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
]), ]),
this.rnAbility.getLogger()), this.rnohCoreContext.logger),
}) })
} }
} }

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
{
"pushy_build_time": "2025-02-14T09:43:25.648Z",
"versionName": "1.0.0"
}

View File

@@ -0,0 +1,14 @@
{
"ios": {
"appId": 24794,
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
},
"android": {
"appId": 27509,
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
},
"harmony": {
"appId": 29140,
"appKey": "JLklGflGIRbY-cMebjQwm1J1"
}
}

View File

@@ -13,5 +13,8 @@
"suppressImplicitAnyIndexErrors": true, "suppressImplicitAnyIndexErrors": true,
"strict": false "strict": false
} }
},
"overrides": {
"@rnoh/react-native-openharmony": "0.72.38"
} }
} }

View File

@@ -8,7 +8,7 @@
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY" "appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
}, },
"harmony": { "harmony": {
"appId": 29040, "appId": 29140,
"appKey": "gdzeAqAFE5Jew15c5Df8EKU9" "appKey": "JLklGflGIRbY-cMebjQwm1J1"
} }
} }

View File

@@ -6003,7 +6003,7 @@ react-is@^17.0.1:
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
"react-native-update@file:../..": "react-native-update@file:../..":
version "10.15.1" version "10.19.6"
dependencies: dependencies:
nanoid "^3.3.3" nanoid "^3.3.3"
react-native-url-polyfill "^2.0.0" react-native-url-polyfill "^2.0.0"

0
harmony/README.md Normal file
View File

View File

@@ -5,14 +5,15 @@
"lockfileVersion": 3, "lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": { "specifiers": {
"rnoh@../../../libs/rnoh": "rnoh@../../../libs/rnoh" "@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38"
}, },
"packages": { "packages": {
"rnoh@../../../libs/rnoh": { "@rnoh/react-native-openharmony@0.72.38": {
"name": "rnoh", "name": "@rnoh/react-native-openharmony",
"version": "0.72.12", "version": "0.72.38",
"resolved": "../../../libs/rnoh", "integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
"registryType": "local" "resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
"registryType": "ohpm"
} }
} }
} }

View File

@@ -7,6 +7,6 @@
"main": "index.ets", "main": "index.ets",
"version": "3.1.0-0.0.7", "version": "3.1.0-0.0.7",
"dependencies": { "dependencies": {
"rnoh": "file:../../../libs/rnoh" "@rnoh/react-native-openharmony":"^0.72.38"
} }
} }

View File

@@ -0,0 +1 @@
../../../../../harmony/oh_modules/.ohpm/@rnoh+react-native-openharmony@0.72.38/oh_modules/@rnoh/react-native-openharmony

View File

@@ -1,4 +1,4 @@
import { HotReloadConfig, JSBundleProvider, JSBundleProviderError, JSPackagerClientConfig } from 'rnoh'; import { HotReloadConfig, JSBundleProvider, JSBundleProviderError, JSPackagerClientConfig } from '@rnoh/react-native-openharmony';
import fileIo from '@ohos.file.fs'; import fileIo from '@ohos.file.fs';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { UpdateContext } from './UpdateContext'; import { UpdateContext } from './UpdateContext';
@@ -40,20 +40,15 @@ export class FileJSBundleProvider extends JSBundleProvider {
} }
throw new Error('Update bundle not found'); throw new Error('Update bundle not found');
} catch (error) { } catch (error) {
throw new JSBundleProviderError(`Couldn't load JSBundle from ${this.filePath}`, error) throw new JSBundleProviderError({
whatHappened: `Couldn't load JSBundle from ${this.filePath}`,
extraData: error,
howCanItBeFixed: [`Check if a bundle exists at "${this.filePath}" on your device.`]
})
} }
} }
getAppKeys(): string[] { getAppKeys(): string[] {
return []; return [];
} }
getHotReloadConfig(): HotReloadConfig | null {
return null;
}
getJSPackagerClientConfig(): JSPackagerClientConfig | null {
return null;
}
} }

View File

@@ -1,5 +1,5 @@
import { RNPackage, TurboModulesFactory } from 'rnoh/ts'; import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
import type { TurboModule, TurboModuleContext } from 'rnoh/ts'; import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
import { PushyTurboModule } from './PushyTurboModule'; import { PushyTurboModule } from './PushyTurboModule';
class PushyTurboModulesFactory extends TurboModulesFactory { class PushyTurboModulesFactory extends TurboModulesFactory {

View File

@@ -1,4 +1,4 @@
import { TurboModule, TurboModuleContext } from 'rnoh/ts'; import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import dataPreferences from '@ohos.data.preferences'; import dataPreferences from '@ohos.data.preferences';
import { bundleManager } from '@kit.AbilityKit'; import { bundleManager } from '@kit.AbilityKit';

View File

@@ -26,15 +26,15 @@ export class UpdateContext {
this.initPreferences(); this.initPreferences();
} }
private async initPreferences() { private initPreferences() {
try { try {
this.preferences = await preferences.getPreferences(this.context, 'update'); this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
const packageVersion = await this.getPackageVersion(); const packageVersion = this.getPackageVersion();
const storedVersion = await this.preferences.get('packageVersion', ''); const storedVersion = this.preferences.getSync('packageVersion', '');
if (packageVersion !== storedVersion) { if (packageVersion !== storedVersion) {
await this.preferences.clear(); this.preferences.clear();
await this.preferences.put('packageVersion', packageVersion); this.preferences.putSync('packageVersion', packageVersion);
await this.preferences.flush(); this.preferences.flush();
this.cleanUp(); this.cleanUp();
} }
} catch (e) { } catch (e) {
@@ -42,33 +42,33 @@ export class UpdateContext {
} }
} }
public async setKv(key: string, value: string): Promise<void> { public setKv(key: string, value: string): void {
await this.preferences.put(key, value); this.preferences.putSync(key, value);
await this.preferences.flush(); this.preferences.flush();
} }
public async getKv(key: string): Promise<string> { public getKv(key: string): string {
return await this.preferences.get(key, '') as string; return this.preferences.getSync(key, '') as string;
} }
public async isFirstTime(): Promise<boolean> { public isFirstTime(): boolean {
return await this.preferences.get('firstTime', false) as boolean; return this.preferences.getSync('firstTime', false) as boolean;
} }
public async rolledBackVersion(): Promise<string> { public rolledBackVersion(): string {
return await this.preferences.get('rolledBackVersion', '') as string; return this.preferences.getSync('rolledBackVersion', '') as string;
} }
public async markSuccess(): Promise<void> { public markSuccess(): void {
await this.preferences.put('firstTimeOk', true); this.preferences.putSync('firstTimeOk', true);
const lastVersion = await this.preferences.get('lastVersion', '') as string; const lastVersion = this.preferences.getSync('lastVersion', '') as string;
const curVersion = await this.preferences.get('currentVersion', '') as string; const curVersion = this.preferences.getSync('currentVersion', '') as string;
if (lastVersion && lastVersion !== curVersion) { if (lastVersion && lastVersion !== curVersion) {
await this.preferences.delete('lastVersion'); this.preferences.deleteSync('lastVersion');
await this.preferences.delete(`hash_${lastVersion}`); this.preferences.deleteSync(`hash_${lastVersion}`);
} }
await this.preferences.flush(); this.preferences.flush();
this.cleanUp(); this.cleanUp();
} }
@@ -143,23 +143,23 @@ export class UpdateContext {
} }
} }
public async switchVersion(hash: string): Promise<void> { public switchVersion(hash: string): void {
try { try {
const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`; const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`;
if (!fileIo.accessSync(bundlePath)) { if (!fileIo.accessSync(bundlePath)) {
throw new Error(`Bundle version ${hash} not found.`); throw new Error(`Bundle version ${hash} not found.`);
} }
const lastVersion = await this.getKv('currentVersion'); const lastVersion = this.getKv('currentVersion');
await this.setKv('currentVersion', hash); this.setKv('currentVersion', hash);
if (lastVersion && lastVersion !== hash) { if (lastVersion && lastVersion !== hash) {
await this.setKv('lastVersion', lastVersion); this.setKv('lastVersion', lastVersion);
} }
await this.setKv('firstTime', 'true'); this.setKv('firstTime', 'true');
await this.setKv('firstTimeOk', 'false'); this.setKv('firstTimeOk', 'false');
await this.setKv('rolledBackVersion', null); this.setKv('rolledBackVersion', null);
} catch (e) { } catch (e) {
console.error('Failed to switch version:', e); console.error('Failed to switch version:', e);
} }
@@ -176,7 +176,7 @@ export class UpdateContext {
return defaultAssetsUrl; return defaultAssetsUrl;
} }
if (!this.isFirstTime()) { if (!this.isFirstTime()) {
if (!this.preferences.get('firstTimeOk', true)) { if (!this.preferences.getSync('firstTimeOk', true)) {
return this.rollBack(); return this.rollBack();
} }
} }

View File

@@ -1,8 +1,5 @@
import { TurboModuleContext } from 'rnoh/ts';
import dataPreferences from '@ohos.data.preferences';
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
import { UpdateContext } from './UpdateContext'; import { UpdateContext } from './UpdateContext';
import { DownloadTaskParams } from './DownloadTaskParams'; import { DownloadTaskParams } from './DownloadTaskParams';
import logger from './Logger'; import logger from './Logger';