Showing posts with label gradle. Show all posts
Showing posts with label gradle. Show all posts

9 April 2016

How to solve problem java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V gradle ?

PROBLEM:

When I practised TDD  I used added all libs manually(simply ask IntelliJ to take care of) , but I decided use gradle.I added  hamcrest ,junit (and Mockito ) and when I run gradle refresh ... I saw this:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
I couldn't figure out for a little bit why this happen and then I tried change order of  dependencies and that solved problem (I remembered ,I had similar problem in the past in other project).

SOLUTION:

Make sure  you put hamcrest dependencies before junit

dependencies {

    (...)   
    compile 'org.hamcrest:hamcrest-all:1.3'

    compile 'junit:junit:4.12'
    (...)

}

Done! Have an epic day/night fellow developer!

7 March 2015

How to solve problem with Failed to resolve: com.appbrain:appbrain-applift-sdk:+

Android Studio encourage us force to use Gradle.

If you didn't use Gradle before, then you will follow blindly, what AppBrain instructs you to setup project,but ....  If follow instruction from AppBrain and copy below part from "getting started"
repositories {
    maven {
        url 'http://swisscodemonkeys.github.io/appbrain-sdk/maven'
    }
}

dependencies {
    compile 'com.appbrain:appbrain-applift-sdk:+'
}

then it may sadly  throw an  error:
Failed to resolve: com.appbrain:appbrain-applift-sdk:+
Not good,but don't panic.. here is ..

SOLUTION:

Instead of what  AppBrain suggested,try code below:

buildscript {
    repositories {
        maven{
            url 'http://swisscodemonkeys.github.io/appbrain-sdk/maven'
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.appbrain:appbrain-applift-sdk:+'
    }
}

And You press sync now ...and it works!(It should at least :) ).

This example of  file build.gradle:

buildscript {
    repositories {
        maven{
            url 'http://swisscodemonkeys.github.io/appbrain-sdk/maven'
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.appbrain:appbrain-applift-sdk:+'
    }
}
apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.google.android.gms:play-services:6.5.87'

}

android {
    compileSdkVersion 21
    buildToolsVersion '20.0'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        instrumentTest.setRoot('tests')
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}


I hope,it helps you.Take care folks and have fun!

1 September 2014

How to solve problem with error:Error:Execution failed for task ':dexDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to run command: Android Studio\sdk\build-tools\android-4.4W\dx.bat

Solution for Android Studio 0.8.6, Gradle 1.12

ERROR:
Error:Execution failed for task ':dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Programs\Android Studio\sdk\build-tools\android-4.4W\dx.bat --dex --num-threads=4 --output D:\Dropbox\dsProjects\dsDiagnosticTools\build\intermediates\dex\debug
(...)
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
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)

STORY:
I love IntellIJ IDEA.It is best IDE. I was delighted, when Google decided to switch from most crappy Eclipse to awesome IntelliJ IDEA.
It makes my Android Studio development enjoyable.
My only problem is Gradle. I wanted to learn Gradle  3 times but I wasted lost of my free time and I didn't achieve anything as it cause lots of problems and hacks to make something to work.
When Google decided move Admob SDK to Google Play Services ,I decided to try use Gradle in Android Studio and ... so far is total disaster.
Anyway...

SOLUTION:

I saw this error in all my android projects that was created in IntelliJ IDEA and used  android-support-v4 library that was imported to libs folder.
Simply delete android-support-v4 library from libs folder and ...It will works.

(Problem appear all project that was migrated to Gradle project)