Android: AIRMap was not found in the UIManager - react-native

So i'm trying to implement a map view in my react native app, using react-native-maps. When i'm installing it with npm it's all good, and linking it makes no errors. The problem is when i try to run it, then I get the
Invariant Violation: requireNativeComponent: "AIRMap" was not fount in the UIManager.
I've narrowed it down to being on the Android side, since that's the emulator i'm running. For some reason, the gradle files seems broken and I have no idea of what it can be. I've tried most guides i've found but none seems to handle the issue. I've tried to link it manually, remove the link and so on. I've also tried adding the direct link to GitHub which doesn't solve it either.
Some build info:
React version: 0.60.0
Gradle version: 5.4.1
Emulator version: Pie API 28
settings.gradle:
rootProject.name = 'ProjectName'
apply from: file("../node_modules/#react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings)
include ':app'
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
build.gradle:
implementation 'com.facebook.react:react-native:+
implementation project(':react-native-maps')
MapView:
import MapView from 'react-native-maps'
<MapView
region={{
latitude: 42.882004,
longitude: 74.582748,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
></MapView>
Lastly, I have also created an API to Google maps in the android project.
The project is manageable to recreate by initiating a new react-native project and implementing react-native-maps

For Android
AndroidManifest.xml
<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzDDDBBLn-PhCtBM1AnC_h66yH8Lw2DDD14WW0"/>
</application>
MainApplication.java
import java.util.List;
import com.airbnb.android.react.maps.MapsPackage; // <-- Add this line
...
#Override
protected List<ReactPackage> getPackages() {
#SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new MapsPackage()); // <- ADD THIS LINE
return packages;
}
android/settings.gradle
if you are not using monorepo technique
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../../../node_modules/react-native-maps/lib/android')
android/build.gradle
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
supportLibVersion = '28.0.0'
playServicesVersion = "17.0.0" // or find latest version
googlePlayServicesVersion = "17.0.0" // or find latest version
androidMapsUtilsVersion = "2.2.3"
}
repositories {
jcenter()
google() // keep google() at last
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../../../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../../../node_modules/jsc-android/dist")
}
jcenter()
maven { url 'https://www.jitpack.io' }
google() // keep google() at last
}
}
android/app/build.gradle
dependencies {
...
implementation project(':react-native-maps') // at last
}
Notes
I am using ../../../node_modules because I am using Monorepo technique to maintain 2 apps in one git repo
../node_modules might work for you
keep google() at last of the code-block
IOS
See this for solution in IOS https://stackoverflow.com/a/67945288/3437900

Related

React-native Expo Build Failed : Task :app:checkDebugDuplicateClasses FAILED [duplicate]

Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.3.31 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31)
Duplicate class kotlin.jdk7.AutoCloseableKt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.3.31 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31)
**./gradlew clean **
build.gradle file:
buildscript {
ext {
buildToolsVersion = "30.0.0"
minSdkVersion = 23
compileSdkVersion = 33
targetSdkVersion = 30
googlePlayServicesAuthVersion = "16.0.1"
kotlinVersion = "1.8.0"
}
firebase: [
bom : "26.0.0"
]
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
classpath "com.google.gms:google-services:4.3.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
repositories {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
mavenLocal()
maven {
url("$rootDir/../node_modules/react-native/android")
}
maven {
url("$rootDir/../node_modules/jsc-android/dist")
}
maven { url 'https://maven.google.com' }
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
I had the same problem with my app. It failed to build because of duplicate classes found in modules jetified-kotlin-stdlib-1.8.0 and jetified-kotlin-stdlib-jdk8-1.6.10
With the link, shared by Igor VANIAN : https://kotlinlang.org/docs/whatsnew18.html#usage-of-the-latest-kotlin-stdlib-version-in-transitive-dependencies
I added
dependencies {
...
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
}
to my android/app/build.gradle and Android builds fine now
I started having the same issue in react native native on the android side. I upgraded Kotlin to version 1.8.0 and built the app again and the issue was fixed. Maybe trying upgrading the kotlin version.
In android/build.gradle update the following
kotlinVersion = "1.8.0"
and add this under dependencies
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
This can happen when you're using different versions for different Kotlin dependencies.
Try to check all Kotlin dependencies. In my case, issue was with this core-ktx
implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Updating to this resolved issue
implementation "androidx.core:core-ktx:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Here kotlin_version = '1.7.0'. You can use your desired version.
Hope this will help others.
I was having the same problem since yesterday.
I found that the reason behind this could be the artifact merge in Kotlin 1.8.0. Here is an issue talking about this breaking change.
So setting kotlinVersion = "1.8.0" as #Narasimha said works. But I still didn't figure out what dependency changed overnight that somehow made kotlin-stdlib:1.8.0 appear in the build logs.
Thanks all, I solve it by doing two things
In android/build.gradle update the following
kotlinVersion = "1.8.0"
In android/app/build.gradle add the following in dependencies
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
I had the same issue today and I fixed it in a different way, if it helps anyone:
When I upgraded my kotlin to version 1.8 it started happening and I had to change my hilt version to 2.44. Now it's running normally.

Execution failed for task ':realm:stripDebugDebugSymbols'

After installing realm in react native and setting up all necessary things console give me this error after starting project (npm run android);
Execution failed for task ':realm:stripDebugDebugSymbols'. NDK at C:\Users\123\AppData\Local\Android\Sdk\ndk\21.4.7075529 did not have a source.properties file.
I check ndk in android studio (after opening project in it) in Android SDK --> SDK tools sections, the ndk already installed. I also change the ndk version (one by one) in android/build.gradle according to some other stackoverflow solutions but didn't work. Below is android/build.gradle code;
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"//"25.1.8937393"//"21.1.6528147"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
This is a android studio screen shot of sdk tools SDK tools

Google Service download failure in gradle

Followed the instructions specified in firebase cloud platform. Getting this issue while running the gradle build.
Could not resolve all artifacts for configuration ':classpath'.
> Could not find com.android.gms:google-services:4.3.3.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/gms/google-services/4.3.3/google-services-4.3.3.pom
- https://jcenter.bintray.com/com/android/gms/google-services/4.3.3/google-services-4.3.3.pom
Required by:
project :
build.gradle , with the artifact added.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
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")
classpath("com.android.gms:google-services:4.3.3")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
Any inputs to the issue will help, checked firewall and proxy issues already.
There are two build.gradle files in an Android Project. One is for app-level and another one is for your project root-level.
In order to setup Firebase correctly, You have to write like following in your root-level (project-level) Gradle file (build.gradle):
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
// ...
// Add the following line:
classpath 'com.google.gms:google-services:4.3.3' // Google Services plugin
}
}
allprojects {
// ...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
// ...
}
}
In your module (app-level) Gradle file (usually app/build.gradle), apply the Google Services Gradle plugin like below snippet:
apply plugin: 'com.android.application'
// Add the following line:
apply plugin: 'com.google.gms.google-services' // Google Services plugin
android {
// ...
}
You are doing everything but in the app-level file. Try Fixing it and tell whether it worked or not.

How to fix missing ReactContextBaseJavaModule symbol?

I wan't to create a custom native module for my app only - so no lib. Following the docs it gives me an error:
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Cannot resolve symbol 'ReactContextBaseJavaModule'
My app's android/app/build.gradle includes this line, which is included in all react-native modules I have used so far as well.
"com.facebook.react:react-native:+" // From node_modules
My android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://maven.google.com' }
}
}
Below are the steps I encountered and used to solve importing all the libraries related to React Native Libraries in the Android Studio:
First when I created a brand new react native library project using react-native-create-library command, the command generated iOS and Android files.
I opened the android folder using Android Studio.
The gradle build reported some errors and fixed the gradle issue by updating some values in build.gradle and gradle-wrapper.properties.
build.gradle
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "27.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
compile 'com.facebook.react:react-native:+'
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
After adding the above 2 changes, Click Sync Now or Try again. In this step if it asks to install the build version, please install.
Now Clean and Rebuild the project, On top status bar of the Android Studio:
Click Build --> Clean Project then
Click Build --> Rebuild Project
After step #5, React Native import errors should disappear and the libraries related to React Native must be imported.
Thanks.

react-native-mauron85-background geolocation error

The following error appears when try to build my react native for production (running ./gradlew assembleRelease),
...
/node_modules/react-native-mauron85-background-geolocation/android/common/src/oreo/java/com/marianhello/bgloc/NotificationHelper.java:4: error: cannot find symbol
import android.app.NotificationChannel;
^
symbol: class NotificationChannel
location: package android.app
...
Execution failed for task ':react-native-mauron85-background-geolocation-common:compileOreoReleaseJavaWithJavac'
Anybody encountered this error before?
Just adding what solved my problem in case anyone is having the same problem.
After tearing off a lot of hairs (although I lack it) I came to a solution. Not sure whether is gonna work for others, you can give it a try.
Add following codes in android/build.gradle
allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "https://maven.google.com" }
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
ext {
compileSdkVersion = 26
targetSdkVersion = 26
buildToolsVersion = "26.0.2"
supportLibVersion = "26.1.0"
googlePlayServicesVersion = "11.8.0"
}
And make sure the dependencies are installed.