Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-native-executorch/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ android {
defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
consumerProguardFiles "consumer-proguard-rules.pro"
externalNativeBuild {
cmake {
abiFilters (*reactNativeArchitectures())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Ported from ExecuTorch's official Android consumer rules:
# https://github.com/pytorch/executorch/blob/904c667007aed15e9a3bb8278aa271b479450c85/extension/android/executorch_android/consumer-proguard-rules.pro

# ExecuTorch Android AAR — Consumer ProGuard/R8 Rules
#
# These rules are automatically applied to any app that depends on the
# ExecuTorch AAR. They prevent R8/ProGuard from stripping classes and
# methods that are called from native (JNI) code.

# Keep ExecuTorch classes and members annotated with @DoNotStrip.
# Scoped to org.pytorch.executorch to avoid affecting unrelated libraries.
-keep @com.facebook.jni.annotations.DoNotStrip class org.pytorch.executorch.** { *; }
-keepclassmembers class org.pytorch.executorch.** {
@com.facebook.jni.annotations.DoNotStrip *;
}

# Keep all native methods across ExecuTorch packages.
# Use -keepclasseswithmembers (not -keepclasseswithmembernames) to prevent
# both shrinking and obfuscation of JNI entry points.
-keepclasseswithmembers class org.pytorch.executorch.** {
native <methods>;
}

# Keep HybridData fields (accessed by fbjni via reflection).
-keepclassmembers class org.pytorch.executorch.** {
com.facebook.jni.HybridData *;
}

# Keep ExecutorchRuntimeException and its factory/subclasses.
# These are instantiated from JNI via jni_helper.cpp.
-keep class org.pytorch.executorch.ExecutorchRuntimeException { *; }
-keep class org.pytorch.executorch.ExecutorchRuntimeException$* { *; }

# Keep EValue (fields and type codes accessed from native code).
-keep class org.pytorch.executorch.EValue { *; }

# Keep Tensor and its inner classes. The Tensor class has methods and fields
# accessed from JNI (dtypeJniCode, shape, getRawDataBuffer, nativeNewTensor).
-keep class org.pytorch.executorch.Tensor { *; }
-keep class org.pytorch.executorch.Tensor$* { *; }

# Keep LlmCallback interface methods (invoked from native code).
-keep interface org.pytorch.executorch.extension.llm.LlmCallback { *; }

# Keep AsrCallback interface methods (invoked from native code).
-keep interface org.pytorch.executorch.extension.asr.AsrCallback { *; }

# --- react-native-executorch rules (not from upstream) ---

# RNE's own JNI entry point, resolved by literal descriptor from C++.
-keep class com.swmansion.rnexecutorch.ETInstaller { *; }
2 changes: 1 addition & 1 deletion packages/react-native-executorch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-executorch",
"version": "0.9.2",
"version": "0.9.3",
"description": "An easy way to run AI models in React Native with ExecuTorch",
"source": "./src/index.ts",
"main": "./lib/module/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ export class ResourceFetcher {
* @remarks
* **REQUIRED**: Used internally for reading configuration files (e.g., tokenizer configs).
*/
// Reference the class by name: `this` inside a static-field arrow gets
// rebound to module scope by Babel under RN's hermes transform profiles.
readAsString: async (path: string) => {
return this.getAdapter().readAsString(path);
return ResourceFetcher.getAdapter().readAsString(path);
},
};
}
Loading