I'm trying to build UI tests for my Android application in Android Studio. The problem is that I can't run them. I get the message: Execution failed for task 'app:prepareDebugAndroidTestDependencies' which I couldn't find what it's about. When I run my application, it starts perfectly, but when i try to run tests it shows the mentioned message. My build.gradle is lsited below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "ba.etf.pkks.eldaralmin.libraryapp"
minSdkVersion 15
targetSdkVersion 22
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/"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:support-v4:22.0.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
// Supports Android 4.0.3 and later (API level 15)
compile 'com.embarkmobile:zxing-android-minimal:2.0.0#aar'
// Supports Android 2.1 and later (API level 7), but not optimal for later Android versions.
// If you only plan on supporting Android 4.0.3 and up, you don't need to include this.
compile 'com.embarkmobile:zxing-android-legacy:2.0.0#aar'
// Convenience library to launch the scanning and encoding Activities.
// It automatically picks the best scanning library from the above two, depending on the
// Android version and what is available.
compile 'com.embarkmobile:zxing-android-integration:2.0.0#aar'
// Version 3.0.x of zxing core contains some code that is not compatible on Android 2.2 and earlier.
// This mostly affects encoding, but you should test if you plan to support these versions.
// Older versions e.g. 2.2 may also work if you need support for older Android versions.
compile 'com.google.zxing:core:3.0.1'
compile 'com.nononsenseapps:filepicker:2.1'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.google.code.gson:gson:1.7.2'
androidTestCompile 'com.android.support.test:runner:0.2'
androidTestCompile 'com.android.support.test:rules:0.2'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
}
My run/debug configurations for tests are in the image below:
http://pokit.org/get/?5b2509c64e5049b1b168c99b95313d5e.jpg
Can anyone help me to figure out where the problem is?
In your apps build.gradle add the following within android { }:
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
But why would lead to such?
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.
Related
I'm curious about this. I made an Android program using an earlier version of the Google Android Studio (I believe 2.3.x), and recently upgraded to a newer version that came out (3.1.2), however, when I tried to bring in the program directly to this version and fire it up, I got a lot of compile errors due to various things being out of date. I tried to fix these in a rather ad-hoc manner because I could not find any comprehensive information despite much googling detailing how to properly migrate a project and it seemed to work (and so I can't post what they were), but now it seems to have broken again (perhaps because of another automatic upgrade) and I am getting this, for which searching has not yielded anything helpful:
Could not find recyclerview-v7.jar (com.android.support:recyclerview-v7:27.1.1).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/recyclerview-v7/27.1.1/recyclerview-v7-27.1.1.jar
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
Yet I go to the "Android SDK Manager" (that shows as a link in the output) and it says the relevant package is both installed and apparently at its latest version (since it does not say any updates are available). Moreover I was not aware I was even using the control "recyclerview" in the program, so I am rather puzzled as to why I am getting this error and I suspect it is because I did the migration wrong (not surprising due to the frustrating lack of information). I still have the project original from the earlier version so I could repeat it, but I'd like to then know how to do it correctly as I suspect this is resulting from the fact that I don't really know what I'm doing - and so what is the way to do that?
FWIW, the present project build.gradle is
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "sg.simetricclock.kumari.metricclock"
minSdkVersion 18
targetSdkVersion 25
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testCompile 'junit:junit:4.12'
}
repositories {
maven {
url 'https://maven.google.com'
}
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:2.0.0-alpha1'
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:+'
}
First Change Your Compile statement to Implimentation and Then Change Your Targeted SDK Version 28 And Then SYNC Your Project. I Hope After That You Will Not get Error
After adding Android Facebook SDK dependencies
compile 'com.facebook.android:facebook-android-sdk:4.21.0'
I'm getting error in
compile 'com.android.support:appcompat-v7:25.3.1'
But Project is running fine.
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 25.3.1, 25.0.0. Examples include
com.android.support:animated-vector-drawable:25.3.1 and
com.android.support:cardview-v7:25.0.0 less... (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that
are incompatible, or can lead to bugs. One such incompatibility is
compiling with a version of the Android support libraries that is not
the latest version (or in particular, a version lower than your
targetSdkVersion.)
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
repositories {
mavenCentral()
}
defaultConfig {
applicationId "sujeet.raj.com"
minSdkVersion 15
targetSdkVersion 25
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'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.21.0'
}
This problem occurs due to different version of dependency files get downloaded.
Explicitly put this as well in gradle file and sync again.
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
Under this directory you can find these libraries getting downloaded
Project Files/Your project/.idea/libraries
Don't ask me why but this solved it for me:
android {
/.../
configurations.all {
resolutionStrategy.force 'com.android.support:cardview-v7:27.1.0'
resolutionStrategy.force 'com.android.support:animated-verctor-drawable:27.1.0'
resolutionStrategy.force 'com.android.support:customtabs:27.1.0'
resolutionStrategy.force 'com.google.android.gms:play-services-base:12.0.1'
resolutionStrategy.force 'com.google.android.gms:play-services-auth:12.0.1'
}
}
You can solve this with one of the following solutions: original here
Run a Gradle dependency report to see what your full tree of dependencies is. From there, you will see which one of your libraries is asking for a different version of the Android Support libraries. For whatever it is asking for, you can ask for it directly with the 25.2.0 version, or use Gradle's other conflict resolution approaches to arrange to get the same version.
Run:
./gradlew -q dependencies <module-name>:dependencies --configuration compile
Example:
./gradlew -q dependencies app:dependencies --configuration compile
For me, the error disappeared after removing com.google.android.gms:play-services:10.2.0
And only include com.google.android.gms:play-services-location:10.2.0 and com.google.android.gms:play-services-maps:10.2.0 as they are the only two play services that I use.
I think the gms:play-services depend on some old components of the support library, so we need to add them explicitly ourselves.
Maybe I am too late for this, but well, trying to be helpful here... this is how I solve it.
open
project/your project/.idea/libraries
then head to facebook sdk and you can see this
library name="facebook-android-sdk-4.22.1"
use the number "4.22.1" into the one in build.gradle
this is how I do it, I am too a beginner myself.
Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here
My build takes to long in Android Studio, more than 2 minutes, sometimes 3'. I tried some methods explained in StackOverflow to accelerate the build time, but it didn't solve my problem.
My build.gradle code for app module is the following:
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' }
}
// Adding The GIT SHA to Crashlytics crash reporting
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.moymer"
minSdkVersion 11
targetSdkVersion 22
multiDexEnabled true
versionCode 5
versionName "2.0.0"
buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:design:22.2.0'
compile 'com.github.nirhart:parallaxscroll:1.0'
compile 'com.android.support:multidex:1.0.0'
compile('com.crashlytics.sdk.android:crashlytics:2.4.0#aar') {
transitive = true;
}
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
compile 'com.android.support:recyclerview-v7:23+'
compile 'com.squareup:otto:1.3.8'
compile 'com.android.support:percent:23.0.0'
compile 'com.jakewharton.timber:timber:3.1.0'
compile project(':androidffmpeglibrary')
}
My gradle.properties file is the following:
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
You have 11+ dependencies and an extra plugin. At least one (androidffmpeglibrary) would appear to involve the NDK. That is not going to be fast, particularly depending on your build hardware.
If you want a faster build, get rid of some of that junk. For example, there have been finer-grained Play Services SDK dependencies for over a year; use only the pieces that you need, rather than the "everything but the kitchen sink" play-services artifact. That, in turn, might allow you to dump multidex, as you might fall back below the 64K DEX method reference limit.
The Android Tools team is working on improving the build speed, which will show up in newer versions of the Android Plugin for Gradle. That must be in your top-level build.gradle file, as I don't see where you are including that here. Make sure you are on the latest one, and keep updating it as new editions come out.
As CommonsWare depicted, having a lot of dependencies does slow down the overall build. As of now, you can start using Android Studio 2.0 which has the instant run feature.
Instant run cuts down the build time by a big factor because it only pushes the small changes that are not. Whatever changes you do in the code, are first classified into three categories - hot swap, warm swap and cold swap. Lesser the load, warmer the swap, quicker the build-time.
Big structural changes like changing annotations, static fields etc come into cold swap. Changes in the manifest file also comes in the cold swap. You can check the full list here.
The good news is most of the small changes fall in the hot swap and these changes are quickly pushed in the running application as soon as you press the run button. The relevant activity restarts, and you can see your changes in a few seconds.
Stable version of Android Studio 2.0 is released and you can download it from this link. It has this instant run feature. Hope this helps.
Android SDK Manager notified me this morning that there was a new Google Play Services release to download: revision 18. So how do I find the corresponding long version number to put in my build.gradle file? All my test devices are running version 5.0.84, so I tried updating
compile 'com.google.android.gms:play-services:4.4.52'
to
compile 'com.google.android.gms:play-services:5.0.84'
But that resulted in an error:
Gradle 'MyApp' project refresh failed: Could not find com.google.android.gms:play-services:5.0.84. Required by: {my app} Gradle settings
I'm running Android Studio 0.5.2 and building for API19 (I haven't upgraded to Android L/API20 yet): maybe that's the issue? But in general, how do you match a revision number shown in SDK Manager (e.g. 18) with a version code for build.gradle (e.g. 5.0.84)?
Here's my full build.gradle in case it helps:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
// Avoid "Duplicate files copied in APK" errors when using Jackson
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
dependencies {
// Was "compile 'com.android.support:support-v4:+'" but this caused build errors when L SDK released
compile 'com.android.support:support-v4:19.1.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
// Support for Google Cloud Messaging
// Was "compile 'com.android.support:appcompat-v7:+'" but this caused build errors when L SDK released
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:5.0.84'
// Jackson
compile 'com.fasterxml.jackson.core:jackson-core:2.3.3'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.3.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.3'
}
OK, I haven't quite managed to find a mapping of one to the other, but I've managed the next best thing which is to see a list of Play Services long version numbers installed on my development machine.
For Windows, it's in [android-sdk]\extras\google\m2repository\com\google\android\gms\play-services
(where [android-sdk] is the path to your Android SDK folder).
On a Mac, it's inside the Android.app package: browse to sdk/extras/google/m2repository/com/google/android/gms/play-services
The latest version on my machine was 5.0.77 (not 5.0.84), and putting that in my build.gradle worked fine.
Here's the kind of thing you should see at that location:
What I did in my project was download google play service and open the project structure > dependencies tab and click on the plus button and choose google play service. I dont have to care about the version anymore