I'm trying to follow the instructions on android testing step 7
https://codelabs.developers.google.com/codelabs/android-testing/#6
cloned the repo: git clone https://github.com/googlecodelabs/android-testing.git -b step-7
Even though I remove every reference to support-annotations, gradle gives the same error and stops:
Error:A problem occurred configuring project ':app'.
> Could not find support-annotations.jar (com.android.support:support-annotations:23.1.1).
Searched in the following locations: file:/C:/Users/UserName/Documents/android_studio/sdk/extras/android/m2repository/com/android/support/support-annotations/23.1.1/support-annotations-23.1.1.jar
build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.notes"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
debug {
// Run code coverage reports by default on debug builds.
// testCoverageEnabled = true
}
}
// If you need to add more flavors, consider using flavor dimensions.
productFlavors {
mock {
applicationIdSuffix = ".mock"
}
prod {
}
}
// Remove mockRelease as it's not needed.
android.variantFilter { variant ->
if(variant.buildType.name.equals('release')
&& variant.getFlavors().get(0).name.equals('mock')) {
variant.setIgnore(true);
}
}
// Always show the result of every unit test, even if it passes.
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
}
/*
Dependency versions are defined in the top level build.gradle file. This helps keeping track of
all versions in a single place. This improves readability and helps managing project complexity.
*/
dependencies {
// App's dependencies, including test
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
compile "com.google.guava:guava:$rootProject.guavaVersion"
compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"
compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"
// Dependencies for local unit tests
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"
// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"
// Espresso UI Testing dependencies.
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
}
/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
}
/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.compile.dependencies.each { compileDependency ->
println "Excluding compile dependency: ${compileDependency.getName()}"
configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
}
}
Try to install the dependencies:
echo y | android update sdk --no-ui --all --filter extra-google-google_play_services,extra-google-m2repository
gradle dependencies
update android support repository package
Related
In my Android project, I have needed to enable the dataBinding library in module level build.gradle as below, but it gives me the error in the image. How can resolve it?
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.nasser.studio.multipledeletelistview"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding{
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.codesgood:justifiedtextview:1.0.2'
}
Edit 1.
I've changed the project level build.gradle to add support-v4 library, but now it throws the following error:
repositories {
google()
jcenter()
configurations.all {
resolutionStrategy.force "com.android.support:support-v4:27.0.2"
}
}
one of your 3rd party libraries or sdk you use rely on support version 21.0.3. Either remove it or have resolutionStrategy in your Gradle.
configurations.all {
resolutionStrategy {
force ....
}
}
Try upgrade your android gradle plugin.
Add compile "com.android.support:support-v4:27.0.2" manually to your gradle file.
That should solve your problem.
That's not a Databinding error, It's just saying that all your support-related libraries should use the same version. For example look at my gradle file:
implementation "com.android.support:recyclerview-v7:$libraries.googleSupportVersion"
implementation "com.android.support:appcompat-v7:$libraries.googleSupportVersion"
implementation "com.android.support:support-v13:$libraries.googleSupportVersion"
implementation "com.android.support:design:$libraries.googleSupportVersion"
implementation "com.android.support:cardview-v7:$libraries.googleSupportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
My support library version being:
ext.libraries = [
...
googleSupportVersion : '27.1.1',
...
]
Your issue seems to be that compile 'com.codesgood:justifiedtextview:1.0.2' internally is using the support library with a version different than yours. However your version is totally updated I wouldn't downgrade it just to have it match with the other, in any case you could just add a:
allprojects {
configurations.all {
resolutionStrategy.force "com.android.support:support-v4:27.0.2"
}
}
In your project gradle. You could also run gradlew app:dependencies in the Android Studio console, do a Ctrl+F on the output, search for that com.android.support:support-v4:27.0.2 and figure out from where is coming. (You only have one dependency for what I see, so there's not much science from where IT should be coming)
Let me know if this works for you.
I got these multiple errors while doing the Module 7. Writing UI tests with Espresso of the Android Testing Code lab.
I am using Android Studio 3.0 and these are the errors I am getting when I try to run the test:
Gradle messages:
Information:Gradle tasks [:app:assembleProdDebug, :app:assembleProdDebugAndroidTest]
/Users/sudo/Projects/Android/Android-Codelabs/android-testing/app/src/androidTest/java/com/example/android/testing/notes/notes/AppNavigationTest.java
Error:(29, 33) error: package android.support.v4.widget does not exist
Error:(61, 28) error: cannot access AppCompatActivity
class file for android.support.v7.app.AppCompatActivity not found
Error:(62, 13) error: cannot infer type arguments for ActivityTestRule<>
/Users/sudo/Projects/Android/Android-Codelabs/android-testing/app/src/androidTest/java/com/example/android/testing/notes/notes/NotesScreenTest.java
Error:(31, 33) error: package android.support.v7.widget does not exist
Error:(47, 37) error: package com.google.common.base does not exist
Error:(47, 1) error: static import only from classes and interfaces
Error:(71, 9) error: cannot find symbol method checkArgument(boolean,String)
Error:(76, 58) error: cannot find symbol class RecyclerView
Error:(95, 29) error: type argument NotesActivity is not within bounds of type-variable T
where T is a type-variable:
T extends Activity declared in class ActivityTestRule
Error:(96, 13) error: cannot infer type arguments for ActivityTestRule<>
Error:Execution failed for task ':app:compileProdDebugAndroidTestJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED in 9s
Information:11 errors
Information:0 warnings
Information:See complete output in console
Here are my build.gradle files
root/build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// 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
}
// Define versions in a single place
ext {
// Sdk and tools
minSdkVersion = 10
targetSdkVersion = 25
compileSdkVersion = 25
buildToolsVersion = '25.0.2'
// App dependencies
supportLibraryVersion = '25.3.1'
guavaVersion = '18.0'
glideVersion = '3.6.1'
junitVersion = '4.12'
mockitoVersion = '1.10.19'
powerMockito = '1.6.2'
hamcrestVersion = '1.3'
runnerVersion = '0.5'
rulesVersion = '0.5'
espressoVersion = '2.2.2'
}
app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.example.android.testing.notes"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
flavorDimensions "versionCode"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
debug {
// Run code coverage reports by default on debug builds.
// testCoverageEnabled = true
}
}
// If you need to add more flavors, consider using flavor dimensions.
productFlavors {
mock {
applicationIdSuffix = ".mock"
}
prod {
}
}
// Remove mockRelease as it's not needed.
android.variantFilter { variant ->
if(variant.buildType.name.equals('release')
&& variant.getFlavors().get(0).name.equals('mock')) {
variant.setIgnore(true);
}
}
// Always show the result of every unit test, even if it passes.
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
}
}
buildToolsVersion '26.0.2'
}
/*
Dependency versions are defined in the top level build.gradle file. This helps keeping track of
all versions in a single place. This improves readability and helps managing project complexity.
*/
dependencies {
// App's dependencies, including test
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
compile "com.google.guava:guava:$rootProject.guavaVersion"
compile "com.github.bumptech.glide:glide:$rootProject.glideVersion"
compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"
// Dependencies for local unit tests
testCompile "junit:junit:$rootProject.ext.junitVersion"
testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
testCompile "org.powermock:powermock-module-junit4:$rootProject.ext.powerMockito"
testCompile "org.powermock:powermock-api-mockito:$rootProject.ext.powerMockito"
// Android Testing Support Library's runner and rules
androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
androidTestCompile "com.android.support.test:rules:$rootProject.ext.rulesVersion"
// Espresso UI Testing dependencies.
androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
}
/*
Resolves dependency versions across test and production APKs, specifically, transitive
dependencies. This is required since Espresso internally has a dependency on support-annotations.
*/
configurations.all {
resolutionStrategy.force "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
}
/*
All direct/transitive dependencies shared between your test and production APKs need to be
excluded from the test APK! This is necessary because both APKs will contain the same classes. Not
excluding these dependencies from your test configuration will result in an dex pre-verifier error
at runtime. More info in this tools bug: (https://code.google.com/p/android/issues/detail?id=192497)
*/
configurations.compile.dependencies.each { compileDependency ->
println "Excluding compile dependency: ${compileDependency.getName()}"
configurations.androidTestCompile.dependencies.each { androidTestCompileDependency ->
configurations.androidTestCompile.exclude module: "${compileDependency.getName()}"
}
}
What am I missing?
I suddenly started getting this error when trying to build. This was all working a few weeks ago with no changes that I know of. The issue seems to be related to react-native-fbsdk, but looking through its build.gradle it does not list support.appcompat-v7.25.x. Any advice?
A problem occurred configuring project ':app'.
> A problem occurred configuring project ':react-native-fbsdk'.
> Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugCompile'.
> Could not find com.android.support:appcompat-v7:25.3.1.
Searched in the following locations:
file:/Users/a/.m2/repository/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.pom
file:/Users/a/.m2/repository/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.jar
https://jcenter.bintray.com/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.pom
https://jcenter.bintray.com/com/android/support/appcompat-v7/25.3.1/appcompat-v7-25.3.1.jar
build.gradle
apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
import com.android.build.OutputFile
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "___"
minSdkVersion 16
targetSdkVersion 23
versionCode 22
versionName "1.5.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [manifestApplicationId: "___",
onesignal_app_id: "___",
onesignal_google_project_number: "___"]
multiDexEnabled true
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-device-info')
compile project(':react-native-code-push')
compile project(':react-native-image-crop-picker')
compile project(':react-native-image-picker')
compile project(':react-native-fs')
compile project(':react-native-vector-icons')
compile project(':react-native-material-kit')
compile project(':react-native-config')
compile project(':react-native-onesignal')
compile project(':react-native-push-notification')
compile project(':react-native-android-permissions')
compile project(':react-native-android-keyboard-adjust')
compile project(':react-native-fbsdk')
compile (project(':react-native-fbads')) {
exclude group: 'com.google.android.gms'
}
compile 'com.facebook.android:audience-network-sdk:4.18.+'
compile 'com.google.ads.mediation:facebook:4.18.+'
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-crash:10.2.0'
compile 'com.google.firebase:firebase-ads:10.2.0'
compile project(':react-native-billing')
compile project(':react-native-blur')
compile project(':instabug-reactnative')
compile project(':mobile-center-analytics')
compile project(':mobile-center-crashes')
compile (project(':react-native-appodeal')) {
exclude group: 'com.facebook.ads'
exclude (group: 'javax.inject', module: 'javax.inject')
}
compile project(':cheetah')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.facebook.fresco:animated-gif:0.12.0"
compile "com.android.support:multidex:1.0.1"
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
I've had the same problem (appcompat-v7:25.3.1), on an android project, but not using react.
I first tried to clean the gradle cache (~/.gradle/caches), like explained here, but it didn't help.
Then I looked at the SDK Manager.
Android Support libraries are normally installed via sdkmanager.
The libraries are then stored in a local maven repository : <SDK_HOME>/sdk/extras/android/m2repository/.
For example, for appcompat-v7 the list of versions installed is in <SDK_HOME>/sdk/extras/android/m2repository/com/android/support/appcompat-v7/maven-metadata.xml.
So, for the Android Support Repository (revision: 47.0.0), the last version was normally 25.3.1.
To fix my problem, I had to uninstall the Android Support Repository via the SDK Manager, then reinstall it.
I also found another way to fetch support libraries : remotely.
After reading here (https://developer.android.com/topic/libraries/support-library/setup.html#add-library) and modifying <PROJECT_ROOT>/build.gradle like this :
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Then I tried to use a newer version of appcompat-v7:25.4.0 that was not in my local maven repository, and it worked !
The list of this Google Maven repository's versions of this library can be seen there : https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/maven-metadata.xml.
Follow the steps,
Add google maven in project gradle (Project: build.gradle),
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Remove existing gradle cache with below command
rm -fr ~/.gradle/caches/
Have a clean build and run
My case was that this is react-native-fbsdk build.gradle (https://github.com/facebook/react-native-fbsdk/blob/master/android/build.gradle):
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
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.1.0'
compile 'com.facebook.react:react-native:+' // support react-native-v0.22-rc+
compile('com.facebook.android:facebook-android-sdk:4.+')
}
I am using React Native 0.37, so this is the line that broke for me:
compile('com.facebook.android:facebook-android-sdk:4.+')
Had to change to this for compatibility:
compile('com.facebook.android:facebook-android-sdk:4.18.+')
For this, try one of the following option:
1. Update your SDK manager > Go to build menu > clean project > then build project
or
2. Right click on project folder > open module setting > libraries > add com.android.support:appcompat-v7:25.3.1 > sync the project
3. Click on file menu > open project structure > and file the libraries
To solve this problem:
Open package.json and edit the react version to:
"react": "16.0.0-alpha.3",
"react-native": "0.43.1",
Delete node_modules directory
And re-install npm with the command npm install
In Addition: If you get a app:compileDebugJava ERROR, run react-native upgrade
(Got the solution from this github page and it worked for me)
Since gradle doesn't support declaring repositories on a per-artifact basis yet.
I modified my build.gradle (not app/build.gradle) to force all dependency to react-native to specific version:
allprojects {
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.facebook.react' && details.requested.name == 'react-native') {
def file = new File("$rootDir/../node_modules/react-native/package.json")
def version = new groovy.json.JsonSlurper().parseText(file.text).version
details.useVersion version
}
}
}
}
}
This seems to be an issue with react-native itself.
There is no official fix for this (yet), however some people have reported upgrading to have solved their problem. You can check more details here
Update 1:
Hi #roachman, this is the exact error I got which pointed me to search for above. There is another ticket logged #14225 for same(cannot post link for some reason). I was just able to resolve it by including exact version of react-native version in build.gradle dependencies line compile "com.facebook.react:react-native:0.xx.y" instead of compile 'com.facebook.react:react-native:+' You might want to try that for all projects that use that setting or a more elegant settings suggested in above in issue #14223 by user david50407
Update 2
This is officially fixed now have a look https://github.com/facebook/react-native/issues/14225#issuecomment-305073392 (had to remove earlier link for issue 14223 as I cannot post more than 2 links)
If you upgraded react-native-fbsdk from 0.5 to 0.6 versions and have this issue then open your android project (pathToYourApp/android) in Android Studio and it automatically offers you to update dependencies. Now It should work fine!
I am setting up an Android Library with different productFlavors.
The library has a light and a full flavor. The file is setted up correctly:
src/main/java/com/example/... for main classes
src/full/java/com/example/... for full classes
src/light/java/com/example/... for light classes
Android Studio correctly understood this and added a (full) to the full flavor.
ISSUE : The dependencies like okhttp is working as expected but NOT the appcompat-v7. Everything using ViewPager, FragmentActivity, RecyclerView. I've tried added the dependencies to the fullCompile but it didn't work either. The dependencies is not resolved by Android Studio, import is not working, except ok okhttp, exoplayer and so on.
I've tried Invalidate Cache/Restart, clean Project, Resync gradle, none worked.
Library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
...
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
publishNonDefault true
productFlavors {
full {
}
light {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.3.0'
fullCompile 'com.android.support:support-v4:23.1.1'
fullCompile 'com.android.support:appcompat-v7:23.1.1'
fullCompile 'com.android.support:recyclerview-v7:23.1.1'
fullCompile 'com.squareup.picasso:picasso:2.5.0'
}
App build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildTypes {
release {
}
}
productFlavors {
full {
}
light {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.android.support:support-v4:23.+'
compile 'com.google.android.gms:play-services-base:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
fullCompile project(path: ':library', configuration: 'fullRelease')
lightCompile project(path: ':library', configuration: 'lightRelease')
}
You have to declare the configuration in the app gradle. When it is related to a library, the configurations are not declared properly. Try:
configurations {
fullDebugCompile
fullReleaseCompile
lightDebugCompile
lightReleaseCompile
}
dependencies {
...
fullDebugCompile project(path:":library", configuration:"fullDebug")
fullReleaseCompile project(path:":library", configuration:"fullRelease")
lightDebugCompile project(path:":library", configuration:"lightDebug")
lightReleaseCompile project(path:":library", configuration:"lightRelease")
}
Long explanation
The gradle android plugin uses different implementations for the app and the library, called AppVariant and LibraryVariant respectively. Sometimes the way variants and build types work is different in both kind of projects. In this case, some time ago the libraries always were compiled in the release build type within a given variant, something that made library projects not so flexible as apps were.
That is why they decided to enable the publishNonDefault option and bring support in Android Studio for this kind of behaviours, so you can use different builds of a library in different builds of an app, but you have to specify which build uses which library. This is the reason that makes you declare the configurations explicitly.
The convention name used by the Android Build Tools team is {buildType}{flavor}TaskName, so for the classpath configuration you have to use the same name.
All of this process has a downside, which is if you publish non default dependencies, the android plugin will ensure all of the possible library configurations are compiled before your app is built, so the build time can increase a bit (depending on the library size)
I recently installed the latest tools from google to my android project:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.xxx"
minSdkVersion 10
targetSdkVersion 21
versionCode 200
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
debug {
...
}
release {
...
}
}
buildTypes {
release {
...
}
debug {
...
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
// ---- Tests with robolectric
testCompile 'com.google.guava:guava:14.0.1'
testCompile 'junit:junit:4.+'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-all:2.0.2-beta'
// ---- Tests with Espresso
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude module: 'hamcrest-core'
}
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {
exclude module: 'hamcrest-core'
}
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
androidTestCompile('junit:junit-dep:4.10') {
exclude module: 'hamcrest-core'
}
}
Where before that I used to use com.github.jcandksolutions.gradle:android-unit-test:2.1.1 to run my robolectric tests in the jvm.
As google says for their new build tools: "New source folders recognized as unit tests: src/test/java, src/testDebug/java, src/testMyFlavor/java etc."
But as you can see below, my test folder isn't recognised as a source folder. It worked with com.github.jcandksolutions.gradle:android-unit-test:2.1.1, but no more with the new build tools:
What I'm missing here? Thank you
I found the solution which is to switch between Test Artifacts in the left corner of the IDE. On this screen only "Android Instrumentation Tests" is available because I downgraded my android tools but with tools 1.1.0+ you should see different types of test to get the IDE recognize them as source folders.
I had a similar problem the other day, except that I was able to run Robolectric tests ok in Android Studio, but didn't work from the command line. What worked for me is the following.
1) Run ./gradlew clean assembleDebug test (instead of just clean test)
(now, it would find source from main packages, but I would get this problem instead)
2) Added this to the build.gradle file: android.sourceSets.test.java.srcDirs += "build/generated/source/r/debug"
Just follow http://tools.android.com/tech-docs/unit-testing-support to enable the experimental unit test and switch test artifact to unit tests. then your unit test folder will be recognised.
when you have more issues perhaps this will help http://nenick-android.blogspot.de/2015/02/android-studio-110-beta-4-and.html
If it's any use I set up a boiler plate project allowing the use of Unit tests and Espresso tests by the use of switching build variants. You won't need the use of any third party plugins with this.
https://github.com/hitherejoe/Android-Boilerplate