I'm trying to set up Junit tests to test my Java code in an android project. I can't seem to get it working with the Gradle build.
I have set up one test as an example for now. My project is legacy which I ported to use Gradle, so I've defined the source sets and the structure rather than move the files into the new directory format.
When I run the build or just UnitTest the output is Build Successful, but it hasn't actually run my test unit test. Android studio does not seem to recognise the file as java either and does not show errors/ code completion on my ExampleTest.java file.
Project
-> Module
-> assets
-> build
-> gen
-> libs
-> res
-> src
-> tests
My gradle build file:
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
}
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 10
targetSdkVersion 20
versionCode 47
versionName '2.1'
}
buildTypes {
release {
runProguard true
zipAlign true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
proguardFile 'proguard-project.txt'
}
debug {
runProguard false
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-project.txt'
}
}
signingConfigs {
debug {
storeFile file('../debug.keystore')
}
release {
storeFile file("XX")
storePassword "XX"
keyAlias "XX"
keyPassword "XX"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
unitTest {
java.srcDir file('tests')
resources.srcDir file('test/resources')
}
}
}
sourceSets {
unitTest {
java.srcDir file('test')
resources.srcDir file('test/resources')
}
}
dependencies {
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.crashlytics.android:crashlytics:1.+'
unitTestCompile 'junit:junit:4.1+'
unitTestCompile files("$buildDir/intermediates/classes/debug")
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
// bind to check
build.dependsOn unitTest
Do the following to your gradle script. This will allow you to run your tests within the JVM, which means not having to run the emulator or run the tests on a device.
At the top:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.robolectric:robolectric-gradle-plugin:0.12.+'
}
}
New plugin:
apply plugin: 'robolectric'
And near the bottom:
robolectric {
//configure the set of classes for JUnit tests
include '**/*Test.class'
//configure whether failing tests should fail the build
ignoreFailures false
}
And add the following dependencies:
androidTestCompile ('junit:junit:4.11')
androidTestCompile ('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-plugin-registry'
exclude module: 'maven-profile'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'nekohtml'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-http-shared'
exclude module: 'wagon-provider-api'
exclude group: 'com.android.support', module: 'support-v4'
}
Then start writing your tests in your tests folder. As you can see I set up a filter so only classes that start with Test.class are included in the test suite. Be sure to put the following annotations on any of these test classes: (be sure to change the url for the manifest file as it would be different for you from what is written)
#RunWith(RobolectricTestRunner.class)
#Config(manifest = "./src/main/AndroidManifest.xml", emulateSdk = 18)
class FirstTest {
// tests go here
}
Finally, run the tests with ./gradlew test
Related
In my CI pipeline until June 6 it worked. Today it failed. The following build error occurred.
WARNING: Module 'com.android.support:support-vector-drawable:26.0.2' depends on one or more Android Libraries but is a jar
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Could not find support-vector-drawable.jar (com.android.support:support-
vector-drawable:26.0.2).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-vector-
drawable/26.0.2/support-vector-drawable-26.0.2.jar
Build.Gradle file
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "io.realm:realm-gradle-plugin:3.1.4"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.newrelic.agent.android:agent-gradle-plugin:5.+'
classpath 'com.google.gms:google-services:3.1.0'
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://mobile-sdk.jumio.com' }
maven {
url "https://maven.google.com/" // Google's Maven repository
}
maven {
url "http://kochava.bintray.com/maven"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'newrelic'
apply plugin: "io.spring.dependency-management"
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
defaultConfig {
applicationId "com.seven.eleven.phoenix"
minSdkVersion 19
targetSdkVersion 26
versionCode 16
versionName "1.1.1_1_QA"
multiDexEnabled true
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 21
renderscriptSupportModeEnabled true
}
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
sourceSets { main { assets.srcDirs = ['src/main/assets',
'src/main/assets/fonts'] } }
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
buildTypes.each {
it.buildConfigField 'String', 'STRIPE_APIKEY',
keystoreProperties['StripeKey']
it.buildConfigField 'String', 'PHOENIX_API_KEY',
keystoreProperties['PhoenixAPIKey']
it.buildConfigField 'String', 'NEW_RELIC_KEY',
keystoreProperties['NewRelicKey']
it.buildConfigField 'String', 'OPEN_WEATHER_API_KEY',
keystoreProperties['OpenWeatherAPIKey']
it.buildConfigField 'int', 'WORKING_BRANCH', getCurrentGitBranch()
}
}
def getCurrentGitBranch() {
def gitBranch = "Unknown branch"
try {
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) {
gitBranch = result.text.trim()
}
} catch (e) {
}
if(gitBranch.contains('master')||gitBranch.contains('PROD') ||
gitBranch.contains('7XXX_Master')){
return "1";
} else {
return "0";
}
}
ext {
SDK_VERSION = "2.10.0"
ANDROID_VERSION = "26.0.2"
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.squareup.retrofit2:retrofit:2.3.0')
{
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
compile('com.squareup.retrofit2:converter-gson:2.3.0')
{
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
compile group: 'de.mindpipe.android', name: 'android-logging-log4j',
version: '1.0.3'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile "com.android.support:cardview-v7:${ANDROID_VERSION}#aar"
compile "com.android.support:mediarouter-v7:${ANDROID_VERSION}#aar"
compile "com.android.support:palette-v7:${ANDROID_VERSION}#aar"
compile "com.android.support:design:${ANDROID_VERSION}#aar"
compile "com.android.support:appcompat-v7:${ANDROID_VERSION}#aar"
compile "com.jumio.android:core:${SDK_VERSION}#aar"
compile "com.jumio.android:bam:${SDK_VERSION}#aar"
compile "com.jumio.android:nv:${SDK_VERSION}#aar"
compile "com.jumio.android:nv-mrz:${SDK_VERSION}#aar"
compile "com.jumio.android:nv-barcode:${SDK_VERSION}#aar"
compile "com.jumio.android:nv-barcode-vision:${SDK_VERSION}#aar"
compile "com.jumio.android:nv-liveness:${SDK_VERSION}#aar"
compile "com.jumio.android:dv:${SDK_VERSION}#aar"
compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile group: 'com.googlecode.libphonenumber', name: 'libphonenumber',
version: '7.0'
compile('com.squareup.retrofit2:converter-simplexml:2.3.0') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
exclude group: 'xpp3', module: 'xpp3'
}
compile files('libs/simple-xml-2.7.1.jar')
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.kochava.base:tracker:3.2.0'
compile 'com.newrelic.agent.android:android-agent:5.+'
compile 'com.stripe:stripe-android:6.0.0'
testCompile 'junit:junit:4.12'
compile 'com.google.dagger:dagger:2.9'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
provided 'javax.annotation:jsr250-api:1.0'
//for pay with google using google wallet service
compile 'com.google.android.gms:play-services-wallet:11.6.0'
compile 'com.google.android.gms:play-services:11.6.0'
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
compile 'org.jsoup:jsoup:1.11.2'
compile
compile('com.amazonaws:aws-android-sdk-kms:2.6+') { transitive = true; }
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile "org.robolectric:robolectric:3.6.1"
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.257'
}
}
apply plugin: 'com.google.gms.google-services'
I have included the build gradle file as well as app level project configuration It was unable to download that dependency.Any help would be greatly appreciated.we are using an gradle 4.1 and a docker container to make the build. I used command ./gradle clean initially.
I have found many versions of this on StackOverflow, but none of the answers that I have found have helped and some have even made more errors. But after forking a project from GitHub and editing the the Gradle and SDK versions, I came across this error:
Error:(70, 0) Cannot convert the provided notation to a File or URI: [C:\Android Projects\Personal\VoidMessenger\build\intermediates\proguard-files\proguard-android.txt-2.2.0, C:\Android Projects\Personal\VoidMessenger\proguard.cfg].
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A URI or URL instance.
This came after I imported the project from GitHub into Android Studio, and changing the SDK and build versions to 25 and the Gradle version to 2.2.0. Here is my build.gradle and my settings.gradle.
Build.Gradle:
apply plugin: 'com.android.application'
apply plugin: 'witness'
buildscript {
repositories {
maven {
url "https://repo1.maven.org/maven2"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath files('libs/gradle-witness.jar')
}
}
repositories {
maven {
url "https://repo1.maven.org/maven2/"
}
jcenter()
mavenLocal()
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
versionCode 1
versionName "0.1"
minSdkVersion 9
targetSdkVersion 25
try{
buildConfigField "String", "BUILD_GIT_COMMIT", "\"" + 'git rev-parse --short HEAD'.execute().text.trim() + "\""
}
catch(IOException e){
buildConfigField "String", "BUILD_GIT_COMMIT", '""'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'LICENSE'
exclude 'NOTICE'
exclude 'asm-license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
signingConfigs {
release
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
release {
minifyEnabled true
proguardFiles = buildTypes.debug.proguardFiles
testProguardFiles buildTypes.debug.testProguardFiles
signingConfig signingConfigs.release
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest {
java.srcDirs = ['test/androidTest/java']
}
test {
java.srcDirs = ['test/unitTest/java']
}
}
lintOptions {
abortOnError false
}
}
tasks.whenTaskAdded { task ->
if (task.name.equals("lint")) {
task.enabled = false
}
}
def Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()){
props.load(new FileInputStream(propFile))
if (props !=null &&
props.containsKey('STORE_FILE') &&
props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') &&
props.containsKey('KEY_PASSWORD'))
{
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
} else {
println 'signing.properties found but some entries are missing'
android.buildTypes.release.signingConfig = null
}
}else {
println 'signing.properties not found'
android.buildTypes.release.signingConfig = null
}
tasks.withType(JavaCompile){
options.warnings = false
}
dependencies {
compile 'se.emilsjolander:stickylistheaders:2.7.0'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
compile project (':libs:org.w3c.dom')
compile 'info.guardianproject.trustedintents:trustedintents:0.2'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.makeramen:roundedimageview:2.1.0'
compile 'com.pnikosis:materialish-progress:1.5'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'pl.tajchert:waitingdots:0.1.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.google.zxing:android-integration:3.1.0'
compile project (':libs:com.android.support.support-v4-preferencefragment')
compile ('com.android.support:gridlayout-v7:22.2.0') {
exclude module: 'support-v4'
}
compile 'com.squareup.dagger:dagger:1.2.2'
compile ("com.doomonafireball.betterpickers:library:1.5.3") {
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.madgag.spongycastle:prov:1.51.0.0'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'
compile project (':libs:org.whispersystems.jobmanager')
compile project (':libs:org.whispersystems.libpastelog:library')
compile 'org.whispersystems:textsecure-android:1.8.3'
compile project (':libs:com.amulyakhare.textdrawable:library')
compile 'me.relex:circleindicator:1.0.0#aar'
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:1.7.1'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.powermock:powermock-api-mockito:1.6.1'
testCompile 'org.powermock:powermock-module-junit4:1.6.1'
testCompile 'org.powermock:powermock-module-junit4-rule:1.6.1'
testCompile 'org.powermock:powermock-classloading-xstream:1.6.1'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile ('org.assertj:assertj-core:1.7.1') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
androidTestCompile ('com.squareup.assertj:assertj-android:1.0.0') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
exclude group: 'com.android.support', module: 'support-annotations'
}
}
dependencyVerification {
verify = [
'pl.tajchert:waitingdots:2835d49e0787dbcb606c5a60021ced66578503b1e9fddcd7a5ef0cd5f095ba2c',
'com.android.support:appcompat-v7:4b5ccba8c4557ef04f99aa0a80f8aa7d50f05f926a709010a54afd5c878d3618',
'com.android.support:recyclerview-v7:b0f530a5b14334d56ce0de85527ffe93ac419bc928e2884287ce1dddfedfb505',
'com.android.support:design:58be3ca6a73789615f7ece0937d2f683b98b594bb90aa10565fa760fb10b07ee',
'com.android.support:support-v4:c62f0d025dafa86f423f48df9185b0d89496adbc5f6a9be5a7c394d84cf91423',
'com.android.support:support-annotations:104f353b53d5dd8d64b2f77eece4b37f6b961de9732eb6b706395e91033ec70a',
'com.android.support:gridlayout-v7:a9b770cffca2c7c5cd83cba4dd12503365de5e8d9c79c479165adf18ab3bc25b',
'com.doomonafireball.betterpickers:library:132ecd685c95a99e7377c4e27bfadbb2d7ed0bea995944060cd62d4369fdaf3d',
'com.madgag.spongycastle:prov:b8c3fec3a59aac1aa04ccf4dad7179351e54ef7672f53f508151b614c131398a',
'com.fasterxml.jackson.core:jackson-annotations:0ca408c24202a7626ec8b861e99d85eca5e38b73311dd6dd12e3e9deecc3fe94',
'com.fasterxml.jackson.core:jackson-core:cbf4604784b4de226262845447a1ad3bb38a6728cebe86562e2c5afada8be2c0',
'com.fasterxml.jackson.core:jackson-databind:835097bcdd11f5bc8a08378c70d4c8054dfa4b911691cc2752063c75534d198d',
'com.github.bumptech.glide:glide:76ef123957b5fbaebb05fcbe6606dd58c3bc3fcdadb257f99811d0ac9ea9b88b',
'com.github.chrisbanes.photoview:library:8b5344e206f125e7ba9d684008f36c4992d03853c57e5814125f88496126e3cc',
'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
'com.google.zxing:android-integration:89e56aadf1164bd71e57949163c53abf90af368b51669c0d4a47a163335f95c4',
'com.googlecode.libphonenumber:libphonenumber:9625de9d2270e9a280ff4e6d9ef3106573fb4828773fd32c9b7614f4e17d2811',
'com.jpardogo.materialtabstrip:library:c6ef812fba4f74be7dc4a905faa4c2908cba261a94c13d4f96d5e67e4aad4aaa',
'com.makeramen:roundedimageview:1f5a1865796b308c6cdd114acc6e78408b110f0a62fc63553278fbeacd489cd1',
'com.pnikosis:materialish-progress:d71d80e00717a096784482aee21001a9d299fec3833e4ebd87739ed36cf77c54',
'de.greenrobot:eventbus:61d743a748156a372024d083de763b9e91ac2dcb3f6a1cbc74995c7ddab6e968',
'info.guardianproject.trustedintents:trustedintents:6221456d8821a8d974c2acf86306900237cf6afaaa94a4c9c44e161350f80f3e',
'com.melnykov:floatingactionbutton:15d58d4fac0f7a288d0e5301bbaf501a146f5b3f5921277811bf99bd3b397263',
'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
'com.squareup.dagger:dagger:789aca24537022e49f91fc6444078d9de8f1dd99e1bfb090f18491b186967883',
'com.squareup.okio:okio:5e1098bd3fdee4c3347f5ab815b40ba851e4ab1b348c5e49a5b0362f0ce6e978',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
'org.apache.httpcomponents:httpclient-android:6f56466a9bd0d42934b90bfbfe9977a8b654c058bf44a12bdc2877c4e1f033f1',
'org.whispersystems:axolotl-android:40d3db5004a84749a73f68d2f0d01b2ae35a73c54df96d8c6c6723b96efb6fc0',
'org.whispersystems:axolotl-java:6daee739b89d8d7101de6d98f77132fee48495c6ea647d880e77def842f999ea',
'org.whispersystems:curve25519-android:3c29a4131a69b0d16baaa3d707678deb39602c3a3ffd75805ce7f9db252e5d0d',
'org.whispersystems:curve25519-java:9ccef8f5aba05d9942336f023c589d6278b4f9135bdc34a7bade1f4e7ad65fa3',
'org.whispersystems:textsecure-android:aec5fc59952d9f5482491091091687816f46be1144342a0244f48fd55d6ab393',
'org.whispersystems:textsecure-java:b407ca6d1430204dfabf38e27db22d5177409072a9668238bd1877de7676ad3f',
'se.emilsjolander:stickylistheaders:a08ca948aa6b220f09d82f16bbbac395f6b78897e9eeac6a9f0b0ba755928eeb',
'com.squareup.okhttp:okhttp:89b7f63e2e5b6c410266abc14f50fe52ea8d2d8a57260829e499b1cd9f0e61af',
]
Settings.Gradle:
include 'libs:com.amulyakhare.textdrawable:library',
'libs:com.android.support.support-v4-preferencefragment',
'libs:org.w3c.dom',
'libs:org.whispersystems.jobmanager',
'libs:org.whispersystems.libpastelog:library'
What could be going on? Also, before editing the gradle version, I got an error saying "Cannot find 'default'". But what could be causing the error stated in this post?
"Cannot find default" is related to some missing project module dependencies. This normally happens when you download from net and some modules codes are missing. these have to be added manually.
I'm building an Android application which size was around 4MB APK file. From a couple of weeks ago, when building signed app, generated APK file is around 17MB.
After investigating why is this happening, I've discovered that new APK archives contain /lib directory which didn't exist on old APKs that were 4MB in size. Does anyone know why this lib directory suddenly appears in APK archive and is there a way to remove it?
Structure of /lib directory inside APK archive is:
/lib
/arm64-v8a
/armeabi
/armeabi-v7a
/mips
/x86
/x86_64
I have recently updated Android Studio to 2.0 and also upgraded gradle. Can this be an issue and is there some configuration parameters that can solve this problem?
My gradle file looks like this:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
flatDir { dirs 'aars' }
}
android {
// when changing this, YOU MUST change C:\AndroidADT\sdk\build-tools\xx.yy.zz\dx.bat to have -> set java_exe=C:\Windows\System32\java.exe
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 11
targetSdkVersion 21
}
def homeDir = System.getenv('HOMEDRIVE') + System.getenv('HOMEPATH');
signingConfigs {
cinema {
storeFile = file("keystore\\cinema.keystore.jks")
storePassword = "cinema"
keyAlias = "cinema"
keyPassword = "cinema"
}
dev {
storeFile = file("keystore\\development.keystore.jks")
storePassword = "development"
keyAlias = "development"
keyPassword = "development"
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
cinema {
debuggable false
signingConfig signingConfigs.cinema
jniDebuggable false
applicationIdSuffix ".cinema"
}
dev {
debuggable true
signingConfig signingConfigs.dev
jniDebuggable true
applicationIdSuffix ".dev"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'src-gen']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug {
}
dev {
res.srcDirs = ['res_dev']
}
cinema {
res.srcDirs = ['res_cinema']
}
androidTest.setRoot('tests')
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile 'joda-time:joda-time:2.3'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.markupartist.android.widget:pulltorefresh:1.0#aar'
compile 'com.paypal.sdk:paypal-android-sdk:2.13.3'
compile('com.crashlytics.sdk.android:crashlytics:2.2.0#aar') {
transitive = true;
}
compile files('libs/gson-2.2.4.jar')
compile files('libs/twitter4j-core-4.0.2.jar')
compile files('libs/core-3.1.0.jar')
compile files('libs/estimote-sdk-preview.jar')
compile files('libs/commons-codec-1.10.jar')
compile files('libs/commons-lang-2.6.jar')
compile files('libs/FastPaySDK_pro.jar')
}
Try this to exclude SO file from the release build
android {
buildTypes {
release {
ndk {
abiFilters "armeabi-v7a", "armeabi" // includes ARM SO files only, so no x86 SO file
}
}
}
}
Have not tested,maybe you can try out: abiFilters "" to exclude all the .SO files
Problem was generated by PayPal SDK which includes card.io libraries. I have found that solution for my problem is to disable card.io card scanning:
packagingOptions {
exclude 'lib/arm64-v8a/libcardioDecider.so'
exclude 'lib/arm64-v8a/libcardioRecognizer.so'
exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
exclude 'lib/arm64-v8a/libopencv_core.so'
exclude 'lib/arm64-v8a/libopencv_imgproc.so'
exclude 'lib/armeabi/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
exclude 'lib/armeabi-v7a/libopencv_core.so'
exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
exclude 'lib/mips/libcardioDecider.so'
exclude 'lib/x86/libcardioDecider.so'
exclude 'lib/x86/libcardioRecognizer.so'
exclude 'lib/x86/libcardioRecognizer_tegra2.so'
exclude 'lib/x86/libopencv_core.so'
exclude 'lib/x86/libopencv_imgproc.so'
exclude 'lib/x86_64/libcardioDecider.so'
exclude 'lib/x86_64/libcardioRecognizer.so'
exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
exclude 'lib/x86_64/libopencv_core.so'
exclude 'lib/x86_64/libopencv_imgproc.so'
}
Or to completely exclude card.io library:
dependencies {
compile('com.paypal.sdk:paypal-android-sdk:2.14.1') {
exclude group: 'io.card'
}
}
I hope this will help somebody.
I have successfully installed Robolectric, but my tests are not running at all. There are no errors, but also no results. What did I miss?
After running ./gradlew test there are no test reports, but test-classes are generated properly
My build.gradle:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
...
classpath 'io.fabric.tools:gradle:1.+'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'idea'
apply plugin: 'hugo'
apply plugin: 'android'
apply plugin: 'robolectric'
idea {
module {
downloadJavadoc = true
downloadSources = true
testOutputDir = file('build/test-classes/debug')
}
}
repositories {
mavenCentral()
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
flatDir name: 'localRepository', dirs: 'libs-aar'
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
repositories {
mavenCentral()
}
...
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
useOldManifestMerger true
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
buildConfigField "String", "GIT_SHA", "\"${gitSha()}\""
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
// buildConfigField "String", "BUILD_TIME", buildTime()
}
...
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/com', 'src/se', 'src/viewpagerindicator' , 'src-gen']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
...
androidTest {
setRoot('src/androidTest')
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
...
robolectric {
include '**/*Tests.class'
exclude '**/espresso/**/*.class'
}
And my test:
#RunWith(RobolectricTestRunner.class)
public class StartTest {
#Test
public void testSomething() throws Exception {
//Activity activity = Robolectric.buildActivity(DeckardActivity.class).create().get();
assertTrue(true);
}
}
I think the problem is with your file mask. You are including Tests.class, but your class is called StartTest (notice the missing s) so it won't be included.
I have a very hard time solving this problem in Android studio.
I have made an app, and trying to test it with this Robolectric test tool, but it seems like robolectric cant find android jar files although android jar is running perfectly when i run the app by it self. My friend has a clone of the test and the app at his computer, and here i runs perfectly. What i wrong ?
Please help me out here.
This is the failure:
java.lang.NoClassDefFoundError: android/R
at org.robolectric.bytecode.Setup.(Setup.java:39)
at org.robolectric.RobolectricTestRunner.createSetup(RobolectricTestRunner.java:137)
at org.robolectric.RobolectricTestRunner.createSdkEnvironment(RobolectricTestRunner.java:114)
at org.robolectric.RobolectricTestRunner$3.create(RobolectricTestRunner.java:307)
at org.robolectric.EnvHolder.getSdkEnvironment(EnvHolder.java:21)
at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:305)
at org.robolectric.RobolectricTestRunner.access$300(RobolectricTestRunner.java:61)
And this is the app gradle file:
apply plugin: 'com.android.application'
apply plugin: 'robolectric'
apply plugin: 'idea'
android {
compileSdkVersion 18
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "com.kea.project.wheeloffortune"
minSdkVersion 16
targetSdkVersion 18
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest {
setRoot('src/test')
}
}
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'org.robolectric:robolectric-gradle-plugin:0.12.+'
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/commons-lang3-3.3.2.jar')
compile files('libs/picasso-2.2.0.jar')
compile files('libs/volley.jar')
compile files('libs/espresso-1.1.jar')
compile files('libs/testrunner-1.1.jar')
compile files('libs/testrunner-runtime-1.1.jar')
androidTestCompile files('lib/espresso-1.1.jar')
androidTestCompile files('lib/testrunner-1.1.jar')
androidTestCompile files('lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1'
androidTestCompile 'com.squareup.dagger:dagger:1.1.0'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
task addTest {
def src = ['src/test/java']
def file = file("app.iml")
doLast {
try {
def parsedXml = (new XmlParser()).parse(file)
def node = parsedXml.component[1].content[0]
src.each {
def path = 'file://$MODULE_DIR$/' + "${it}"
def set = node.find { it.#url == path }
if (set == null) {
new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"])
def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
file.text = writer.toString()
}
}
} catch (FileNotFoundException e) {
// nop, iml not found
}
}
}
gradle.projectsEvaluated {
preBuild.dependsOn(addTest)
}
robolectric {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}