跳到主要内容

本地 SDK 版本自定义

⚠️ ⚠️ 高级配置 本节适用于需要使用特定版本 Rive 本地 SDK 的高级用户。在大多数情况下,您应该使用库自带的默认版本。只有在您有特定要求并理解潜在的兼容性影响时,才自定义这些版本。

重要: 如果您自定义了本地 SDK 版本,之后将 Rive React Native 升级到更新版本时,应重新检查您的自定义版本设置。您指定的自定义版本可能与更新的 Rive React Native 版本不兼容。请务必检查新版本中的默认版本并进行充分测试。

默认行为​

默认情况下,Rive React Native 使用其 package.json 中指定的本地 SDK 版本。例如,@rive-app/react-native 0.5.5 使用:

"runtimeVersions": {
"ios": "6.28.1",
"android": "11.12.1"
}

这些版本经过测试,已知与该版本的 Rive React Native 配合良好。请查看发行说明了解每个发行版使用的版本。

自定义版本​

您可以使用平台特定的配置文件覆盖这些默认版本。

参见可用的本地 Rive Android 和 iOS 版本。

某些功能需要最低本地 SDK 版本。例如,GPU Canvas 需要 Rive iOS 6.25.0 和 Rive Android 11.12.0 或更高版本。

iOS(普通 React Native)​

创建或编辑 ios/Podfile.properties.json:

{
"RiveRuntimeIOSVersion": "6.24.0"
}

然后运行:

cd ios && pod install

Android(普通 React Native)​

添加到 android/gradle.properties:

Rive_RiveRuntimeAndroidVersion=11.9.2

Expo 项目​

对于 Expo 项目,在 app.config.ts 中使用内联 config plugin:

import { ExpoConfig, ConfigContext } from "expo/config";
import {
withPodfileProperties,
withGradleProperties,
} from "@expo/config-plugins";

export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
plugins: [
(config) => {
config = withPodfileProperties(config, (config) => {
config.modResults["RiveRuntimeIOSVersion"] = "6.24.0";
return config;
});

config = withGradleProperties(config, (config) => {
config.modResults.push({
type: "property",
key: "Rive_RiveRuntimeAndroidVersion",
value: "11.9.2",
});
return config;
});

return config;
},
],
});

版本解析优先级​

库按以下顺序解析版本:

iOS:

  1. 运行 pod install 时的 RIVE_RUNTIME_IOS_VERSION 环境变量
  2. Podfile 中的 $RiveRuntimeIOSVersion 全局变量
  3. ios/Podfile.properties.json → RiveRuntimeIOSVersion
  4. package.json → runtimeVersions.ios(默认)

Android:

  1. 根项目 ext 块中的 RiveRuntimeAndroidVersion(android/build.gradle)
  2. android/gradle.properties → Rive_RiveRuntimeAndroidVersion
  3. package.json → runtimeVersions.android(默认)
看完还有疑问?进群交流下!
与众多 Rive 创作者、开发者一起交流探讨与答疑解惑。
加入交流群