Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): preserve new-arch classnames used in backwards-compat logic #1149

Merged
merged 2 commits into from
Nov 25, 2024
Merged
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
4 changes: 2 additions & 2 deletions docs-react-native/react-native/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ yarn add @notifee/react-native

### 2a. Android API versions

The values of the compileSdkVersion & targetSdkVersion might need to be changed. compileSdkVersion needs to be at least 33. In addition, if your app is going to request permission on Android 13 via requestPermission, targetSdkVersion needs to be at least 33, as well. These setting are in the file `/android/build.gradle`.
The values of the compileSdkVersion & targetSdkVersion might need to be changed. compileSdkVersion needs to be at least 34. In addition, if your app is going to request permission on Android 13 via requestPermission, targetSdkVersion needs to be at least 33, as well. These setting are in the file `/android/build.gradle`.

```gradle
buildscript {
ext {
compileSdkVersion = 33 // at least 33
compileSdkVersion = 34 // at least 34
targetSdkVersion = 33 // If requesting permission on Android 13 via requestPermission, at least 33
...
}
Expand Down
10 changes: 9 additions & 1 deletion packages/react-native/android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
-keep class io.invertase.notifee.NotifeeEventSubscriber
-keep class io.invertase.notifee.NotifeeInitProvider
-keepnames class com.facebook.react.ReactActivity
-keepnames class io.invertase.notifee.NotifeePackage
-keepnames class io.invertase.notifee.NotifeeApiModule

# We depend on certain classes to exist under their names for dynamic
# class-loading to work. We use this to handle new arch / old arch backwards
# compatibility despite the class names moving around
-keep class com.facebook.react.defaults.DefaultNewArchitectureEntryPoint { *; }
-keep class com.facebook.react.ReactApplication { *; }
-keep class com.facebook.react.ReactHost { *; }
-keep class * extends com.facebook.react.ReactHost { *; }
-keepnames class com.facebook.react.ReactActivity

# Preserve all annotations.
-keepattributes *Annotation*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,30 @@ static void promiseResolver(Promise promise, Exception e) {
Method bridgelessEnabled = entryPoint.getMethod("getBridgelessEnabled");
Object result = bridgelessEnabled.invoke(null);
if (result == Boolean.TRUE) {
Log.d("getReactContext", "We are in bridgeless new architecture mode");
Log.d("Notifee::getReactContext", "We are in bridgeless new architecture mode");
Object reactApplication = EventSubscriber.getContext();
Method getReactHost = reactApplication.getClass().getMethod("getReactHost");
Object reactHostInstance = getReactHost.invoke(reactApplication);
Method getCurrentReactContext =
reactHostInstance.getClass().getMethod("getCurrentReactContext");
return (ReactContext) getCurrentReactContext.invoke(reactHostInstance);
} else {
Log.d("getReactContext", "we are NOT in bridgeless new architecture mode");
Log.d("Notifee::getReactContext", "we are NOT in bridgeless new architecture mode");
}
} catch (Exception e) {
Log.d("getReactContext", "New Architecture class load failed. Using fallback.");
Log.d("Notifee::getReactContext", "New Architecture class load failed. Using fallback.");
}

Log.d("getReactContext", "Determining ReactContext using fallback method");
Log.d("Notifee::getReactContext", "Determining ReactContext using fallback method");
ReactNativeHost reactNativeHost =
((ReactApplication) EventSubscriber.getContext()).getReactNativeHost();
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
return reactInstanceManager.getCurrentReactContext();
} catch (Exception e) {
Log.w("getReactContext", "ReactHost unexpectedly null", e);
Log.w("Notifee::getReactContext", "ReactHost unexpectedly null", e);
}

Log.w("getReactContext", "Unable to determine ReactContext");
Log.w("Notifee::getReactContext", "Unable to determine ReactContext");
return null;
}

Expand Down
Loading