hi
i install react native map and when i run-android i get this error
how can i fix this??
I was facing same issue. Just follow this guide.
https://gist.github.com/nazrdogan/87c63e89a2bfd4cefee24990e4e7ed0e
same here. I have the same issue
@nazrdogan I did all the steps but i get error
@ariya94
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Did you add google()
?
First do this:
https://github.com/react-community/react-native-maps/issues/2188#issuecomment-380757839
Make sure your gradle-wrapper.properties has
distributionUrl = https\://services.gradle.org/distributions/gradle-4.1-all.zip
(basically, update your gradle)
and your app/build.gradle has
implementation(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
implementation 'com.google.android.gms:play-services-base:10.0.1'
implementation 'com.google.android.gms:play-services-maps:10.0.1'
or (read docs to see which you want)
implementation project(':react-native-maps')
Okay I got it. The problem is that, the latest react-native-maps
is using syntax for Gradle 3.
So we get that error. to fix it, either Update gradle 3 or hack the react-native-maps
package inside ./node_modules
. Yup, inside ./node_modules
and change the build.gradle
and replace:
compile
to implementation
I've created an article on how to solve this problem. By installing react-native-maps
properly and upgrading the gradle version to 3.
Yes. Personally I'd prefer if we moved back to Gradle 2. Because most of the other packages are on Gradle 2. I'll have to generate an APK and put it through testing to see if anything is breaking.
Does anybody know how to fix this for the examples that come bundled with react-native-maps?
@nazrdogan
yes add it but still i have an error for google ()
@deorukhkarchaitanya
i done those but get this error
@nazrdogan
@deorukhkarchaitanya
thanks guys
my problem solved
i change the build tools to 26.0.2 and solve
but build tools 26.0.2 can be a problem for other components like (nativebase , ...)
@ariya94 I think its not problem for nativebase
, but can be problem other native plugin. I added my app react-native-camera
its makes problem for me and I used this guide.
https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f
I created an empty project to test the official instruction for Android, it didn't work. I tried every solution listed here but they don't work for me.
@stevemu
did add implementation method in app/build.gradle?
Does anybody know step by step add react-native-maps in android?
its working in my ios app and i have added lot of effort in android but not successful.
my app working fine with this steps.
https://gist.github.com/nazrdogan/87c63e89a2bfd4cefee24990e4e7ed0e
I may have found a workaround solution. In my test project, the newest version of the map (^0.21) with newest react native (0.55.2) works under iOS. But under Android, I had to use map 0.20.1 with newest react native version. So what I had to do is have the Android side use map 0.20.1, while the iOS can use the newest map version.
To that, I copied the map 0.20.1 to an separate folder. eg /older_modules/react-native-maps_0.20.1, then in settings.gradle, reference this older version:
rootProject.name = 'androidMapTest'
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../older_modules/react-native-maps_0.20.1/lib/android')
include ':app'
You will also need older version of syntax in configuration files in android side. The installation guide wouldn't not work.
Here is my build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:2.1.2' // <--- update this
classpath 'com.google.gms:google-services:3.2.0' // google-services plugin
}
}
allprojects {
repositories {
configurations.all {
resolutionStrategy {
force "com.google.android.gms:play-services-auth:11.8.0"
}
}
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
// -------------------------------------------------
// Add this below the existing maven property above
// -------------------------------------------------
maven {
url 'https://maven.google.com'
}
}
}
/**
+ Project-wide Gradle configuration properties
*/
app/build.gradle:
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation
* entryFile: "index.android.js",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.androidmaptest"
minSdkVersion 16
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
compile 'com.google.android.gms:play-services-base:11.8.0'
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.android.support:appcompat-v7:27.1.1'
}
// 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.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services' // <--- this should be the last line
MainApplication.java:
package com.androidmaptest;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.airbnb.android.react.maps.MapsPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MapsPackage()
);
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidmaptest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCk9Q1Tnco1DBQ8pfdlIy5ECx8eX3ySY_Y"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
You will also need the google-services.json.
Result:
@moseslucas aren't the installation docs accurate? if so maybe you can participate with a PR ? 🤗
@rborn the installation doc is accurate but there wasn’t any note telling us that we need to upgrade gradle to version 3 in order for react-native-maps
to work.
It’s also worth noting that in the docs, using react-native link
is discouraged. But actually we can still use it, then just add just the few remaining configs that wasn’t included in the link instead. That way, the installion/setup is faster.
I agree we can use link, however it breaks if you wanna use google maps on ios. If anybody can fix this I'm all for it
I agree, since the tutorial I made is only for Android, using react-native link
might not be advisable if you're also developing for iOS. Let's all hope that react-native
update its out of the box gradle version to 3 in the future.
@raktec I made a step-by-step guide installation of react-native-maps
with the fix for gradle 3 here.
You can fix this by navigating to node_modules/react-native-maps/lib/android/build.gradle and changing these lines
compileOnly "com.facebook.react:react-native:+"
implementation "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
implementation "com.google.maps.android:android-maps-utils:$androidMapsUtilsVersion"
to
provided "com.facebook.react:react-native:+"
compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
compile "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
compile "com.google.maps.android:android-maps-utils:$androidMapsUtilsVersion"
@moseslucas
I did fix it as well with your guide, I did it again from scratch.
The gradle check passed before, now the project is building but if you do a ./gradlew check there is still a building error :
What went wrong:
Execution failed for task ':app:lint'.Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
Then if you add :
lintOptions {
abortOnError false
}
It will become this error :
What went wrong:
Execution failed for task ':react-native-maps:lint'.Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
Someone has a solution to pass the ./gradlew check with the guide of @moseslucas ?
I attempted to follow the many links/guides to updating to gradle v4 + android gradle plugin v3 only to find gradle then blows up attempting to pull in my other react-native dependencies which are still targeting the android gradle plugin v2 syntax.
@RyanThomas73 follow @KarimFereidooni suggestion, worked for me!
@RyanThomas73 follow @KarimFereidooni , it works for me too!
$ yarn add replace-in-file --dev
scripts/react-native-maps-hack.js
with the content:const replace = require('replace-in-file')
const file = './node_modules/react-native-maps/lib/android/build.gradle'
const options1 = {
files: file,
from: /compileOnly/g,
to: 'provided'
}
const options2 = {
files: file,
from: /implementation/g,
to: 'compile'
}
replace(options1)
.then(changedFiles => {
console.log('modified compileOnly:', changedFiles)
})
.catch(error => {
console.error('Error occurred:', error)
}).then(
() => {
replace(options2)
.then(changedFiles => {
console.log('modified implementation:', changedFiles)
})
.catch(error => {
console.error('Error occurred:', error)
})
}
)
console.log('react-native-maps is fixed!')
$ node scripts/react-native-maps-hack.js
at the root of the project.Optional:
You can add the previous hack to scripts
to feel the luxury that node grant.
in package.json
in scrpits
add:
"react-native-maps-hack": "node scripts/react-native-maps-hack.js",
run $ yarn run react-native-maps-hack
to get the code running.
in case of npm
$ npm install replace-in-file --save-dev
$ npm run react-native-maps-hack
it repeated this failure to recreate successfull working react-native-maps
react - 16.3.1
react-native - 0.55.4
react-native-maps - 0.21.0
step 1
i created app like this
$react-native init tank1
step 2
I followed installation from
https://github.com/react-community/react-native-maps/blob/master/docs/installation.md
step 3
follow installation from
https://itnext.io/install-react-native-maps-with-gradle-3-on-android-44f91a70a395
step 4
in MainApplication.java
use without @Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new MapsPackage()
);
}
Note :
I had doub't about synatx@import GoogleMaps;
in AppDelegete.m
but this too works fine
Then you much help me please ?
There are two working solution for this issue
solution 1.
easily update gradle version to 3
solution 2.
change ./node_modules/react-native-maps/lib/android/builg.gradle
compileOnly
--> provided
implementation
--> compile
thank you very very much my friend..
Goliath
On Mon, 23 Jul 2018 20:43 Masoud Tavakkoli, notifications@github.com
wrote:
There are two working solution for this issue
solution 1.
easily update gradle version to 3solution 2.
change ./node_modules/react-native-maps/lib/android/builg.gradlecompileOnly --> provided
implementation --> compile—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/react-community/react-native-maps/issues/2188#issuecomment-407160458,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATj5b9lcCk9bzpdHJbat8UclCX8CNTVWks5uJhlJgaJpZM4TRQD0
.
@KarimFereidooni I tried doing this but after trying to build my project I get:
Conflict with dependency 'com.android.support:support-v4' in project ':react-native-maps'. Resolved versions for compilation (26.1.0) and packaging (24.0.0) differ. This can generate runtime errors due to mismatched resources.
:react-native-maps:prepareDebugDependencies FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-maps:prepareDebugDependencies'.
> Dependency Error. See console for details.
You can see the forked react-native-maps
repo I'm using here: https://github.com/jamesone/react-native-maps/tree/rm-airgooglemaps - I forked off of @mikemorris PR which adds support for using react-native link
so we don't need to use Carthage (note: The fork contains the most recent rn-maps changes).
Sidenote: iOS works flawlessly
@jamesone You could try excluding the com.android.support:support-v4
library from react-native-maps like to default to using the version supplied by what I'm guessing is another package.
compile(project(':react-native-maps')){
exclude group: 'com.android.support', module: 'support-v4'
})
Alternatively, you could try something like https://github.com/react-native-community/react-native-camera/issues/1532#issuecomment-392081796 to force resolution to a particular version of com.android.support:support-v4
for all packages.
@mikemorris I tried adding:
compile(project(':react-native-maps')){
exclude group: 'com.android.support', module: 'support-v4'
})
but it didn't work. It threw the exact same error as listed here: https://github.com/react-community/react-native-maps/issues/2188#issuecomment-413134041
Here is my build.gradle
: (dependencies section)
dependencies {
// Tried this, but it doesn't work same v4- support error
compile (project(':react-native-maps')) {
exclude group: 'com.android.support', module: 'support-v4'
}
// 1. ALSO TRIED THIS:
// compile(project(':react-native-maps')) {
// exclude group: 'com.google.android.gms', module: 'play-services-base'
// exclude group: 'com.google.android.gms', module: 'play-services-maps'
// }
// 2. ALSO TRIED THIS:
// compile project(':react-native-maps');
// Tried this, but it doesn't work same v4- support error
compile ("com.android.support:support-v4:26.0.1") {
force = true //<-- force dependency resolution to 26.0.1 in my case
}
compile fileTree(dir: "libs", include: ["*.jar"])
compile ("com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}")
// From previous RN version (0.55) - Tried this, but it doesn't work same v4- support error
// compile('com.android.support:appcompat-v7:23.0.2') {
// exclude group: 'com.google.android.gms', module: 'play-services'
// }
compile('com.google.android.gms:play-services-base:+') {
force = true;
}
compile('com.google.android.gms:play-services-maps:+') {
force = true;
}
// compile "com.facebook.react:react-native:+" // RN 0.56 upgrade line
// from node_modules
compile('com.facebook.react:react-native:+') {
exclude group: 'com.google.android.gms', module: 'play-services'
}
compile 'com.android.support:multidex:1.0.1'
}
Hi, any news?
@jamesone
Seems to have solved by upgrading to gradle 3
Here's a patch-package patch
https://gist.github.com/epeli/f7a518f22c485d0cb9c7eb1b12d63631
from the node_modules/gradle.build workaround https://github.com/react-community/react-native-maps/issues/2188#issuecomment-385420099
Here is what my native android files look like:
app/Build.gradle -> dependencies {:
....
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"
compile(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
....
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
task wrapper(type: Wrapper) {
gradleVersion = '4.4' //version required
}
buildscript {
repositories {
/**
* Must stay in this order
*/
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
subprojects {
afterEvaluate { project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27
}
}
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "$rootDir/../node_modules/react-native/android" }
mavenCentral()
}
}
ext {
buildToolsVersion = "26.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}
Once this in place, you'll need to:
gradle
(if you haven't already) (you can do this via brew)cd android
gradle wrapper
gradle wrapper
has successfully ran./gradlew assemble
This is what I had todo to get mine working
Check this answer here for more details: https://stackoverflow.com/a/27982996/4140346
I got this error among others that were similar, I just changed compile to implementation in the apps build.gradle and it suddenly started building again. I'd suggest to start with that
Best Solution --
https://github.com/react-native-community/react-native-camera/issues/1490#issuecomment-381852316
I’m closing this issue because it has been inactive for a while. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on for so long, then it seems no one has the time to implement this.
Please reopen if you still encounter this issue with the latest stable version.
Thank you!
Most helpful comment
Okay I got it. The problem is that, the latest
react-native-maps
is using syntax for Gradle 3.So we get that error. to fix it, either Update gradle 3 or hack the
react-native-maps
package inside./node_modules
. Yup, inside./node_modules
and change thebuild.gradle
and replace:compile
toimplementation
I've created an article on how to solve this problem. By installing
react-native-maps
properly and upgrading the gradle version to 3.Follow guide/tutorial here.