java.lang.NoClassDefFoundError: com.viewpagerindicator.R$attr on APi =< 19 - android

I use https://github.com/JakeWharton/ViewPagerIndicator in my project.
And get java.lang.NoClassDefFoundError on devices with API <= 19:
If API > 19 - all fine.
my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'android-command'
apply plugin: "jacoco"
apply plugin: 'newrelic'
jacoco {
toolVersion = "0.7.1.201405082137"
}
def coverageSourceDirs = [
'../app/src/main/java'
]
task jacocoTestReport(type: JacocoReport, dependsOn: "connectedAndroidTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports"
classDirectories = fileTree(
dir: '../app/build/intermediates/classes/debug',
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/BuildConfig.*',
'**/Manifest*.*']
)
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files('../app/build/jacoco/testDebug.exec')
reports {
xml.enabled = false
html.enabled = true
}
}
android {
compileSdkVersion 23
buildToolsVersion '23'
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "xxx"
minSdkVersion 16
targetSdkVersion 22
versionCode 4
versionName "1.3"
multiDexEnabled = true
}
buildTypes {
debug {
debuggable true
testCoverageEnabled = true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.squareup:otto:1.3.8'
compile 'com.pnikosis:materialish-progress:1.5'
compile 'com.newrelic.agent.android:android-agent:5.+'
compile 'com.prolificinteractive:material-calendarview:0.8.0'
compile 'com.github.lecho:hellocharts-library:1.5.5#aar'
compile 'com.github.orangegangsters:swipy:1.2.0#aar'
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1#aar'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'org.solovyev.android.views:linear-layout-manager:0.5#aar'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.4.1'
}
Maybe somebody have the same problem.
Also I tried to import Viewpager library as project and I used next approach: Add ViewPagerIndicator to Android Studio, but nothing changed.

Problem was in 65k methods limit.
You can find instructions here.

Related

Android Studio 3.5 ERROR: Unable to resolve dependency for ':app#debug/compileClasspath'

I have this errors when I try to sync gradle. I am using Android Studio 3.5 and gradle 5.4.1 . It worked fine with this configuration and suddenly I start getting this errors.
**ERROR**: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.google.android.gms:play-services-location:[15.0.0, 16.0.0).
Affected Modules: app
**ERROR**: Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-location:[15.0.0, 16.0.0).
Affected Modules: app
**ERROR**: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-messaging:[10.2.1, 12.1.0).
Affected Modules: app
**ERROR**: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-location:[10.2.1, 12.1.0).
Affected Modules: app
this is my app/build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'com.apollographql.android'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'io.fabric'
def versionMajor = 4
def versionMinor = 0
def versionPatch = 0
def versionBuild = 345
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
signingConfigs {
config {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
compileSdkVersion 29
defaultConfig {
applicationId "example"
minSdkVersion 26
targetSdkVersion 29
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}.${versionBuild}"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
manifestPlaceholders = [auth0Domain: "#string/com_auth0_domain", auth0Scheme: "demo"]
setArchivesBaseName new Date().format("dd.MMM.yy") + "-v#" + versionName
//OneSignal
manifestPlaceholders = [
onesignal_app_id: 'id',
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: 'REMOTE'
]
// add some strings to res
resValue('string', 'google_maps_api_key', google_maps_api_token)
resValue('string', 'google_maps_places_api_key', google_maps_places_api_token)
buildConfigField("String", "API_TOKEN", "\"$api_token\"")
buildConfigField("String", "ADJUST_TOKEN", "\"$adjust_token\"")
buildConfigField("String", "GRAPH_QL", "\"$api_graphql\"")
renderscriptTargetApi 28
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField("String", "SERVER_URL", "\"$api_base_url$api_ext_release\"")
signingConfig signingConfigs.config
}
staging {
debuggable true
applicationIdSuffix ".staging"
buildConfigField("String", "SERVER_URL", "\"$api_base_url$api_ext_staging\"")
signingConfig signingConfigs.config
}
debug {
debuggable true
applicationIdSuffix ".debug"
buildConfigField("String", "SERVER_URL", "\"$api_base_url$api_ext_dev\"")
signingConfig signingConfigs.config
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
}
apollo {
customTypeMapping = ["Datetime": "java.lang.String"]
customTypeMapping = ["Currency": "java.lang.String"]
useSemanticNaming = false
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// android ui and support versions
implementation(
"androidx.appcompat:appcompat:$appcompat_version",
"androidx.constraintlayout:constraintlayout:$constraintlayout_version",
"com.google.android.material:material:$material_design_components_version"
)
compileOnly group: "javax.annotation", name: "javax.annotation-api", version: "1.3.2"
compileOnly group: "org.jetbrains", name: "annotations", version: "13.0"
implementation(
"androidx.core:core-ktx:$ktx_version",
"androidx.fragment:fragment-ktx:$ktx_version",
"android.arch.navigation:navigation-fragment-ktx:$nav_version",
"android.arch.navigation:navigation-ui-ktx:$nav_version"
)
implementation "android.arch.navigation:navigation-fragment:$nav_version"
// use -ktx for Kotlin
implementation "android.arch.navigation:navigation-ui:$nav_version"
// use -ktx for Kotlin
implementation(
"com.mikepenz:fastadapter:$fast_adapter_version",
"com.mikepenz:fastadapter-commons:$fast_adapter_version",
"com.mikepenz:fastadapter-extensions-expandable:$fast_adapter_version",
"com.mikepenz:fastadapter-extensions:$fast_adapter_version",
"com.mikepenz:materialize:$materialize_version"
)
// firebase
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
// data and api
implementation(
"com.apollographql.apollo:apollo-runtime:$apollo_version",
"com.apollographql.apollo:apollo-http-cache:$apollo_version"
)
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_interceptor_version"
// rx
implementation(
"io.reactivex.rxjava2:rxandroid:$rx_android_version",
"io.reactivex.rxjava2:rxjava:$rx_java_version",
"com.apollographql.apollo:apollo-rx2-support:$apollo_version"
)
implementation "de.hdodenhof:circleimageview:$circle_imageview_version"
// koin di
implementation(
"org.koin:koin-android:$koin_version",
"org.koin:koin-androidx-scope:$koin_version",
"org.koin:koin-androidx-viewmodel:$koin_version"
)
// rx android networking
implementation(
"com.amitshekhar.android:rx2-android-networking:$afn_version",
"com.github.prashantsolanki3:Secure-Pref-Manager:$secure_prefs_vresion"
)
//Beta by Crashlytics
compile('com.crashlytics.sdk.android:crashlytics:2.10.1#aar') {
transitive = true;
}
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation "com.google.maps.android:android-maps-utils:0.5"
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.libraries.places:places:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation "junit:junit:$junit_version"
androidTestImplementation("androidx.test:runner:$test_runner_version",
"androidx.test.espresso:espresso-core:$espresso_test_version"
)
//Glide
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
//Permission Manager
implementation 'com.github.florent37:runtime-permission-kotlin:1.1.0'
//Notification banner
implementation 'com.github.shasin89:NotificationBanner:1.1.0'
//Loading spinner
implementation 'com.github.ybq:Android-SpinKit:1.2.0'
//Circle image view
implementation 'de.hdodenhof:circleimageview:3.0.0'
//helpers for Android SDK
implementation "org.jetbrains.anko:anko:$anko_version"
//date helper
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'
//Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
//EventBus
implementation 'org.greenrobot:eventbus:3.1.1'
//Round corner progress bar
implementation 'com.akexorcist:RoundCornerProgressBar:2.0.3'
//Expandable RecycleView
implementation 'com.thoughtbot:expandablerecyclerview:1.3'
//OneSignal
implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
implementation "joda-time:joda-time:$jodatime_version"
implementation 'com.github.drawers:SpinnerDatePicker:2.0.1'
//Adjust
implementation 'com.adjust.sdk:adjust-android:4.18.0'
implementation 'com.android.installreferrer:installreferrer:1.0'
// implementation 'com.adjust.sdk:adjust-android-webbridge:4.18.0' if user Adjust with webview
testImplementation 'org.koin:koin-test:1.0.1'
debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
stagingImplementation 'com.readystatesoftware.chuck:library:1.1.0'
releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'
}
apply plugin: 'com.google.gms.google-services'
If you have it declared as follows in project build.gradle
maven { url "https://jitpack.io" }
try changing to
maven { url "https://www.jitpack.io" }
You must check your internet connection and disabled gradle offline mode in setting
after that do :
File > Invalidate Cache and restart.
And try to sync the app !

Execution failed for task ':app:transformClassesWithInstantRunForClientDebug'

The error
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' }
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile project(':venuemap')
// compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
// compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
// compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
// compile "com.google.android.gms:play-services:$rootProject.playServicesVersion"
compile "com.google.android.gms:play-services-location:$rootProject.playServicesVersion"
compile "com.google.android.gms:play-services-maps:$rootProject.playServicesVersion"
compile "com.google.android.gms:play-services-plus:$rootProject.playServicesVersion"
compile "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
compile "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
compile "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"
compile "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttpVersion"
compile 'com.google.maps.android:android-maps-utils:0.4.4'
// compile 'com.google.maps.android:android-maps-utils:0.4+'
// compile 'com.google.maps.android:android-maps-utils:0.5+'
compile 'net.hockeyapp.android:HockeySDK:4.1.1'
compile 'com.flurry.android:analytics:6.5.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0#aar'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'org.parceler:parceler-api:1.1.9'
compile 'com.github.jd-alexander:library:1.1.0'
compile 'com.android.support:multidex:1.0.0'
compile "com.google.firebase:firebase- core:$rootProject.playServicesVersion"
compile 'com.facebook.android:facebook-android-sdk:4.+'
// annotationProcessor 'org.parceler:parceler:1.1.9'
compile('com.crashlytics.sdk.android:answers:1.4.0#aar') {
transitive = true;
}
}
android {
def defaultApplicationId = "com.yamo.android"
def defaultVersionName = "1.1.7"
def buildNumber = "53" // increment when merging with master
def defaultVersionCode = Integer.parseInt(buildNumber)
def buildNumberSuffix = " (" + buildNumber + ")"
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
applicationId defaultApplicationId
versionCode defaultVersionCode
versionName defaultVersionName
vectorDrawables.useSupportLibrary = true
// multiDexEnabled true
}
signingConfigs {
debug {
storeFile rootProject.file("keystore/debug.keystore")
}
release {
storeFile rootProject.file("keystore/release.keystore")
storePassword "password"
keyAlias "locassa"
keyPassword "password"
}
}
buildTypes {
debug {
minifyEnabled true
useProguard false
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
useProguard true
shrinkResources true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
live {
versionName defaultVersionName + buildNumberSuffix
}
client {
versionName defaultVersionName + "-CLIENT" + buildNumberSuffix
applicationId defaultApplicationId
}
internal {
versionName defaultVersionName + "-INTERNAL" + buildNumberSuffix
applicationId defaultApplicationId + ".internal"
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
}
//apply from:
rootProject.file('config/checkstyle/checkstyle.gradle')
apply plugin: 'com.google.gms.google-services'
}
When building app, I have got this error.
I am using android studio 2.3.3.
CompileSdkVersion is 26 and buildToolsVersion is 26.0.2.
And my gradle version is 2.3.3.
I have been searching the solution about this problem for several days but I didn't find anything on google.
Please help me to resolve this error. Thanks a lot!
This is your Problem :
compile 'com.facebook.android:facebook-android-sdk:4.+'
Use this :
compile 'com.facebook.android:facebook-android-sdk:4.4.0'

Compile time errors with dagger

Very often while compiling I get the following error:
Error:(5, 18) error: cannot find symbol class DaggerDataComponent
Error:(14, 21) error: cannot find symbol class DaggerNetComponent
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
It is enough to start building again with no changes to make the building succeeding.
I have the Instant Run feature disabled.
I'm using Java8 with retrolambda and dagger2 2.8.
This is my build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.3.1'
}
}
plugins {
id "me.tatarka.retrolambda" version "3.3.1"
}
// Required because retrolambda is on maven central
repositories {
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 25
buildToolsVersion "24.0.2"
compileOptions.incremental = false
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "org.app"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
jackOptions {
enabled false
}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
compileOptions {
incremental true
}
/**
* Signing keys config.
*/
signingConfigs {
debug {
storeFile file("ddebug.keystore")
keyAlias "ddebug"
storePassword "07477800086d!"
keyPassword "07477800086d!"
}
release {
storeFile file("drelease.keystore")
keyAlias "drelease"
storePassword "07477800086d!"
keyPassword "07477800086d!"
}
}
buildTypes {
release {
debuggable false
minifyEnabled true
zipAlignEnabled true
renderscriptDebuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
debuggable true
signingConfig signingConfigs.debug
minifyEnabled false
versionNameSuffix "_dev"
}
}
}
dependencies {
apt 'com.google.dagger:dagger-compiler:2.7'
compile 'com.google.dagger:dagger:2.7'
provided 'javax.annotation:jsr250-api:1.0'
apt 'com.gabrielittner.auto.value:auto-value-with:1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
def supportVersion = '25.1.0'
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:design:$supportVersion"
compile "com.android.support:cardview-v7:$supportVersion"
compile "com.android.support:recyclerview-v7:$supportVersion"
compile "com.android.support:support-annotations:$supportVersion"
compile "com.android.support:gridlayout-v7:$supportVersion"
compile "com.android.support:support-annotations:$supportVersion"
compile 'io.reactivex:rxandroid:0.24.0'
def retrofit2 = '2.1.0'
def okhttp3 = '3.4.1'
compile "com.squareup.retrofit2:retrofit:$retrofit2"
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit2"
compile "com.squareup.retrofit2:converter-gson:$retrofit2"
compile "com.squareup.okhttp3:okhttp:$okhttp3"
compile "com.squareup.okhttp3:okhttp-urlconnection:$okhttp3"
compile "com.squareup.okhttp3:logging-interceptor:$okhttp3"
def butter_knife = '8.4.0'
apt "com.jakewharton:butterknife-compiler:$butter_knife"
compile "com.jakewharton:butterknife:$butter_knife"
def leak_canary = '1.4-beta2'
debugCompile "com.squareup.leakcanary:leakcanary-android:$leak_canary"
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary"
testCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary"
compile 'com.github.clans:fab:1.6.4'
compile 'io.reactivex:rxjava:1.2.0'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0'
provided 'com.google.auto.value:auto-value:1.2'
apt 'com.google.auto.value:auto-value:1.2'
compile 'com.ryanharter.auto.value:auto-value-parcel-adapter:0.2.5'
apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
apt 'com.ryanharter.auto.value:auto-value-gson:0.3.2-rc1'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.jakewharton.timber:timber:4.3.1'
compile 'com.google.firebase:firebase-crash:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'junit:junit:4.12'
//other dependencies for testing
def hamcrestVersion = '1.3'
testCompile "org.hamcrest:hamcrest-core:$hamcrestVersion"
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
testCompile "org.hamcrest:hamcrest-integration:$hamcrestVersion"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
apply plugin: 'com.google.gms.google-services'
android.packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}

NoClassDefFoundError (4.0.4- 4.4.2)on Android Live Application

Recently I pushed an app(Proguard enabled) to play store but it start reporting NoClassDefFoundError on my activities (Not any library activity), these are happening on Android OS version 4.0.4 - 4.4.2 . Any help would be greatly appreciated.
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'android-apt'
apply plugin: 'jacoco'
def final myApplicationId = 'myapp.appModules.login'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
vectorDrawables.useSupportLibrary = true
applicationId myApplicationId
minSdkVersion 15
resConfigs "en"
targetSdkVersion 23
compileOptions.encoding = 'windows-1252'
/** compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}*/
}
dexOptions {
javaMaxHeapSize "4g"
}
testOptions {
unitTests.returnDefaultValues = true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
jniDebuggable false
renderscriptDebuggable false
zipAlignEnabled true
}
debug {
testCoverageEnabled true
}
}
productFlavors
{
production
{
}
staging
{
}
quality
{
}
dev
{
}
}
}
repositories {
mavenCentral()
}
task jacocoTestReport(type: JacocoReport) {
group = "Reporting"
description = "Generate Jacoco coverage reports"
// exclude auto-generated classes and tests
def fileFilter = ['**/R.class', '**/R$*.class',
'**/BuildConfig.*', '**/Manifest*.*',
'android/**/*.*', '**/*$ViewBinder*.*', '**/view/**', '**/vo/**/*.*']
def debugTree = fileTree(dir:
"${project.buildDir}/intermediates/classes/production/debug",
excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"
sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
additionalSourceDirs = files([
"${buildDir}/generated/source/buildConfig/production/debug",
"${buildDir}/generated/source/r/production/debug"
])
executionData = fileTree(dir: project.projectDir, includes:
['**/*.exec', '**/*.ec'])
reports {
xml.enabled = true
xml.destination = "${buildDir}/jacocoTestReport.xml"
csv.enabled = false
html.enabled = true
html.destination = "${buildDir}/reports/jacoco"
}
}
dependencies {
compile project(':ImageCropper')
compile project(':dropboxChooserSDK')
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.facebook.android:facebook-android-sdk:3.23.1'
compile 'com.google.android.gms:play-services-drive:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
compile files('libs/volley.jar')
compile files('libs/comscore.jar')
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
testCompile 'org.mockito:mockito-all:1.10.19'
testCompile 'org.powermock:powermock-api-mockito:1.6.4'
testCompile 'org.powermock:powermock-module-junit4:1.6.4'
testCompile 'junit:junit:4.12'
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}

Jacoco Android createDebugCoverageReport not found

I want to run my tests in Android app and create coverage reports, so I added Jacoco configuration into my build.gradle file, but it doesn't work.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "mm"
minSdkVersion 12
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.google.code.gson:gson:2.1'
compile files('libs/android-async-http-1.4.4.jar')
compile files('libs/freemarker.jar')
compile files('libs/greendao-1.3.1.jar')
compile files('libs/raygun4android-1.1.0.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.hamcrest:hamcrest-library:1.3'
compile 'junit:junit:4.11'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
jacoco {
version "0.7.1.201405082137"
}
jacoco {
toolVersion "0.7.1.201405082137"
}
def coverageSourceDirs = [
'src/main/java',
]
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
classDirectories = fileTree(
dir: './build/intermediates/classes/debug',
excludes: ['**/R*.class',
'**/*$InjectAdapter.class',
'**/*$ModuleAdapter.class',
'**/*$ViewInjector*.class'
])
sourceDirectories = files(coverageSourceDirs)
executionData = files("$buildDir/jacoco/testDebug.exec")
doFirst {
new File("$buildDir/intermediates/classes/").eachFileRecurse { file ->
if (file.name.contains('$$')) {
file.renameTo(file.path.replace('$$', '$'))
}
}
}
}
I know, there is issue with gradle version 1.3.0 and with 1.3.1 it should work normally, however with 1.3.1 I get Task 'createDebugCoverageReport' not found in root project.
You have to enable the testCoverageEnabled :
buildTypes {
debug{
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
isTestCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
isTestCoverageEnabled true
}
}

Categories

Resources