I am exploring the possibility of using mapsfoge/graphhopper in an android application, but am not able to get the test to compile with graphhopper.
Based on research, I believe the problem is with dependencies within graphhopper and mapsforge.
Here is the exception:
Execution failed for task ':app:dexDebug'.
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/applantation/android/svg/ParserHelper;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
My application builde.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.test.maptest"
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'org.mapsforge:mapsforge-map-android:0.4.3'
compile 'com.graphhopper:graphhopper-android:0.3'
}
It looks like the problem is with svg-android, which is relied upon by mapsforge-android. What is odd is that the app complies and runs fine if I just use mapsforge-map-android. I have also tried removing the mapsforge-map-android line from my gradle.build file since mapsforge is brought in via graphhopper, but still no luck.
Any help resolving this would be much appreciated!
An update to how I fixed the issue:
I wasn't able to track down exactly what was happening, so take the following as simply what it is: my work around (though do note this is the recommended way of doing things according to the github docs).
I ended up grabbing the latest code from github, compiling that into jars (via the shell script). This creates a graphhopper-0.4-SHAPSHOT-android.jar, and the slf4j-android-1.6.1-RC1.jar, and I put those in the libs directory of my project.
NOTE: I think the issue may be there are updates merged into the current master branch on Github which have not been pushed out to Maven Central. You cannot use .3 of the graphhopper library, and as this is the only version in the central repository, you are unable to just add graphhopper to your build.gradle as I was attempting.