fauno fauno - 24 days ago 12
Android Question

react-native-system-notification NativeModule is undefined on apk release

I'm working on this app project where I need to schedule notifications based on a list of predefined texts. Everything works fine on my dev environment, but when I build the APK release, they won't work. Debugging further I found out the notifications are a NativeModule and it becomes

undefined
on the release.

This returns the module attributes on
react-native run-android
but
undefined
in the release:

console.log(React.NativeModules.NotificationModule);


This is the actual error that led me to it:

Notification
.create({ attrs })
.then((n) => console.log('Notification', n)
.catch((err) => console.log(err);


Prints:

{ [TypeError: undefined is not an object (evaluating 'd.rGetApplicationName')] line: 670 column: 2663, sourceURL: 'index.android.bundle' }


I'm using react-native-system-notification with what I understand is an unrelated modification that removes the GCM requirement.

There's this issue but the project seems inactive since August and the issue is from April.

So, where else should I look for to solve this?

Answer

I've disabled proguard from the release and the notifications started to work! No idea how to prevent proguard from messing with the package, but it was only saving 1Mb so I'm happy with this solution.

def enableProguardInReleaseBuilds = false

in android/app/build.gradle