Dependency httpclient - AndroidStudio - android

my run and debug buttons in my Android Studio are disabled.
I have seen many answers about this but the solution are not correct in my case.
This is my error in my gradle console:
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug 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.1 is ignored for release 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
Incremental java compilation is an incubating feature.
This is my build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "myProjectPackageName"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.0'
// Zxing libraries Scan
compile 'com.embarkmobile:zxing-android-minimal:2.0.0#aar'
compile 'com.embarkmobile:zxing-android-integration:2.0.0#aar'
compile 'com.google.zxing:core:3.0.1'
//Google api books
compile 'com.google.apis:google-api-services-books:v1-rev80-1.21.0'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
// Dependency for Google Sign-In
compile 'com.google.android.gms:play-services-plus:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
//Facebook Login
compile 'com.facebook.android:facebook-android-sdk:4.13.2'
// Dependency for Firebase
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-storage:9.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
}
apply plugin: 'com.google.gms.google-services'
Thanks a lot for the help

You need to exclude dependencies inside build.gradle files.
compile('com.google.apis:google-api-services-books:v1-rev80-1.21.0') {
exclude module: 'httpclient'
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
Try to exclude it from all configurations.
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}
Restart studio and then check again. Or either select app module from drop down menu beside Run button.

Related

"Unable to merge dex" error when update to Android Studio 3.0?

This error appears after I updated to Android Studio 3.0. I tried many ways in many similar questions, but nothing works.
Here is the error:
I realized that when I remove the library 'com.google.android.gms:play-services-maps:11.4.2' my project build successful. But I need this library in my project, anyone knows how to deal with this problem?
My complete build.gradle.
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
google()
}
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "vn.com.ttsoft.dhd"
minSdkVersion 21
targetSdkVersion 25
versionCode 14
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// Disable fabric build ID generation for debug builds
ext.enableCrashlytics = false
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile files('libs/android-async-http-1.4.4.jar')
compile files('libs/google-play-services.jar')
compile files('libs/gson-2.3.1.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
compile 'com.github.pavlospt:roundedletterview:1.2'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.google.android.gms:play-services-maps:11.4.2'
compile 'me.tatarka.support:jobscheduler:0.1.1'
compile 'com.evernote:android-job:1.1.8'
testCompile 'junit:junit:4.12'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
}
I am putting the gradle file you can use it may help you
apply plugin: 'com.android.application'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "vn.com.ttsoft.dhd"
minSdkVersion 14
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// Disable fabric build ID generation for debug builds
ext.enableCrashlytics = false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile files('libs/android-async-http-1.4.4.jar')
compile files('libs/google-play-services.jar')
compile files('libs/gson-2.3.1.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true;
}
compile 'com.github.pavlospt:roundedletterview:1.2'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.android.support:support-v4:25.3.0'
compile 'me.tatarka.support:jobscheduler:0.1.1'
compile 'com.evernote:android-job:1.1.8'
testCompile 'junit:junit:4.12'
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
}
apply plugin: 'io.fabric'
and another project gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'io.fabric.tools:gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
I was also facing the same issue and I think something is wrong with google play services dependencies so I got it resolved by adding all below google play services dependencies :
compile 'com.google.android.gms:play-services-base:11.4.2'
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile 'com.google.firebase:firebase-core:11.4.2'
compile 'com.google.firebase:firebase-messaging:11.4.2'
compile 'com.google.android.gms:play-services-gcm:11.4.2'
compile 'com.google.android.gms:play-services-location:11.4.2'
compile 'com.google.android.gms:play-services-maps:11.4.2'
compile 'com.google.android.gms:play-services-places:11.4.2'
I had a similar problem with the 'Multiple Dex' build error after upgrading to AS 3.0 / Gradle 3.0.0.
I found that the invalidate caches and restart, clean project, and minifyEnabled "solutions" were all red herrings.
I struggled with this for a few hours then found out what was causing my problem.
I was compiling Picasso, GSON and SQLiteAssetHelper using the statements
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'
...but I also had the sqliteassethelper, GSON and Picasso .jar files being compiled from my \libs folder.
compile fileTree(include: ['*.jar'], dir: 'libs')
Hence the duplicates.
Yes - pretty obvious but sometimes you can't see the wood for the trees!
I hope this helps someone.
(Final Note: compile command is deprecated in Gradle 3.0.0, therefore you might wish to change the above commands from compile to implementation)
What version of Play Services do you load from file? I guess that's an issue, you try to load whole play services and partial play-services-maps together. Also that explains the fact that, when you remove maps, everything works fine.
take a look on this link for selective compiling play services APIs, this will also help to reduce method count
https://developers.google.com/android/guides/setup
To somebody who is using android-async-http and had tried enable DEX, invalidate cache, delete .gradle files and check duplicate import/version:
I have some conflict in org.apache and android-async-http packages,
after I change i.e. org.apache.http.Header
to cz.msebera.android.httpclient.Header, my problem solved.
{
useLibrary 'org.apache.http.legacy' // avoid this
}
dependencies {
compile files('libs/android-async-http-1.4.4.jar') // only keep this one
}

plugin with id 'com.android.application' not found Android studio

I'm getting "plugin with id 'com.android.application' not found" error in my app after adding one library project in my app, but now I removed that library project from my app but still same error is persist. I googled a lot and tried almost all the solution but yet unable to resolve this error. For more information, please check the following "app module's build.gradle"--
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.lemo.wikinews"
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile project(':easyAndroidAnimationsLibrary')
compile project(':liveSdk')
compile project(':main')
compile project(':zbarSample')
compile project(':stickyHeaderLibrary')
compile project(':starBar')
compile project(':facebookSDK')
compile project(':library')
compile project(':ffmpeg4android_lib')
compile project(':socialNetworkingLib')
compile 'com.google.android.gms:play-services:9.6.1'
compile files('libs/nmdp_speech_kit.jar')
compile files('libs/AndroidSwipeLayout-v1.1.8.jar')
compile group: 'commons-logging', name: 'commons-logging', version: '1.2'
compile files('libs/CWAC-SackOfViewsAdapter.jar')
compile files('libs/devsmartandroid.jar')
compile group: 'com.google.api-client', name: 'google-api-client', version: '1.6.0-beta'
compile files('libs/google-api-services--v1-1.3.0-beta.jar')
compile files('libs/httpclient-4.4.jar')
compile group: 'oauth.signpost', name: 'signpost-commonshttp4', version: '1.2'
compile group: 'oauth.signpost', name: 'signpost-core', version: '1.2.1.2'
compile group: 'oauth.signpost', name: 'signpost-jetty6', version: '1.2.1.1'
compile 'com.android.support:multidex:1.0.0'
'4.4-alpha1'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpmime:4.3.5'
version: '4.3.5.1'
compile('org.apache.httpcomponents:httpmime:4.3')
{
exclude module: "httpclient"
}
}
And below is my top level 'builg.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:1.5.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Also please let me know if I can provide more information to understand the problem. Thank you.
Bellow is my way to resolve a import problem,the project use a old studio plugin. Forgive my poor English.
Edit your top moudle build.gradle ,edit gradle plugin to your studio's have . then maybe show this,
Error:Minimum supported Gradle version is 2.14.1. Current version is 2.2.1. If using the gradle wrapper, try editing the distributionUrl in C:\Users\Administrator\Desktop\SelectCityDome\gradle\wrapper\gradle-wrapper.properties to gradle-2.14.1-all.zip
Fix Gradle wrapper and re-import project
Gradle settings follow the step fix it.
JUST SEE THIS PICTURE

gradle dependency version conflict

I have the following dependency script:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.asdf.asdf"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField 'String', 'YOUTUBE_API_KEY', YoutubeApiKey
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0-beta-2'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:0.13.2'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
javanano {
option 'ignore_services=true'
}
}
task.plugins {
grpc {
option 'nano=true'
}
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'
compile 'com.android.support:customtabs:23.2.1'
compile 'com.google.apis:google-api-services-youtube:v3-rev164-1.21.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'io.grpc:grpc-protobuf-nano:0.13.2'
compile 'io.grpc:grpc-okhttp:0.13.2'
compile 'io.grpc:grpc-stub:0.13.2'
compile 'com.google.guava:guava:18.0'
}
Though both the youtube library and the grpc library are dependent on the google guava library, they're reliant on different versions causing a conflict. Youtube is dependent on com.google.guava:guava-jdk5:17.0 and grpc on com.google.guava:guava:18.0.(Notice the artifact difference, if that is possibly relevant) The problem is grpc ends up trying to locate a method defined in youtube's version of guava when it only exists in in its own version of the dependency. How do I resolve this?
ERROR Message
FATAL EXCEPTION: SyncAdapterThread-1
Process: com.asdf.asdf, PID: 4025
java.lang.NoSuchMethodError: No static method directExecutor()Ljava/util/concurrent/Executor; in class Lcom/google/common/util/concurrent/MoreExecutors; or its super classes (declaration of 'com.google.common.util.concurrent.MoreExecutors' appears in /data/data/com.fentale.dalol/files/instant-run/dex/slice-guava-jdk5-17.0_a8ada10dcaf113cb6e3b4d3e5b46975833f8ae8f-classes.dex)
at io.grpc.internal.ClientCallImpl.<init>(ClientCallImpl.java:100)
at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:320)
at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:299)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:130)
at com.fentale.dalol.nano.DalolGrpc$DalolBlockingStub.topPosts(DalolGrpc.java:365)
The method "directExecutor" is defined in guava-v18, but grpc tries to access it from the guava-jdk5.
I would try to exclude guava-jdk5 by using
exclude module: 'guava-jdk5'
in your dependencies.
The problem is that version conflicts cannot be detected if the artifacts have different names (like here, guava and guava-jdk5). Then it can happen that the wrong classes are loaded because both jars are included.
Specify the guava version manually
compile 'com.google.guava:guava:18.0.0'
So your dependencies will be the following
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.google.apis:google-api-services-youtube:v3-rev164-1.21.0'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'io.grpc:grpc-protobuf-nano:0.13.2'
compile 'com.google.guava:guava:18.0.0'
}
That way you will force guava v18 to be used.
Or in the top level gradle you can use
configurations.all {
resolutionStrategy.force 'com.google.guava:guava:18.0.0'
}
You have to edit project level build.gradle you have to
exclude module: 'guava-jdk5'
inside dependencies. Please check attached screenshot for more details
If you are using firebase plugins add
classpath ('com.google.firebase:firebase-plugins:1.1.0') {
exclude group: 'com.google.guava', module: 'guava-jdk5'
}

Android Studio not recognizes Espresso imports

I am trying to write a test case using Espresso.
I am using Android Studio 1.5.1 (Stable channel), Gradle plugin 1.5, Gradle 2.7.
The problem is that Android Studio doesn't recognize any import related to Espresso (and not only)
So, I tried to clean the project, rebuild, invalidate cache and restart, but nothing.
I added these dependencies in my app module:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
I added the runner in defaultConfig:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
I created the test suite class under androidTest folder:
What am I doing wrong please?
UPDATE
Here is (part) of my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 5
versionName '1.4'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
//my build type configs
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
disable 'InvalidPackage'
}
dexOptions {
incremental true
preDexLibraries = false
jumboMode = false
javaMaxHeapSize "2g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.viewpagerindicator:library:2.4.1'
compile project(':libraries:RITracking')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.google.code.gson:gson:2.5'
compile 'com.google.android.gms:play-services-plus:8.4.0'
compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'de.greenrobot:eventbus:2.4.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.7.2'
compile 'com.facebook.android:facebook-android-sdk:4.9.0'
compile 'com.cocosw:bottomsheet:1.2.0#aar' //Bottom Sheet that implement material design used for ShareDialog
compile 'com.github.bumptech.glide:glide:3.6.1' //Glide library
compile 'com.googlecode.libphonenumber:libphonenumber:7.2.3' //Library used to parse/merge phones number to E164 format
compile 'me.leolin:ShortcutBadger:1.1.3#aar' //Used to show badge on application icon, library is optimized to work on most of devices
compile 'com.stripe:stripe-android:1.0.3' //Stripe payment gateway, used to integrate credit card payment
provided 'org.projectlombok:lombok:1.16.6'
apt "org.projectlombok:lombok:1.16.6"
compile 'com.jakewharton:butterknife:7.0.1'
apt "com.jakewharton:butterknife:7.0.1"
compile 'de.greenrobot:greendao:2.1.0' //Green Dao library is ORM implementation for Android SQL lite
compile files('libs/libammsdk.jar')
compile files('libs/apptimize-android-2.9.1.jar')
testCompile 'junit:junit:4.12'
androidTestCompile "com.android.support:support-annotations:23.1.1"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
}
Perhaps your Build Variant is on "release" mode. you have to change it to debug.
UPDATE 30/11/2016
Just like #Jaymes Bearden said in comment below.
Use testBuildType. Android Studio 2.2, gradle 2.2.2
android {
testBuildType "yourBuildType"
}
OLD ANSWER
I found not solution but some source of problem. In my project I have, a lot of BuildTypes. Especially more than one debug build.
Everything works only in default debug build type. I think that this is some internal Android Studio error.
My AS version - 2.1
You need to use debug build variant. With other build options espresso will not be recongnised.
I'm pretty sure, that you're something missing in your configuration. compare your build.gradle with mine below
def ASVersion = '23.1.1'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
dataBinding {
enabled = true
}
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.piotr.awesome"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile "com.android.support:support-annotations:$ASVersion"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
androidTestCompile 'com.android.support.test:runner:0.4.1'
compile "com.android.support:appcompat-v7:$ASVersion"
compile "com.android.support:support-v4:$ASVersion"
compile "com.android.support:design:$ASVersion"
}
Also choose File -> Invalidate cache/restart and try first option.
Hope it help
In Android Studio:
Open Run menu -> Edit Configurations -
Add a new Android Tests configuration
- Choose a module
Add a specific instrumentation runner:
android.support.test.runner.AndroidJUnitRunner
Also try to update the Android Support Library from SDK Manager.
Hope this helped.
You can also try this topic: link
Good luck!
I had the same problem. Here is how i fixed it:
Go the src directory of your project in finder/explorer, select the directory containing your test.
Rename the directory with the prefix "androidTest" followed by the name of the flavor you are trying to test.
Open Android Studio, Invalidate Caches and Restart.

Generate JAR from Android Library with Dependencies, NoClassDefFound

I have an Android Library module that I need to ship as a JAR. The library has no resources, so I think it's valid to extract the classes.jar from the generated aar file. However, the classes in my library have remote dependencies, so when I try to import classes.jar and instantiate a class defined there, I get a NoClassDefFound problem.
I have read about using the transitive keyword (How do I ship an Android Library (aar) with remote dependencies (gradle)?), but I want to allow users to just drop in JARs to accommodate those not using gradle, so my problem is slightly different.
I can browse to my local gradle cache and find all my library's dependencies (as JARs), so I could pull all these and have users drop them in, but it seems inelegant. Is there a way I can either a) have the jars of the remote dependencies output to a folder in my build directory at library compile time or b) have gradle export all transitive dependencies into my aar?
My gradle.build:
apply plugin: 'android-library'
apply plugin: 'maven'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
// my two cloud endpoints libraries
compile ([group: 'com.appspot.super_endpoint_999', name: 'hello', version: 'v1-1.18.0-rc-SNAPSHOT'])
compile files('libs/advancedhello-v1-1.19.0-SNAPSHOT.jar')
compile 'com.google.android.gms:play-services:4.2.+'
compile('com.google.api-client:google-api-client:1.17.0-rc') {
exclude(group: 'xpp3', module: 'xpp3')
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
exclude(group: 'junit', module: 'junit')
exclude(group: 'com.google.android', module: 'android')
}
compile('com.google.api-client:google-api-client-android:1.17.0-rc') {
exclude(group: 'com.google.android.google-play-services', module: 'google-play-services')
}
compile('com.google.http-client:google-http-client-android:1.17.0-rc') {
exclude(group: 'com.google.android', module: 'android')
}
compile 'com.google.guava:guava:14.0.+'
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

Categories

Resources