Gradle android test - android

I have project with next structure:
-project_dir
--libmodule
---src[main code path]
---test[test code path]
--app
---src[main code path]
I have just one test class with one test function inside inside project_dir/libmodule/test// folder.
I can run it from source file (I am using Android Studio). But if i try to run it using test gradle task, it has not found any tests. I have followed modified source configuration (just legacy yet, but seems it does not matter):
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
test {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['test']
resources.srcDirs = ['test']
aidl.srcDirs = ['test']
renderscript.srcDirs = ['test']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
Have you any ideas why test task doesn't see any tests?

If this is an android test, you need to set sourceDirs for configuration androidTest instead of test, or alternatively, instead of setting each of those srcDirs, you could do:
androidTest.setRoot('test')

Related

How to use different set of resources (images, themes, etc.) during builds in Android Studio?

We need to build different looking apps for different clients from the same source base. The app for each client has to be branded - i.e. must have different images, colors, etc. Most of the resources - e.g. layouts, strings - will be shared among all clients.
We are thinking of using sourceSet in build.gradle. For example:
android {
...
sourceSets {
Main {
// resources common to all clients
resSrcDirs = 'res'
// resources specific to client1
resSrcDirs += 'client1/res'
// resources specific to client2
//resSrcDirs += 'client2/res'
...
// The same approach taken for manifest that contains application theme
manifestSrcFile=client1/AndroidMainifest.xml
// manifestSrcFile=client2/AndroidManifiest.xml
...
}
}
}
Before each build we will uncomment/comment out selected lines in build.gradle.
We think that this would work but wonder if there is a better way of doing it.
You can use flavorDimensions,
android {
flavorDimensions "version"
productFlavors {
commom
client1
client2
}
}
then create your resource folder src/client1 & src/client2.
In the Build Variants window,you can switch which style to run or debug.Refer to the figure below.
If you selected client1Debug or client1Release,the resources in client1/res will override the resources of the same names in the main/res.
Your approach is right, divide the source set per client brand.
We had the same experience and we resolved it like:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['jniLibs']
}
brandA {
java.srcDirs = ['src_a']
res.srcDirs = ['res_a']
assets.srcDirs = ['assets_a']
}
brandB {
java.srcDirs = ['src_b']
res.srcDirs = ['res_b']
assets.srcDirs = ['assets_b']
}
brandC {
java.srcDirs = ['src_c']
res.srcDirs = ['res_c']
assets.srcDirs = ['assets_c']
}
}

Aagger2 could not generate the component file when using old Eclipse source stucture in Android Studio

The androidTest Code put in Project/tests/java folder is not in the Android Studio standard folder. (It's from an Eclipse project, so the folder structure is this way)
The DaggerSimpleTest_SimpleComponent could not be generated.
Dagger-compiler does not work for this?
---- ----------------build.gradle -----------------
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
androidTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
-------------------- SimpleTest.java --------------
#RunWith(AndroidJUnit4.class)
public class SimpleTest {
#Singleton
#Component( modules = {MockUserModule.class})
public interface SimpleComponent extends DemoComponent {
void inject(SimpleTest test);
}
#Before
public void setUp() {
// SimpleComponent component =
}
}
---------------------MockUserModule.java----------------
#Module
public class MockUserModule {
#Provides
#Singleton
User provideUser() {
return Mockito.mock(User.class);
}
}

gradle android plugin variant dependencies: DSL method not found

I have a multi-flavor project, with flavors called "qa" and "prod". I need to include different versions of a library depending on both the build type and the flavor.
The documentation at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Type-Product-Flavor-Build-Variant suggests that build types and flavors can be combined, using a "flavorBuildCompile" notation. However when I do this I get this error:
Error:(88, 0) Gradle DSL method not found: 'qaDebugCompile()'
I'm pretty sure this used to work (in an older version of gradle). Currently using gradle 2.1. I haven't found an explanation if the way to do this has changed.
Note, it works fine if I use "flavorCompile" notation, it only fails when I include the build type as well.
Here is the outline of my build script:
android {
compileSdkVersion 17
buildToolsVersion "20"
...
productFlavors {
qa {
applicationId "com.myapp.qa"
}
prod {
applicationId "com.myapp.prod"
}
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
qa {
res.srcDirs = ['res_qa']
}
prod {
res.srcDirs = ['res_prod']
}
}
}
...
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
qaCompile 'com.myapp.integration:other_lib:3.0+#aar' //this is fine
qaDebugCompile 'com.myapp.integration:mylib_qa:3.0+#aar' //this fails!
prodDebugCompile 'com.myapp.integration:mylib_prod:3.0+#aar'
qaReleaseCompile 'com.myapp.release:mylib_qa:3.0+#aar'
prodReleaseCompile 'com.myapp.release:mylib_prod:3.0+#aar'
}

Robotium test case is not working with gradle

I am using Robotium for my test case. When i am using eclipse for run a test case it is working and showing 2 fail result but when i am using gradle for test case it is showing BUILD SUCCESSFUL.But in my code 2 fail results.
I am using this command - gradle clean connectedCheck build
My build.gradle file--
buildscript { repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('MyTestCase')
instrumentTest {
java.srcDirs = ['MyTestCase/src']
manifest.srcFile file('MyTestCase/AndroidManifest.xml')
resources.srcDirs = ['MyTestCase/src']
res.srcDirs = ['MyTestCase/res']
assets.srcDirs = ['MyTestCase/assets']
}
}
dependencies {
compile files('libs/android-support-v4.jar')
}
lintOptions {
abortOnError false
}
}

Gradle Android buildTypes overriding each other

I'd appreciate any help with this since I'm a noobie w/ gradle. I've got a build script with multiple buildTypes, but it appears settings for one of them are overwriting the others.
Here's my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.2'
}
}
apply plugin: 'android'
dependencies {
compile project(':facebook-android-sdk-3.0.1:facebook')
compile project(':google-play-services_lib')
compile project(':nineoldandroids')
compile project(':SlidingMenu-master:library')
compile project(':ViewPagerIndicator')
compile project(':volley')
compile project(':windowed-seek-bar')
compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
}
android {
buildToolsVersion "17.0"
compileSdkVersion 17
signingConfigs {
debug {
storeFile file('keystores/debug.keystore')
}
release {
storeFile file('keystores/release.keystore')
storePassword "***"
keyAlias "***"
keyPassword "***"
}
}
buildTypes {
debug {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'normal']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
release {
signingConfig signingConfigs.release
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src', 'normal']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
utest {
debuggable true
signingConfig signingConfigs.debug
sourceSets {
main {
manifest.srcFile 'utest/AndroidManifest.xml'
java.srcDirs = ['src', 'utest']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
}
}
The settings for utest are overriding the settings for release and debug. Anybody know why?
Your usage of source sets is wrong. It is not inside each build type closure. They are declared on their own:
android {
buildTypes {
debug {
...
}
release {
...
}
utest {
...
}
}
sourceSets {
debug {
...
}
release {
...
}
utest {
...
}
}
}
Note that the build types have their own source sets on top of the 'main' source sets. So you shouldn't set all the build type sourceset to use 'src'. You could do
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
utest {
manifest.srcFile 'utest/AndroidManifest.xml'
java.srcDirs = ['utest']
}
}
}
Note that in this case the manifest under utest/AndroidManifest.xml will be merged in the main manifest.

Categories

Resources