'react-native-safe-area-context throw `Unresolved reference:` error
While trying to upgrade react-native-navigation I got the following error, after upgrading react-native-safe-area-context
Note: Recompile with -Xlint:deprecation for details.
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt: (12, 34): Unresolved reference: R
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt: (15, 34): Unresolved reference: getInsets
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt: (16, 24): Unresolved reference: Type
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt: (17, 28): Unresolved reference: Type
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt: (18, 28): Unresolved reference: Type
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaUtils.kt: (55, 50): Unresolved reference: R
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt: (8, 37): Unresolved reference: FabricViewStateManager
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt: (9, 37): Unresolved reference: FabricViewStateManager
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt: (19, 66): Unresolved reference: HasFabricViewStateManager
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt: (24, 41): Unresolved reference: FabricViewStateManager
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt: (26, 3): 'getFabricViewStateManager' overrides nothing
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt: (26, 45): Unresolved reference: FabricViewStateManager
e: /home/me/myProject/node_modules/react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaViewManager.kt: (71, 10): Unresolved reference: fabricViewStateManager
FAILURE: Build failed with an exception.
My Build-Script:
buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:3.5.3')
}
}
Solution 1:[1]
Short Solution:
If you use ReactNative <= 0.63, install react-native-safe-area-context in V3 (e.g 3.4.1), as it's not compatible with v4 of safe-area-context
Long Painfull journey, that also fix some other of my errors on the way:
This helps me to solve it:
First, set your buildscript-version:
- minSdkVersion = 24 (That is Android 7 [nougat])
- targetSdkVersion =
- compileSdkVersion = 31 (set latest possible here)
Explaination what those Versions do:
| A header | Another header |
| -------- | -------------- |
| minSdkVersion | set lowest Android-Version you want to support with your app. But keep in mind, that your app’s minSdkVersion must be at least as high as your dependencie-requirements
The Google Play Store also use this to determine which of a user’s devices an app can be installed on |
| targetSdkVersion | This is the main way Android provides forward compatibility by not applying behavior changes unless the targetSdkVersion is updated |
| compileSdkVersion| is the Version your app will be compiled with. Changing this Value does not change runtime behavior, your compileSdkVersion is not included in your APK |
If you want to read more about this, see here
NOTE: If you increase the compileSdkVersion, make sure, you've also installed the new SDK at your PC. In my case I missed that and got a non helping error like:
* Where:
Build file '/home/me/myProject/android/app/build.gradle' line: 130
* What went wrong:
A problem occurred evaluating project ':app'.
> No signature of method: build_bzoaxr1mlfb80yiyz2yt0w97u.android() is applicable for argument types: (build_bzoaxr1mlfb80yiyz2yt0w97u$_run_closure1) values: [build_bzoaxr1mlfb80yiyz2yt0w97u$_run_closure1@1068678f]
E.g. in Android-Studio it looks like this: 
Then have a look to upgrade gradle-plugin.
https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle
After upgrading Gradle, I got this error:
10:01 Gradle sync failed: Could not get unknown property 'compile' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer. (3 s 273 ms)
So I've changed from configurations.compile to implementation in android/app/build.gradle:
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.implementation
into 'libs'
}
Then the gradle-sync succeed without error.
As I did this in android studio I've cleared the project buy run > clean project, but you also can go to /android and run ./gradlew clean
But as I've tried to start the Application, I got an issue. After some search on stackoverflow, the cause seems to be, that RN still not compatible with Gradle7. So back to 6.9:
cd /android && ./gradlew wrapper --gradle-version 6.9
I've also had to change build:gradle-tools to 4.2.2
dependencies {
classpath('com.android.tools.build:gradle:4.2.2')
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
