As long as I set the minSdkVersion to 21 everything is fine. But as soon as I set it to 18, the build takes like 18 minutes on my Macbook Pro (2016).
Especially transformClassesWithDexForFullDebug takes like forever.
my build gradle file:
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: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId “my.android.app”
//Todo: change to 18 for final export. Having minSdkVersion 21 reduces build time significantly
minSdkVersion 18
targetSdkVersion 25
versionCode 6
versionName "0.5.1"
testInstrumentationRunner "my.android.app.MockTestRunner"
setProperty("archivesBaseName", “MyApp-v$versionName")
multiDexEnabled true
// externalNativeBuild {
// ndk {
// abiFilters "armeabi-v7a", "x86"
// }
// }
}
sourceSets {
main {
jni.srcDirs = []
}
}
buildTypes {
debug{
// Disable fabric build ID generation for debug builds
ext.enableCrashlytics = false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
demo {
applicationIdSuffix ".demo"
versionNameSuffix "-demo"
resValue "string", "app_name", “Appname Demo"
}
full {
resValue "string", "app_name", “Appname”
}
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a'
universalApk false
}
}
// externalNativeBuild {
// ndkBuild {
// path "src/main/jni/Android.mk"
// }
// }
}
repositories {
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
maven{
url 'https://maven.fabric.io/public'
}
}
dependencies {
def supportLibVersion = '25.3.1'
def playServicesVersion = '10.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
//Utils
compile 'com.jakewharton.timber:timber:4.5.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex.rxjava2:rxjava:2.0.9'
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.birbit:android-priority-jobqueue:2.0.1'
compile "com.google.android.gms:play-services-gcm:$playServicesVersion"
compile "com.google.android.gms:play-services-vision:$playServicesVersion"
//UI
compile "com.android.support:support-dynamic-animation:$supportLibVersion"
compile "com.android.support:appcompat-v7:$supportLibVersion"
compile "com.android.support:design:$supportLibVersion"
compile "com.android.support:recyclerview-v7:$supportLibVersion"
compile 'io.realm:android-adapters:2.0.0'
compile 'com.commit451:PhotoView:1.2.5'
compile 'com.squareup.picasso:picasso:2.5.2'
//Used to create Picasso instance wrapping a custom OkHttp client for testing
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
//API calls
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
compile 'com.squareup.okhttp3:okhttp:3.4.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.0'
//Views injection
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile "com.android.support:support-annotations:$supportLibVersion"
//Analytics
compile "com.mixpanel.android:mixpanel-android:5.+"
compile "com.google.android.gms:play-services:$playServicesVersion"
//Crash reporting
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
//Debug database
debugCompile 'com.facebook.stetho:stetho:1.5.0'
debugCompile 'com.uphyca:stetho_realm:2.0.0'
//Testing
androidTestCompile "com.android.support:support-annotations:$supportLibVersion"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//For recyclerview actions
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2') {
// Necessary to avoid version conflicts
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'recyclerview-v7'
}
testCompile 'junit:junit:4.12'
//Mockito and other dependencies to mock api calls
androidTestCompile 'org.mockito:mockito-core:2.0.2-beta'
androidTestCompile "com.crittercism.dexmaker:dexmaker:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-dx:1.4"
//Library that allows waiting for retrofit calls with espresso
androidTestCompile ('com.jakewharton.espresso:okhttp3-idling-resource:1.0.0'){
exclude module: 'okhttp'
}
androidTestCompile 'com.android.support.test:runner:0.5'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.5'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'com.linkedin.testbutler:test-butler-library:1.3.1'
}
I am looking for a way to bring down the compilation time to max 5 minutes. My guess is that it would help a lot if I could figure out what transformClassesWithDexForFullDebug actually really does on a granular level, which would allow me to remove those library dependencies which are causing this insane build time. Any ideas?
This is a common problem and the reason why many developers use minSdkVersion 21 for debug builds. I myself have two productFlavors, one with minSdkVersion 15 and one with 21. I use the one with minSdkVersion 21 for my day-to-day work, because it builds so much faster than API 15. 18 minutes is extreme though, what is your build time on API 21?
See also: https://developer.android.com/studio/build/optimize-your-build.html
"When developing your app, you should deploy to a device running Android 7.0 (API level 24) or higher whenever possible."
I managed to bring down build time to 2.5 minutes by removing all directories inside ~/.gradle/
rm -rf ~/.gradle/
Related
I know there are very similar questions asked previously but before I make any drastic changes I thought I would post the question here first.
This is the error I'm getting.
My build.gradle is like this
android {
compileSdkVersion 27
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.microsoft.graph.helpdesk"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
multiDexEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
}
configurations {
all {
resolutionStrategy.force 'com.android.support:support-annotations:23.4.0'
}
}
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
// Azure AD
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.android.support:support-vector-drawable:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.github.baoyachi:StepView:1.9'
implementation 'com.github.vipulasri:timelineview:1.0.6'
compile(project(':o365-auth'))
// Dagger compiler for DI annotation support
annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.5'
provided('com.squareup.dagger:dagger-compiler:1.2.5')
// Butterknife
annotationProcessor 'com.jakewharton:butterknife:6.1.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.microsoft.graph:msgraph-sdk-android:1.1.0'
compile 'joda-time:joda-time:2.9.4'
compile 'com.google.guava:guava:19.0'
compile 'com.android.volley:volley:1.1.0-rc2'
compile 'com.android.support:design:27.0.2'
// Test libraries
androidTestCompile 'com.android.support:support-annotations:23.4.0'
//noinspection GradleCompatible
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.2'
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
apply plugin: 'com.google.gms.google-services'
I have tried all the other solutions I could find but nothing has worked so far.
If anyone has any help at all it would be much appreciated
[EDIT] I have actually tried to run three other projects using API 27 and I am getting the same error.
at project ':o365-auth' that helped me to compile it;
try adal latest version or design instead appcompat etc
dependencies {
// compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
// Dependency injection
compile 'com.squareup.dagger:dagger:1.2.5'
provided 'com.squareup.dagger:dagger-compiler:1.2.5'
// Azure AD
compile 'com.microsoft.aad:adal:1.12.0'
}
compile(project(':o365-auth'))
have similar issues;
prev on 23 and 23.0.3 all work good
tried upper gradle but same issues on 25 too
I try to start migrating a Java based multidexed project to Kotlin but I get ClassNotFoundException whenever the app tries to reference a Kotlin class. The weird thing is that the same code sometimes works sometimes it doesn't. There are computers which produce working apk and others don't. Sometimes a rebuild is enough to solve the problem.
I've tried to google it but I've only found this thread, but there is no resolution. Does this thing work properly for everyone else or aren't there any multidexed Kotlin project yet?
I've tried with AS 2.3.3 and AS 3.0.0-beta6, 2.3.3 android plugun, kotoin version 1.1.50, without proguard.
buildscript {
ext.kotlin_version = '1.1.50'
ext.android_plugin_version = '2.3.3'
ext.support_lib_version = '25.3.1'
ext.play_services_version = '11.0.4'
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
apply plugin: "com.android.application"
apply plugin: "me.tatarka.retrolambda"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "com.google.firebase.firebase-perf"
repositories {
mavenCentral()
jcenter()
maven {
url "https://jitpack.io"
}
}
android {
signingConfigs {
debug {
...
}
}
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.my.app"
signingConfig signingConfigs.debug
minSdkVersion 14
targetSdkVersion 25
versionCode 13
versionName "2.0.1.b8face5"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
testInstrumentationRunner "com.my.app.TestRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//this is because instabug uses rxjava 1 and now we have both 1 and 2 on the classpath
packagingOptions {
exclude "META-INF/rxjava.properties"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
}
}
}
dependencies {
compile fileTree(include: "*.jar", dir: "libs")
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.1") {
exclude module: "support-annotations"
}
androidTestCompile("com.android.support.test.espresso:espresso-contrib:2.2.1") {
// Necessary to avoid version conflicts
exclude group: "com.android.support", module: "appcompat"
exclude group: "com.android.support", module: "support-v4"
exclude group: "com.android.support", module: "support-annotations"
exclude module: "recyclerview-v7"
}
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:$support_lib_version"
compile "com.android.support:recyclerview-v7:$support_lib_version"
compile "com.android.support:design:$support_lib_version"
compile "com.android.support:cardview-v7:$support_lib_version"
compile "com.google.android.gms:play-services-auth:$play_services_version"
compile "com.google.android.gms:play-services-identity:$play_services_version"
compile "com.google.android.gms:play-services-location:$play_services_version"
compile "com.google.android.gms:play-services-maps:$play_services_version"
compile "com.google.firebase:firebase-core:$play_services_version"
compile "com.google.firebase:firebase-crash:$play_services_version"
compile "com.google.firebase:firebase-perf:$play_services_version"
compile "com.google.code.gson:gson:2.8.1"
compile "com.google.maps.android:android-maps-utils:0.4"
compile "com.squareup.retrofit2:retrofit:2.3.0"
compile "com.squareup.retrofit2:converter-gson:2.3.0"
compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
compile "io.reactivex.rxjava2:rxandroid:2.0.1"
compile "io.reactivex.rxjava2:rxjava:2.1.3"
compile "com.squareup.okhttp3:okhttp-urlconnection:3.8.1"
compile "com.facebook.stetho:stetho:1.5.0"
compile "com.facebook.stetho:stetho-okhttp3:1.5.0"
compile "com.squareup.picasso:picasso:2.5.2"
compile "com.jakewharton:butterknife:8.2.1"
compile "com.annimon:stream:1.1.8"
compile "com.github.lawloretienne:quickreturn:0.0.1"
compile "com.github.chrisbanes:PhotoView:1.2.6"
compile "fr.baloomba:viewpagerindicator:2.4.2"
compile "com.github.bluejamesbond:textjustify-android:2.1.6"
compile "com.turingtechnologies.materialscrollbar:lib:10.1.4"
compile "com.github.PhilJay:MPAndroidChart:v3.0.1"
compile "com.android.support:multidex:1.0.1"
compile "com.bugsnag:bugsnag-android:3.9.0"
//TODO check periodically whether they upgraded to rxjava 2
compile "com.instabug.library:instabug:4.2.11"
testCompile "junit:junit:4.12"
androidTestCompile "com.android.support:support-annotations:$support_lib_version"
androidTestCompile "com.android.support.test:runner:0.5"
androidTestCompile "com.android.support.test:rules:0.5"
annotationProcessor "com.jakewharton:butterknife-compiler:8.2.1"
compile "com.google.dagger:dagger:2.5"
annotationProcessor "com.google.dagger:dagger-compiler:2.5"
provided "javax.annotation:jsr250-api:1.0"
}
apply plugin: "com.google.gms.google-services"
Finally I was able to solve the issue! The exception was caused by a RetroLambda bug and thankfully disappeared after I updated to 3.7.0. The build was nondeterministic because it seems gradle clean doesn't delete everything. After I manually deleted the build folder both in the app and root module, the results became deterministic.
If you are using Java 8 then you should also use Kotlin jre8.
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
This is more of asking suggestion for changes to be made to my build.gradle as i am about to release my first android app.Searched a lot but no satisfactory solution.Here is my gradle file
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' }
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 19
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
resConfigs "en_US", "hi_IN"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.digits.sdk.android:digits:2.0.6#aar') {
transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.7#aar') {
transitive = true;
}
compile('io.fabric.sdk.android:fabric:1.3.10#aar') {
transitive = true;
}
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:gridlayout-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:support-annotations:25.3.1'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.google.android.gms:play-services-location:10.2.1'
compile 'com.google.android.gms:play-services-places:10.2.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.google.firebase:firebase-crash:10.2.1'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.google.firebase:firebase-storage:10.2.1'
compile 'com.google.firebase:firebase-appindexing:10.2.1'
compile ('io.branch.sdk.android:library:2.5.9') {
transitive = true;
exclude module: 'answers-shim';
}
}
apply plugin: 'com.google.gms.google-services'
Every suggestion matters as it could also be helpful for other beginners like me who are planning to release their first build in play store.
I can see that you have enabled pro guard in your release mode. I suggest you to consider following statement from android doc
For even more code shrinking, try the proguard-android-optimize.txt file that's in the same location. It includes the same ProGuard rules, but with other optimizations that perform analysis at the bytecode level—inside and across methods—to reduce your APK size further and help it run faster.
change this
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
to this
proguardFiles getDefaultProguardFile('**proguard-android-optimize.txt**'), 'proguard-rules.pro'
Also add this to release mode
shrinkResources true
And don't forget to add pro guard rules if you haven't already.
Doing above two things will make your app small in size and more optimized.
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.
As soon as I update my build.grade file to API level 23, I get errors that I cannot locate, and cannot fix them. However, these same errors do not show up with 22 or 21. The error that shows up is:
Attribute "titleTextColor" has already been defined, and for some reason, it highlights the colors.xml file. There are no instances of titleTextColor in my entire project. When I do a project wide (cmd + shift + f) search, the only instances of titleTextColor show up in generated build files. What's going on here, and how can I fix this?
[Edit] build.grade file
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'play'
repositories {
//ViewPagerIndicator AAR packaged
maven {
url 'http://dl.bintray.com/populov/maven'
}
jcenter()
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
publishingConfigs {
}
signingConfigs {
basicRelease {
}
advancedRelease {
}
debug {
storeFile file('publish/debug.keystore')
}
}
productFlavors {
basic {
applicationId "com.basic"
versionCode 1
versionName "1.0.0"
}
advanced {
applicationId "com.advanced"
versionCode 2
versionName "1.0.1"
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'LICENSE.txt'
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
}
}
lintOptions {
abortOnError true
htmlReport true
checkAllWarnings true
warningsAsErrors true
}
configurations {
all*.exclude group: 'com.google.android', module: 'support-v4'
all*.exclude group: 'com.google.android', module: 'support-v13'
}
dependencies {
compile 'com.android.support:support-v13:23.0.+'
compile 'com.android.support:appcompat-v7:23.0.+'
compile 'commons-httpclient:commons-httpclient:3.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'joda-time:joda-time:2.3'
compile 'org.ocpsoft.prettytime:prettytime:3.2.1.Final'
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
//https://github.com/weddingparty/AndroidFloatLabel
compile ':float-label:1.2.1.0#aar'
//Forked from https://github.com/inmite/android-styled-dialogs
compile 'eu.inmite.android.lib:android-styled-dialogs:1.2.0'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.makeramen:roundedimageview:1.2.1'
compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'
debugCompile 'com.squareup.retrofit:retrofit-mock:1.9.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile('com.squareup.okhttp:okhttp-urlconnection:2.3.0') {
exclude(group: 'com.squareup.okhttp', module: 'okhttp')
}
compile 'com.squareup.okio:okio:1.3.0'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'info.metadude.android:typed-preferences:2.0.0'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'commons-io:commons-io:2.4'
compile 'com.crittercism:crittercism-android-ndk-agent:5.0.6'
compile 'com.jakewharton:butterknife:6.1.0'
compile('com.segment.analytics.android:analytics-core:3.0.2#aar') {
transitive = true
}
compile 'pl.charmas.android:android-reactive-location:0.5#aar'
compile 'com.github.amlcurran.showcaseview:showcaseview:5.1.1#aar'
compile files('libs/appsflyer-2.3.1.16.jar')
debugCompile 'com.jakewharton.madge:madge:1.1.1'
debugCompile 'com.jakewharton.scalpel:scalpel:1.1.1'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') {
exclude group: 'javax.inject'
}
compile files('libs/comscore.jar')
}
From the error it looks like in one of your dependencies "titleTextColor" attribute could already be defined.
For example, this popular square library has an open ticket:
https://github.com/square/android-times-square/issues/226
So remove the culprit library or in-case if you need the library, you will need to revert back to API 22.
Hope this helps.