"Cannot determine expansion folder" when running android Instrumentation tests - java

We want to set up instrumentation tests for our app, that also has 2 flavors. We have successfully set up Android Studio to run instrumented tests directly from the IDE, but trying to run instrumented tests from the command line via 'gradle connectedCheck' always results in the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDevelopmentDebugAndroidTestJavaResources'.
> Cannot determine expansion folder for /Users/james/Development/AndroidProjects/parkinsons11/app/build/intermediates/packagedJarsJavaResources/androidTest/development/debug/junit-4.12.jar936209038/LICENSE-junit.txt with folders
Our test app, which also has two flavours and is set up for instrumented tests, runs both from the IDE and from command line without incident.
Here is our gradle file from our main project:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.app.ourapp"
minSdkVersion 16
versionCode 11
versionName "1.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets',
'src/main/assets/font']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
live {
versionName "1.1 live"
applicationId "com.app.ourapp.live"
}
development {
versionName '1.1 development'
applicationId "com.app.ourapp.development"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library:datetimepicker')
compile project(':library:tools')
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'org.quanqi:mpandroidchart:1.7.+'
compile 'commons-io:commons-io:2.+'
compile 'joda-time:joda-time:2.+'
compile 'com.microsoft.azure.android:azure-storage-android:0.4.+'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:${robolectricVersion}"
testCompile "org.mockito:mockito-core:1.+"
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:1.+"
}
And here is our gradle.build from our test app (which works):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.test.picroft.instrumentationtestapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
newFlavour {
applicationId "com.test.picroft.instrumentationtestapp.newflavor"
}
oldFlavour {
applicationId "com.test.picroft.instrumentationtestapp.oldflavor"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.+"
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:1.+"
}
I'm at a loss as to where I'm going wrong. I've compared the directory structure from both apps and there's no meaningful difference. Here's a rough outline of our main project's structure:
src
-androidTest
--java
---*
-live
--res
---layout
---values
-main
--java
---*
-test
--java
---*
I'm totally confused why instrumented tests on one app works fine both in IDE and in command line, while the other refuses to work via command line.

It seems the issue resolved itself. I believe it was some kind of corruption of the build state that was fixed through an invalidate/restart.
Its also worth pointing out that when you switch build flavours in the Build Variation panel, its worth it to wait until Android Studio finishes synchronizing and is not performing any tasks before doing a build or run. I've found that when I was hitting build or run and Android Studio hadn't finished switching the build flavour, it caused all manner of unpredictable issues.

I think the problem might be that you haven't defined a default instrumentation runner, as mentioned here. You should include this in your build.gradle file
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}

Related

Getting error to generate Signed Apk from Android Studio

While generating signed apk from Android Studio getting an error. A few days later all works good, while from last 2 days I am facing problem to generate signed apk.
Error is:
FAILURE: Build failed with an exception. What went wrong: A problem
was found with the configuration of task ':app:packageRelease'. File
'/media/user86/data/MySIPonline/app/build/intermediates/res/resources-release-stripped.ap_'
specified for property 'resourceFile' does not exist.
I've checked that folder and release-stripped.ap file is present in it. I am not able to figure out the error.
Here is build.gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.xxxxxxxx"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'de.petendi:ethereum-android-lib:0.2.1'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
testCompile 'org.ethereum:ethereumj-core:1.2.0-RELEASE'
testCompile 'commons-io:commons-io:2.4'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy {
force 'com.fasterxml.jackson.core:jackson-databind:2.7.1-1'
force 'com.fasterxml.jackson.core:jackson-annotations:2.7.0'
force 'com.fasterxml.jackson.core:jackson-core:2.7.1'
}
}
Here is link for pro-guard file - https://gist.github.com/Sanwal13/b667326812b87702c86fa02870b28240
Please help and thank you very much for your time and assistance in this matter.

Lambda expression in Android Library Module not working

I had an android app module which used jdk 8 and enabled Jack Options. Then I convert it to an Android Library module. And then I have to remove Jack Options from build gradle. And now the Lambda expression gives me below error when I try to build the AAR file.
Error:(59, 25) error: cannot find symbol method metafactory(Lookup,String,MethodType,MethodType,MethodHandle,MethodType)
The code giving this error is,
Runnable r= () -> {
appManager.startApp(definition,identifier);
};
My Build Gradle is
Apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
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 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
What is the reason for this problem?
On my machine I was missing the file $ANDROID_SDK/build-tools/28.0.3/core-lambda-stubs.jar, so I had to reinstall version 28.0.3 of the build tools using the Android Studio SDK manager.
(I had to check 'Show package details' to see the full list of build-tools versions)
You forgot to apply the retro lambda plugin.
Add this line to your build.gradle file:
apply plugin: 'me.tatarka.retrolambda'

"Failed to resolve: com.android.support:support-v4:26.0.0" and other similar errors on Gradle sync [duplicate]

This question already has answers here:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
(26 answers)
Closed 5 years ago.
I have just created a new Android Studio project for both Android Mobile and wear. The initial gradle build failed because I am getting several errors-
Error: Failed to resolve: com.android.support:support-v4:26.0.0
Error: Failed to resolve: com.android.support:percent:26.0.0
Error: Failed to resolve: com.android.support:recyclerview-v7:26.0.0
Error: Failed to resolve: com.android.support:support-annotations:26.0.0
With each error, I am given the option to Install repository and sync project, but nothing happens when I click on it. I have spent several hours trying to find why I am getting these errors, but I can't find any solutions. Does anybody know how to fix these very frustrating errors? Thank you!
build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (mobile)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.androidweartest"
minSdkVersion 23
targetSdkVersion 26
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'
})
wearApp project(':wear')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:appcompat-v7:26+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.android.support:support-core-utils:26+"
testCompile 'junit:junit:4.12'
}
build.gradle (wear)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.androidweartest"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile "com.android.support:support-core-utils:26+"
}
I am sure that my version of Android Studio is updated, and all support repositories and APIs are installed.
I don't have an Android wear project, but I had the same problem when I wanted to upgrade the Support Library version for an existing project to 26.0.0. Since 26.0.0 the support libraries are available through Google's Maven repository. So I had to add the repository to my build. gradle file.
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Check out https://developer.android.com/topic/libraries/support-library/setup.html for more details.
The following worked for me:
In the Application build.gradle considered to add following:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
in the Module build.gradle:
compileSdkVersion 26
buildToolsVersion "26.0.1"
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:support-compat:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:26.0.1'
compile 'com.android.support:support-vector-drawable:26.0.1'
compile 'com.android.support:animated-vector-drawable:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:percent:26.0.1'
compile 'com.android.support:wear:26.0.1'
compile 'com.google.android.support:wearable:2.0.4'
provided 'com.google.android.wearable:wearable:2.0.4'
}
Either change your build tool version from 26.0.1 to 26.0.0 or you can replace 26.0.0 by 26.+ like below.
compile 'com.android.support:support-v4:26.0.0'
to
compile 'com.android.support:support-v4:26.+"
Do same with all...
Hope it helps.
Happy Coding! ^_^
For now, I fixed this with changing in the wear build.gradle:
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
It seems like the problem is com.google.android.support:wearable:2.0.4. With that, Using 26.0.1 build tools compiles fine. I haven't gone any further with this but it looks like a dependency problem related to a repository although that is really just a guess from the error messages.
Add the following dependencies in your app/build.gradle.
repositories {
maven { url 'https://maven.fabric.io/public' }
maven{url 'https://maven.google.com'}
}
Replace this:
compile 'com.android.support:recyclerview-v7:26.0.0'
With this
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
Do same with all
Update - new version released
compile 'com.android.support:recyclerview-v7:26.1.0'
Add following dependency in your gradle
Replace
compile 'com.android.support:support-v4:26.0.0'
with
compile 'com.android.support:support-v4:25.0.0'
and Replace
compile 'com.android.support:appcompat-v7:26+'
with
compile 'com.android.support:appcompat-v7:25.0.0'
The reason that my project was giving me these errors was because I created the project for Android Platform 26. However, Wear currently doesn't support 26, and it is essential to change the target and compile SDK versions to 25 in the wear module of build.gradle.
Link to Android Developers documentation - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone
build.gradle (wear)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.georgeberdovskiy.findmyphone"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'
}
apply plugin: 'com.google.gms.google-services'
I only needed to change the compile and target SDK versions to 25 in the wear module. I left them as 26 for the mobile module.
This one worked for me
allprojects {
repositories {
jcenter()
google()
}
}
google() does the magic with the following configuration
Studio version : 3.0 beta 2
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
I meet this problem, changing the build tool/ sdk version didn't work, clearly write compile version didn't work, off line build didn't work.
Finally I just change wearable version, and this problem gone.
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
to
provided 'com.google.android.wearable:wearable:2.0.2'
compile 'com.google.android.support:wearable:2.0.2'
By the way, I used offline building now because it is really fast when I check this issue.

Adding gradle dependency for pd for android in my gradle file does nothing

I am trying to import pd-for-android into my project as a gradle dependancy as per the instructions on pd-for-android's githubpage (i.e. make sure jcenter() is in the top level repositories in build.gradle, then add compile 'org.puredata.android:pd-core:1.0.1' to your dependancies in the app build.gradle)
I followed these instructions but I cannot see the library downloading into my external libraries. Is there something else i need to do in order to get this working?
here's my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "21.1.2"
defaultConfig {
...
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
...
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.2.1'
compile 'io.reactivex:rxjava:+'
compile 'io.reactivex:rxandroid:+'
compile 'org.puredata.android:pd-core:1.0.1'
}
Check if It's inside app\build\intermediates\exploded-aar\
If you have there the library, you shouldn't have any problem to use it.
Does it show up correctly as dependency when you click File->Project Structure and then on the dependencies tab in Android Studio?
if not, have you tried to add it there via the "+" Button?

Not able to add dependecy in gradle(Android Studio)

I am trying to add this dependency https://github.com/hoang8f/android-flat-button in to my android studio project and I am getting
Error:(26, 13) Failed to resolve: info.hoang8f:fbutton:1.0.5
I am able to add google play services dependency easily without any problems.
Below is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.planner"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'info.hoang8f:fbutton:1.0.5'
}
Solutions tried:- 1.)Gradle is working in online mode not offline.
2.)Cleaned and builded/rebuilded the project.
3.) Changed to
repositories {
mavenCentral()
}
in my root gradle file
4.) Tools->android->Sync Project with gradle files
Still no luck in making it work.
P.S.:- Not that it effects the questions, I faced the same problem while trying to add parse sdk via gradle, so I added the jar file independently.
add
repositories {
mavenCentral()
}
include android tag
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.planner"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
mavenCentral()
}}
Please try this. Add fbutton-1.0.5.aar file into your lib folder.
repositories {
flatDir {
dirs 'libs'
}
}
Add aar file into dependencies.
dependencies {
compile(name:'ARFile', ext:'aar')
}
Did you noticed how looks like build.gradle of a demo project?
https://github.com/hoang8f/android-flat-button/blob/master/demo/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 2
versionName "1.1"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
} }
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.larswerkman:HoloColorPicker:1.4'
compile fileTree(dir: 'libs', include: ['*.jar']) // compile project(':library')
compile 'info.hoang8f:fbutton:1.0.5'
}
Check if you're not missing something in your Gradle file or you put something wrong
EDIT: I've put whole your build.gradle file into my new project and it's work fine.
If rebuilding not help, create a new clean project and put this build.gradle. Tell me is it works with new project.
EDIT2:
In your project you have two build.gradle change the second one to
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}
allprojects {
repositories {
jcenter()
}
}
I had the same problem.
Invalidate cache and restart your android studio. Then sync gradle.
I cloned the project and used "demo" module to test the lib. The lib that you needed was downloaded successfully and this is expected, because it exists in the maven repo
The only point I noticed - probably you may have problems with gradle, because there's runProguard command, that is not used in gradle no more.
So you may just delete it or change to minifyEnabled false.
After doing this, demo project assembles successfully

Categories

Resources