Can't compile tests with Robolectric - android

My build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.stanfy.spoon:spoon-gradle-plugin:0.10.0'
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'android'
apply plugin: 'spoon'
apply plugin: 'robolectric'
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
testInstrumentationRunner 'com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner'
}
buildTypes {
debug {
}
release {
}
}
productFlavors {
first {
//just version codes and packages
}
second {
//just version codes and packages
}
third {
//just version codes and packages
}
}
}
spoon {
debug = true
}
dependencies {
compile project(':app:libs:facebookSDK')
compile 'com.google.android.gms:play-services:5.0.89'
compile 'com.android.support:support-v4:20.0.0+'
compile 'com.google.code.gson:gson:2.2.4'
compile fileTree(dir: 'libs', include: '*.jar')
androidTestCompile fileTree(dir: 'libsTest', include: '*.jar')
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.0'
androidTestCompile 'junit:junit:4.+'
androidTestCompile 'org.robolectric:robolectric:2.3'
}
libsTest: espresso-contrib-1.1-bundled.jar
Now, my error is following:
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/SelfDescribing;
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)
More detailed log available here:
http://pastebin.com/Yye3cd1c
How do I fix this issue?
UPD:My question now is basically how do I hunt those duplicated parts?

My question now is basically how do I hunt those duplicated parts?
You do this using the log. The log you pasted says:
com.android.dex.DexException: Multiple dex files define
This is most probably due to the conflicting libraries. The log continues with:
Lorg/hamcrest/SelfDescribing;
Here is the conflicting library, hamcrest.
After adding dependencies to your project, if there are common sub-libraries used by your libraries (or as your libraries), this error occurs. So it seems like hamcrest is being used by not only one of your libraries.
We'll learn about this conflict by inspecting dependencies. Of course an efficient inspection needs to be both intuitive and rational at the same time.
Let's start with hamcrest itself. (I'll assume you haven't heard of hamcrest before.)
Let's take a look at Hamcrest project page. Hamcrest defines itself as library of matchers for building test expressions. And the definition says Typical scenarios include testing frameworks, mocking libraries... This is illuminating because you have some dependencies about testing like JUnit, Espresso and Robolectric.
Now we should continue with JUnit dependencies. Seems like JUnit makes use of hamcrest-core. Here is our first hamcrest as a sub-dependency.
Let's continue with Espresso, as you have espresso-contrib-1.1-bundled.jar in libsTest folder.
When we check out espresso-contrib project dependencies, we can see that Espresso makes use of hamcrest heavily.
We probably get the conflicting library in your project, the last step is excluding hamcrest-core from one of our dependencies while adding this dependency. You can achieve this with:
androidTestCompile('junit:junit:4.+') {
exclude module: 'hamcrest-core'
}

I had a similar issue a while ago and if I remember correctly, I fixed it by adding an exclude statement as follows:
androidTestCompile('junit:junit:4.+') {
exclude module: 'hamcrest-core'
}

Inspired from the deckard-gradle sample project, I suggest trying something like this:
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}

One trick to hunt those errors is using Android Studio "Navigate > Class..." option.
Given you have this error:
Lorg/hamcrest/SelfDescribing;
then you can search "org.hamcrest.SelfDescribing" so you can have an idea of the .jars using it.

Related

java.util.zip.ZipException: duplicate entry: android/support/v4/view/MotionEventCompatEclair.class

I'm new to android studio and am trying to import a project from eclipse but I feel like i am running into every single problem possible. The error I'm currently getting is:
Error:Execution failed for task ':jobFlexwithInvoice:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/view/MotionEventCompatEclair.class
Ive seen similar answers to problems like here and here. But i think I need more help because its just not going away. I've added the exception to just about everything in my build.gradle file, including the actual support 4v dependency just for kicks, and am still getting this error. And also I have multiple build.gradle files because of included projects? It seems like the project build.gradle file can be ignored, I just have to add the exceptions to the module build.gradle files? (which is annoying when someone says to add something to the build.gradle file, im not always sure which one)
Anyway, here are the dependencies sections of each of my build.gradle files as they currently are:
myApp:
dependencies {
compile ('com.android.support:multidex:1.0.0'){
exclude module: 'support-v4'
}
compile project(':facebook') {
exclude module: 'support-v4'
}
compile project(':apptentive')
compile project(':androidsdkui'){
exclude module: 'support-v4'
}
compile ('com.google.android.gms:play-services:+'){
exclude module: 'support-v4'
}
compile files('libs/android-support-v13.jar') {
exclude module: 'support-v4'
}
compile files('libs/DynamicPDF.jar')
compile files('libs/picasso-2.5.0.jar')
compile ('com.android.support:support-v4:22.0.0'){
exclude module: 'support-v4'
}
}
facebook:
dependencies {
compile files('libs/bolts-android-1.2.1.jar')
compile ('com.android.support:support-v4:22.0.0'){
exclude module: 'support-v4'
}
}
androidsdkui:
dependencies {
compile files('libs/appboy.jar')
compile ('com.android.support:support-v4:22.0.0'){
exclude module: 'support-v4'
}
}
there is also an apptentive build.gradle file but it does not have any dependencies. Before adding all of these exceptions I was getting the same error as the one in the first link, now the only difference is its android/support/v4/view/MotionEventCompatEclair.class instead of android/support/v4/util/TimeUtils.class
If there is a way to see where the duplicates are coming from that would be great too, I was unable to find anything with a quick google search.
I updated the question so you can see some of the ways I was doing things wrong. Some of my projects included support v4 and I wasn't excluding them right. The proper way to exclude things from projects is:
compile (project(':facebook')) {
exclude module: 'support-v4'
}
you have to put the extra set of parenthesis around everything after compile. Im assuming the same goes for excluding things from files
ie.
compile file(myfile.jar)
would become
compile (file(myfile.jar)) {
exclude module: 'support-v4'
}
Could you try adding the following in the top-level build.gradle file inside allprojects element? It should look something like below.
allprojects {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
}
Hope this helps.

Warning:Conflict with dependency 'com.android.support:support-annotations'

I have tried almost every trick in the book.
ResolutionStrategy.force
Excluding modules
But nothing seems to work, below is my build.gradle. I'm using Gradle version 1.2.3. Can someone please throw light on what else could be wrong with my code.
The only thing I haven't tried is changing version of Gradle.
It's a very basic Espresso Test case. Thanks!
apply plugin: 'com.android.application'
android {
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.1.0'
}
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.rasika.job"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
}
I forked android-topeka google sample and updated appcompat version to 23.1.0, same message:
Warning:Conflict with dependency
'com.android.support:support-annotations'. Resolved versions for app
(23.1.0) and test app (23.0.1) differ.
I added:
androidTestCompile 'com.android.support:support-annotations:23.1.0'
Now both resolve to 23.1.0, the warning is gone, and the app and tests still work.
I'm not sure that it's the better solution, so I'm searching for another but found your question.
Update: Read this good explanation by PaulR.
Update2: Confirmed, android-testing google sample does it.
// Testing-only dependencies
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile 'com.android.support:support-annotations:23.0.1'
Update3: Another good response by CommonsWare.
Check your specific versions/conflicts/resolutions using:
./gradlew -q yourmodule:dependencies
Appcompat is 22.1.1 in your case but you are forcing 22.1.0.
Update4:
Dependency conflict explained at The Android Build System (Android Dev Summit 2015).
Resolving conflicts between main and test APK
When instrumentation tests are run, both the main APK and test APK
share the same classpath. Gradle build will fail if the main APK and
the test APK use the same library (e.g. Guava) but in different
versions. If gradle didn't catch that, your app could behave
differently during tests and during normal run (including crashing in
one of the cases).
To make the build succeed, just make sure both APKs use the same
version. If the error is about an indirect dependency (a library you
didn't mention in your build.gradle), just add a dependency for the
newer version to the configuration ("compile" or "androidTestCompile")
that needs it. You can also use Gradle's resolution strategy
mechanism. You can inspect the dependency tree by running ./gradlew
:app:dependencies and ./gradlew :app:androidDependencies.
I solved the conflict by adding dependency:
androidTestCompile 'com.android.support:support-annotations:23.2.0'
I had the same issue, solved by this:
// build.gradle
...
android {
...
defaultConfig {
...
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2') {
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
}
}
solution was found here:
https://github.com/codepath/android_guides/wiki/UI-Testing-with-Espresso
UPDATE:
finally dependencies block in my build.gradle looks like this:
dependencies {
...
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:design:23.2.1'
...
// Necessary if your app targets Marshmallow (since Espresso
// hasn't moved to Marshmallow yet)
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support:support-annotations:23.2.1') {
exclude group: 'com.android.support'
}
androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.2') {
exclude group: 'com.android.support'
}
}
This happened to me recently when adding the uiautomator. To fix this issue, you need to figure out which dependency or dependencies is using the outdated module. You can do this by wrapping each androidTestCompile dependency into a block, like so:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
transitive = false;
}
This might break some other things though, so you need to be careful. I was able to pinpoint exactly which two of the dependencies was causing this issue for me, and just adding this blocking mechanism to those.
I solved the conflict by excluding the support-annotation library from both runner and espresso-core dependencies:
androidTestCompile 'com.android.support.test:runner:0.5',{
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2'){
exclude group: 'com.android.support', module: 'support-annotations'
}
Add follow codes to your dependency block in build.gradle file
compile 'com.android.support:support-annotations:23.2.1'
testCompile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support:support-annotations:23.2.1'
Add this to your main build.gradle:
allprojects {
...
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.1'
}
...
}
androidTestCompile change to testCompile. And remind dont't change it to compile, just need this dependencies to be compiled into our debug APK or test APK.
For me this worked fine
dependencies {
androidTestCompile 'com.android.support:support-annotations:23.1.1'
}
I solved the conflict by adding dependency:
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
...
androidTestCompile 'com.android.support:support-annotations:23.2.1'
In also got into the Problem saying
Could not resolve
com.android.support:support-annotations:23.1.0
and tried to find in other servers ,
But what resolved my problem is adding :
google-service.json
file from
https://developers.google.com/mobile/add
and copy and paste it into
YourAndroidProject/app
Then recompile it and i hope your code will fly
Use this for resolving conflict
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
I solved the conflict by adding dependency:
androidTestCompile "com.android.support:support-annotations:26.0.0-beta1"

Exclude support v4 in gradle to remove duplicate but getting java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14

I have an old eclipse based project , and i converted it to android studio based. The convertion success, but i have problem when adding other dependency, first i get error java.exe finished with non-zero exit value 2, because of duplicate dependency support v4, and i try to exlude modul support v4, but now im getting java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
this is my build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':SlidingMenu')
compile project(':PhotoView')
compile project(':viewpager')
compile project(':StackBlur')
compile project(':FacebookSDK')
compile files('libs/LibAllShareInterface_2.0.0.jar')
// Exclude module support-v4 to remove duplicate
compile ('com.android.support:appcompat-v7:22.2.0') { exclude module: 'support-v4' }
compile('com.android.support:design:22.2.0') { exclude module: 'support-v4' }
compile('com.squareup.picasso:picasso:2.5.2') { exclude module: 'support-v4' }
compile('com.android.support:recyclerview-v7:21.0.0') { exclude module: 'support-v4' }
compile('com.android.support:cardview-v7:22.2.0') { exclude module: 'support-v4' }
compile('com.android.support:support-annotations:22.2.0') { exclude module: 'support-v4' }
}
Any help will be appreciated
Well although I am not gradle expert and I'm experiencing some problems myself, I was able to reproduce an error complaining about appcompat-v4, using your dependencies.
It seems that you are completely excluding support-v4 from all your dependencies, and since support-v4 is required, you must either specify it as a dependency separately, or change this:
compile ('com.android.support:appcompat-v7:22.2.0') { exclude module: 'support-v4' }
to this:
compile ('com.android.support:appcompat-v7:22.2.0')
so you don't exclude support-v4 completely from your project.
I did the second and the project could build (A sample project with just those dependencies defined).

Android Gradle Dependency conflict with internal version provided by Android

Possible duplicate of this question, although the solution did not help me.
I hate copy/paste all source code but seems in gradle there is no way :( since this is the 3rd day that gradle staffing me around I put my codes here and my apology for putting so much code...
I have three projects in my main project. Therefore my settings.gradle looks like this:
include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
and my main build.gradle (in root of project) looks like this:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
}
}
ext {
ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'
androidConfiguration = {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'values/com_crashlytics_export_strings.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
lintOptions {
abortOnError false
absolutePaths false
lintConfig file("lint.xml")
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/resources']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
java {
exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
}
}
}
signingConfigs {
debug {
storeFile file("$rootProject.projectDir/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
storePassword System.getenv("PASSWORD")
keyAlias System.getenv("ALIAS")
keyPassword System.getenv("PASSWORD")
}
}
}
}
For doing Unit test by Robolectric and Instrument test I am following Decard-Gradle project that I tested and works successfully.
booking-sdk is the project that holds business logic of app. It's structure is like this:
-booking-sdk
-/build
-/src
- booking_1 (flavour 1)
- booking_2 (flavour 2)
- main
- test
- build.gradle
I have same package name under /src/main/java and /src/test/java. Finally, build.gradle of booking-sdk looks like this:
apply plugin: 'com.android.library'
android androidConfiguration
android {
publishNonDefault true
productFlavors {
booking_1 { }
booking_2 { }
}
}
dependencies {
repositories {
mavenCentral()
}
compile ANDROID_SUPPORT
compile CRASHLYTICS
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup:otto:1.3.5'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile files('src/main/libs/GeoPIP4J.jar')
// Robolectric
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'
// TODO: requires special build of robolectric right now. working on this...
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}
When I run clean command the result is:
./gradlew :booking-sdk:clean
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1DebugUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1ReleaseUnitTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
:booking-sdk:clean
BUILD SUCCESSFUL
Total time: 4.83 secs
Error happens when I run ./gradlew :passenger-sdk:check code to see unit test result. I'm getting above outputs first then a lot of errors like this:
...
:booking-sdk:compileBookingDebugUnitTestJava
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
It is basically saying all my imports do not exist while they do exists and I have no error in my code file and all imports recognised by class.
Any Idea would be appreciated. Thanks.
OK, Geadle is f*king horrible although is powerful tool.
For your reference if you fall in same trouble this is my experience. Since I'm not sure my findings are absolutely right please correct me if I'm wrong.
I found that it is not possible to put your test folder under library projects. I wanted to have src/test/java for every project libraries and run my test cases like ./gradlew :booking-sdk:test. However, by moving this package to main application (in my case booking-app) and also moving related files from build.gradle of booking-sdk to build.gradle of booking-app I could see test case results.
I found exclude modules from dependencies don't work. The solution that I found is using configuration.
Like this:
configurations {
all*.exclude module: 'classworlds'
all*.exclude module: 'commons-logging'
all*.exclude module: 'httpclient'
all*.exclude module: 'maven-artifact'
all*.exclude module: 'maven-artifact-manager'
all*.exclude module: 'maven-error-diagnostics'
all*.exclude module: 'maven-model'
all*.exclude module: 'maven-project'
all*.exclude module: 'maven-settings'
all*.exclude module: 'plexus-container-default'
all*.exclude module: 'plexus-interpolation'
all*.exclude module: 'plexus-utils'
all*.exclude module: 'wagon-file'
all*.exclude module: 'wagon-http-lightweight'
all*.exclude module: 'wagon-provider-api'
}
Hope it helps.

Graphhopper 0.3 in Android studio not compiling: Dex Exception

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.
I've played a bit with it and here is the result. The good thing is that you don't have to recompile the source:
compile 'org.mapsforge:mapsforge-map-android:0.5.0-rc1'
compile ('com.graphhopper:graphhopper:0.3') {
exclude group: 'log4j', module: 'log4j'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'org.openstreetmap.osmosis', module: 'osmosis-osm-binary'
exclude group: 'org.apache.xmlgraphics', module: 'xmlgraphics-commons'
}
I had the same problem and thanks to answer by #Blehi I fixed it. The problem was mainly in the fact that the Android Studio doesn't correctly handle the exclude groups. So, for version 0.3 of graphhopper these are my dependencies:
dependencies {
compile files('libs/mapsforge-core-0.4.3.jar')
compile files('libs/mapsforge-map-0.4.3.jar')
compile files('libs/mapsforge-map-android-0.4.3.jar')
compile files('libs/mapsforge-map-reader-0.4.3.jar')
compile files('libs/slf4j-android-1.6.1-RC1.jar')
compile ('com.graphhopper:graphhopper:0.3') {
exclude group: 'log4j', module: 'log4j'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'org.openstreetmap.osmosis', module: 'osmosis-osm-binary'
exclude group: 'org.apache.xmlgraphics', module: 'xmlgraphics-commons'
}
}

Categories

Resources