Description
Bug
The Android application crashes immediately during React Native context creation/startup with a NoClassDefFoundError related to react-native-safe-area-context.
The crash occurs even though newArchEnabled=false.
Environment
React Native: 0.81.x
Platform: Android
Architecture: Old Architecture / Paper
newArchEnabled=false
Hermes: enabled
react-native-safe-area-context: 5.9.0
Package.json dependency: "react-native-safe-area-context": "^5.5.2"
Yarn: 1.22.22
Gradle: 8.14.3
Android Gradle Plugin: 9.2.1
Target SDK: 36
Crash
The application crashes during create_react_context:
FATAL EXCEPTION: create_react_context
java.lang.NoClassDefFoundError:
Failed resolution of:
Lcom/th3rdwave/safeareacontext/SafeAreaContextModule;
at com.th3rdwave.safeareacontext.SafeAreaContextPackage.getReactModuleInfoProvider(SafeAreaContextPackage.kt:22)
at com.facebook.react.BaseReactPackage.getNativeModuleIterator(BaseReactPackage.kt:54)
at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.kt:41)
at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1571)
at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1542)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1453)
Caused by:
java.lang.ClassNotFoundException:
com.th3rdwave.safeareacontext.SafeAreaContextModule
Caused by:
java.lang.NoClassDefFoundError:
Failed resolution of:
Lcom/th3rdwave/safeareacontext/NativeSafeAreaContextSpec;
Caused by:
java.lang.ClassNotFoundException:
Didn't find class
"com.th3rdwave.safeareacontext.NativeSafeAreaContextSpec"
Investigation
The project is configured with:
newArchEnabled=false
The react-native-safe-area-context Android source contains the Paper implementation:
android/src/paper/java/com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec.java
Initially, the Android source set was not including the Paper Java directory correctly.
The following source-set configuration was added:
sourceSets.main {
if (isNewArchitectureEnabled()) {
java.directories.add("${project.buildDir}/generated/source/codegen/java")
kotlin.directories.add("src/fabric/java")
} else {
java.directories.add("src/paper/java")
kotlin.directories.add("src/paper/java")
}
}
After rebuilding react-native-safe-area-context, the generated AAR was inspected and confirmed to contain:
com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec.class
com/th3rdwave/safeareacontext/SafeAreaContextModule.class
com/th3rdwave/safeareacontext/SafeAreaContextPackage.class
The rebuilt AAR therefore contains the missing class.
The final APK was also inspected using dexdump. The APK contains:
SafeAreaContextModule
SafeAreaContextPackage
and SafeAreaContextModule has:
Superclass:
Lcom/th3rdwave/safeareacontext/NativeSafeAreaContextSpec;
However, the installed APK previously showed that NativeSafeAreaContextSpec was not listed as a class descriptor, indicating a possible packaging/dex resolution issue.
Expected behavior
The application should start successfully when:
newArchEnabled=false
and react-native-safe-area-context should load its Paper implementation without crashing.
Actual behavior
The application crashes immediately during React Native context creation with:
java.lang.NoClassDefFoundError:
com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec
Steps to reproduce
Install the project dependencies.
Use react-native-safe-area-context 5.9.0.
Set:
newArchEnabled=false
Build the Android debug APK.
Install the APK on an Android device.
Launch the application.
The application crashes during React Native context creation.
Additional information
The issue appears to be related to how the Paper Java source/codegen class from react-native-safe-area-context is compiled and/or packaged into the final Android application.
The library AAR can contain NativeSafeAreaContextSpec.class, while the final APK may still fail to resolve the class at runtime.
Further investigation is required to determine whether this is caused by the React Native version, Android Gradle Plugin/Gradle combination, safe-area-context 5.9.0, or the Android source-set/codegen configuration
Steps to reproduce
Steps to reproduce
Install the project dependencies.
Use react-native-safe-area-context 5.9.0.
Set:
newArchEnabled=false
Build the Android debug APK.
Install the APK on an Android device.
Launch the application.
The application crashes during React Native context creation.
Snack or a link to a repository
.
Safe Area Context version
5.5.2
React Native version
0.81.4
Platforms
Android
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
Real device
Device model
iqoo z10 AND s24
Acknowledgements
Yes
Description
Bug
The Android application crashes immediately during React Native context creation/startup with a NoClassDefFoundError related to react-native-safe-area-context.
The crash occurs even though newArchEnabled=false.
Environment
React Native: 0.81.x
Platform: Android
Architecture: Old Architecture / Paper
newArchEnabled=false
Hermes: enabled
react-native-safe-area-context: 5.9.0
Package.json dependency: "react-native-safe-area-context": "^5.5.2"
Yarn: 1.22.22
Gradle: 8.14.3
Android Gradle Plugin: 9.2.1
Target SDK: 36
Crash
The application crashes during create_react_context:
FATAL EXCEPTION: create_react_context
java.lang.NoClassDefFoundError:
Failed resolution of:
Lcom/th3rdwave/safeareacontext/SafeAreaContextModule;
at com.th3rdwave.safeareacontext.SafeAreaContextPackage.getReactModuleInfoProvider(SafeAreaContextPackage.kt:22)
at com.facebook.react.BaseReactPackage.getNativeModuleIterator(BaseReactPackage.kt:54)
at com.facebook.react.NativeModuleRegistryBuilder.processPackage(NativeModuleRegistryBuilder.kt:41)
at com.facebook.react.ReactInstanceManager.processPackage(ReactInstanceManager.java:1571)
at com.facebook.react.ReactInstanceManager.processPackages(ReactInstanceManager.java:1542)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1453)
Caused by:
java.lang.ClassNotFoundException:
com.th3rdwave.safeareacontext.SafeAreaContextModule
Caused by:
java.lang.NoClassDefFoundError:
Failed resolution of:
Lcom/th3rdwave/safeareacontext/NativeSafeAreaContextSpec;
Caused by:
java.lang.ClassNotFoundException:
Didn't find class
"com.th3rdwave.safeareacontext.NativeSafeAreaContextSpec"
Investigation
The project is configured with:
newArchEnabled=false
The react-native-safe-area-context Android source contains the Paper implementation:
android/src/paper/java/com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec.java
Initially, the Android source set was not including the Paper Java directory correctly.
The following source-set configuration was added:
sourceSets.main {
if (isNewArchitectureEnabled()) {
java.directories.add("${project.buildDir}/generated/source/codegen/java")
kotlin.directories.add("src/fabric/java")
} else {
java.directories.add("src/paper/java")
kotlin.directories.add("src/paper/java")
}
}
After rebuilding react-native-safe-area-context, the generated AAR was inspected and confirmed to contain:
com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec.class
com/th3rdwave/safeareacontext/SafeAreaContextModule.class
com/th3rdwave/safeareacontext/SafeAreaContextPackage.class
The rebuilt AAR therefore contains the missing class.
The final APK was also inspected using dexdump. The APK contains:
SafeAreaContextModule
SafeAreaContextPackage
and SafeAreaContextModule has:
Superclass:
Lcom/th3rdwave/safeareacontext/NativeSafeAreaContextSpec;
However, the installed APK previously showed that NativeSafeAreaContextSpec was not listed as a class descriptor, indicating a possible packaging/dex resolution issue.
Expected behavior
The application should start successfully when:
newArchEnabled=false
and react-native-safe-area-context should load its Paper implementation without crashing.
Actual behavior
The application crashes immediately during React Native context creation with:
java.lang.NoClassDefFoundError:
com/th3rdwave/safeareacontext/NativeSafeAreaContextSpec
Steps to reproduce
Install the project dependencies.
Use react-native-safe-area-context 5.9.0.
Set:
newArchEnabled=false
Build the Android debug APK.
Install the APK on an Android device.
Launch the application.
The application crashes during React Native context creation.
Additional information
The issue appears to be related to how the Paper Java source/codegen class from react-native-safe-area-context is compiled and/or packaged into the final Android application.
The library AAR can contain NativeSafeAreaContextSpec.class, while the final APK may still fail to resolve the class at runtime.
Further investigation is required to determine whether this is caused by the React Native version, Android Gradle Plugin/Gradle combination, safe-area-context 5.9.0, or the Android source-set/codegen configuration
Steps to reproduce
Steps to reproduce
Install the project dependencies.
Use react-native-safe-area-context 5.9.0.
Set:
newArchEnabled=false
Build the Android debug APK.
Install the APK on an Android device.
Launch the application.
The application crashes during React Native context creation.
Snack or a link to a repository
.
Safe Area Context version
5.5.2
React Native version
0.81.4
Platforms
Android
Architecture
Paper (Old Architecture)
Build type
Debug mode
Device
Real device
Device model
iqoo z10 AND s24
Acknowledgements
Yes