android library unit testing gradle file - android

I have an android library project.
I can run the android tests in android studio.
I am not sure how to trigger the tests from the gradle file.
Tried few things but nothing helped. Folder structure is src/main and src/androidTest
Gradle file is below:-
...
sourceSets {
androidTest.setRoot('src/androidTest/java')
androidTest.java.srcDirs = ['src/androidTest/java']
}

Your task for testing should include your flavor and build type.
Firstly, you can check available tasks using
gradle tasks --all
if it fails, check why
gradle tasks --stacktrace
In the output you'll see all the tasks, that are available.
I'm shure that you can run unit-tests, that are under /test folder.
I didn't find the task for running instrumentation tests that are under /androidTest.
If you created unit-tests under /androidTest, I'd recommend you to use
Robolectric and move them to /test folder, it's pretty easy. After that you'll be able to run them with gradle.

Related

Run Ktlint for all modules by executing single task command

I have multiple modules in my android project. I have one Gradle file which having code for ktlint. I applied that Gradle file to every module by writing this in the project Gradle file.
subprojects { subProject ->
apply from: "$project.rootDir/commonFiles/gradleScript/kotlin-code-quality.gradle"
}
now the problem is I can run ktlint on each module by giving their name in command like this.
Running ktlint for cache module.
./gradlew :cache:ktlint
but I need to run all modules ktlint at once.
Here is my open-source repository and pull request on which I need to perform ktlint action.
Sorry, it's my bad. ./gradlew ktlint will always run on multimodule. I had some lint checks fail in the app module. I thought it is running only on the app module.
but when I fixed the app module's lint and ran the ./gradlew ktlint. it jumped to the cache module.
I hope it helps you Thanks.

Android build gradle dependencies

I have an app with 2 libraries as dependencies. I'm trying to build a script that clones those libraries into an empty folder and build the project.
I created a task within the app's build.gradle that clones the repos:
exec { commandLine "git", "clone", repo, repoFolderName }
The script starts and clones the repos, all fine but when it starts building the app if fails with the following error:
"Could not determine the dependencies of task ..."
If I run the script again it will successfully build the project.
From my initial investigation it seems that Gradle creates the dependencies as the 1st thing, before the libraries are locally cloned so the libraries are not there hence the build fails. If I run it again as the libraries are already there it will successfully build the project.
Any help is much appreciated.

Gradle dependency tree for "test" task different in different projects

I am running "gradlew test" task in my 2 android projects- in one it has a dependecy on mergeDebugAssets task while in other it doesn't have.
Though I want my "gradlew test" task to have dependency on mergeDebugAssets because otherwise I am not able to access assets from folder- build/intermediates/bundles/debug in my test.
I don't think it is appropriate to explicitly modify test task for this.
Also, should it depend on android sdk or buildtools version or gradle version? Though I kept the gradle version of 2 projects same but same is happening. Where am I missing?

Configure Bamboo for Android Gradle based Project

I am trying to setup Bamboo for my Gradle build system based Android Project.
I have done the following setup on Bamboo.I'm done with rest of all setup upto project repository path.
I want to run the following tasks using gradlew for android
clean assembleDebug LintDebug
For that I have created new task called Gradle Wrapper.
Below is the Gradle Wrapper Configuration
When I am executing gradle wrapper task, I am getting the following error.
Caused by: java.lang.IllegalStateException: Cannot find executable 'D:\AndroidDemo\gradle-2.10\bin\gradlew.bat'
Note :- Standalone Gradle is working fine on local machine with all the tasks(clean assembleDebug LintDebug)
Gradle_Home = D:\AndroidDemo\gradle-2.10\bin(Local machine)
Can anyone suggest a solution for the same?
I also had some initial difficulties to set up Bamboo to build an Android project using Gradle.
First of all, make sure that you have the Gradle wrapper (gradlew) in your repo. (Seemingly that's the situation in your case). It seems to me, however the Gradle wrapper ignores the system default Gradle distribution (set by the GRADLE_HOME env var), and always downloads a Gradle version mandated by the Android Build tools.
Also make sure, that the Android SDK root environment variable (ANDROID_HOME or ANDROID_SDK_ROOT) is pointing to the SDK's root directory (e.g. $ export ANDROID_HOME="/opt/android-sdk/")[1].
Restart Bamboo after applying the environment variable changes.
In Bamboo, in the build tasks lists, add a new Script task. The interpreter should be '/bin/sh or cmd.exe', the script location should be 'inline', and the script body should contain the call for the parametrized Gradle wrapper, e.g.
gradlew clean build
Point the working subdirectory to the Gradle wrapper's relative location (to the repo root), if necessary.
[Sample Bamboo Android Gradle build script]
After these steps, Bamboo should execute the Gradle wrapper, which in fact should perform the actual build steps.

android studio use sync project with gradle files action

I want to use sync project with gradle file in command line but I dont know how to do
like this :
It besides do ./gradlew build also do other things
For example, in a file is written to a local library name android-test
than in settings.gradle read this file and call include ":${android-test}" .if I use AS sync project with gradle files button,AS can load
module to project , but when I run ./gradlew build, it doesn't work.
But I have developed a plugins, and I want to use this action, so how to call this function ?
Building and syncing from the command line is really simple. In the root of your project you can invoke the gradle wrapper's build command with
./gradlew build
To get a list of all available build tasks for your project:
./gradlew tasks
"./gradlew build" and "./gradlew tasks" in the path of your project.
more commands and steps here:https://developer.android.com/studio/build/building-cmdline.html
The action id is Android.SyncProject, so you can call it in your plugin:
ActionManager.getInstance().getAction("Android.SyncProject").actionPerformed(e);
You can find it in android-plugin.xml, maybe line 161.
Also in SyncProjectAction.java, line 36 you can find its text.

Categories

Resources