react-native-maps: Build process failed - :app:dexDebug FAILED

I init new react-native project and I wanted to include react-native-maps, but it shows me this error.

:app:dexDebug
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;
Unknown source file :   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file :   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file :   at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file :   at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file :   at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file :   at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file :   at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file :   at com.android.dx.command.Main.main(Main.java:106)

:app:dexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I had to add /lib at the end in projectDir in android/settings.gradle

include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android/lib')

I do not know, what am I doing wrong. I am sure, that problem is in somewhere in react-native-maps module, because it was the last, what I installed from npm and then I wanted to build and it shows me error.

Dependencies:

"apsl-react-native-button": "^2.5.0",
    "axios": "^0.12.0",
    "buffer": "^4.7.0",
    "install": "^0.8.1",
    "lodash": "^4.13.1",
    "npm": "^3.10.5",
    "react": "15.2.1",
    "react-dom": "^15.2.1",
    "react-motion": "^0.4.4",
    "react-native": "0.29.0",
    "react-native-animatable": "^0.6.1",
    "react-native-button": "^1.6.0",
    "react-native-camera": "github:lwansbrough/react-native-camera",
    "react-native-carousel": "^0.8.0",
    "react-native-dismiss-keyboard": "^1.0.0",
    "react-native-drawer": "^2.2.6",
    "react-native-fit-image": "^1.3.2",
    "react-native-gifted-spinner": "0.0.5",
    "react-native-keyboard-spacer": "^0.3.0",
    "react-native-maps": "^0.7.1",
    "react-native-orientation": "^1.17.0",
    "react-native-responsive-image": "^1.3.0",
    "react-native-router-flux": "^3.31.0",
    "react-native-simple-store": "^1.0.1",
    "react-native-spring-carousel": "^0.3.4",
    "react-native-vector-icons": "^2.0.3",
    "react-redux": "^4.4.5",
    "redux": "^3.5.2",
    "redux-form": "^5.3.1",
    "redux-promise": "^0.5.3",
    "redux-thunk": "^2.1.0"

Thanks for help.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (1 by maintainers)

Most upvoted comments

not sure why but if you go into android and do a ./gradlew clean it solves the issue

yep. i solved by: cd android/ && ./gradlew clean && cd … && react-native run-android

Not working for me, same error… 😕

I try to reproduce my work. Maybe something will help you identify, what am I doing wrong. (not just me like I see). I build on real device Samsung J5 Android 5.1.1.

react-native init test2
cd test2
react-native run-android
adb reverse tcp:8081 tcp:8081
react-native start

Everything works well, but this is clean RN0.29. Then

npm install --save react-native-maps
sudo rnpm link react-native-maps

Then I add Google Maps key to AndroidManifest.xml. Point 4 in installation instructions. Then

react-native run-android

First false:

$ react-native run-android
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Cannot evaluate module react-native-maps : Configuration with name 'default' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

This false was fixed like I wrote in first comment with add /lib at the end in projectDir in android/settings.gradle. Then

:app:dexDebug
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim;
Unknown source file :   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file :   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file :   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file :   at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file :   at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file :   at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file :   at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file :   at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file :   at com.android.dx.command.Main.main(Main.java:106)

:app:dexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I fixed this with texas697 idea, so thumbs up for him.

$ ./gradlew clean
:app:clean
:react-native-maps:clean

BUILD SUCCESSFUL

Total time: 1.47 secs

Then

react-native run-android
adb reverse tcp:8081 tcp:8081
react-native start

Build process success, but shows blank view and false in console.

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
    Dimensions
} from 'react-native';
import MapView from 'react-native-maps/components/MapView';

let { width, height } = Dimensions.get('window');

const ASPECT_RATIO = width / height;
const LATITUDE = 37.78825;
const LONGITUDE = -122.4324;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;

class test2 extends Component {
  render() {
    return (
      <View style={styles.container}>
          <MapView
              ref="map"
              style={styles.map}
              initialRegion={{
                  latitude: LATITUDE,
                  longitude: LONGITUDE,
                  latitudeDelta: LATITUDE_DELTA,
                  longitudeDelta: LONGITUDE_DELTA
              }}
          />
      </View>
    );
  }
}

const styles = StyleSheet.create({
    container: {
        position: 'absolute',
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
        justifyContent: 'flex-start',
        alignItems: 'center'
    },
    map: {
        position: 'absolute',
        top: 0,
        left: 0,
        right: 0,
        bottom: 0
    }
});

AppRegistry.registerComponent('test2', () => test2);

I think somebody wrote about this issue, but not for Android, but IOS. I did not test it on IOS.

false

Thanks for help.

try this on build.gradle

compile (project(':react-native-maps')) {
        exclude group: "com.google.android.gms"
    }

Yes, this worked for me too.

cd android ./gradlew clean

cd … react-native run-android

Any idea why this is?