How to implement code coverage into github android project (Travis CI, codecov) - android

I am now struggling with adding code coverage to my Android test project, can someone help?
https://github.com/zisean/CarbonContact-SCC-Group1
CI: Travis

You can read the error in this line, a permission denied.
You can fix it adding the next lines to your .travis.yml:
before_install:
- chmod +x gradlew
Alternatively, you can add the exec-permission to your gradlew script via git like this:
git update-index --chmod=+x gradlew

Related

cannot access './gradlew': No such file or directory Github actions

I am using workflow on GithubActions but getting the following error:
chmod: cannot access './gradlew': No such file or directory
Error: Process completed with exit code 1.
Following is my workflow.yml file
name: Android CI
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build
I tried you change chmod command in a different way but non of execution succeed, but same workflow on my other project is working file i don't know whats the issue, Any help highly appreciated. Thanks
I tried to change chmod command in a different way
That wouldn't change the fact the file itself (gradlew) seems to be missing.
I would check if it is anywhere (run: find / -type f -name "gradlew"), considering the actions/setup-java is supposed to include Gradle.
That would be just for testing, as a first step:
- name: Look for gradlew
run: find / -type f -name "gradlew"
- name: Change wrapper permissions
...
If it is in the $PATH, this issue suggests:
I changed
"./gradle build" to "gradle build" in Build with Gradle step.
That solved the issue. (see gradle-publish.yml)
Instead of using ./gradlew, try using gradle. This worked for me.
This solution here helped me solve the same problem. You just have to change the gradlew file permission using this code: Run this on the terminal
git update-index --chmod=+x gradlew
git commit -m "Make gradlew executable"
I also removed chmod +x from my workflow.yml file after changing the gradlew file permissions
I have faced the same issue and I found someone change it to
name: gradlew
run: gradle
enter image description here
with removing "./" and "w"
and worked for me
It's possible that you don't initialise wrapper.
You can try clone your repository from scratch and the exetuce ./gradlew build command. If it's failed. Try use the
gradle wrapper
This command init your wrapper and you can see which files was generated and required for ./gradlew
Finally, You have two options:
Run gradle wrapper locally and push required files
or
Add extra step to init wrapper during the workflow
...
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Init gradle wrapper
run: gradle wrapper
- name: Change wrapper permissions
run: chmod +x ./gradlew
- name: Build with Gradle wrapper
run: ./gradlew build

Job failed using Gitlab

I have used the Gitlab for run the CI plan.
Problem sequence:
Run the CI plan, with below yaml script, now CI getting passed
Again run the CI plan, now CI getting failed with below error code
warning: failed to remove MediaDrmCts/app/build/outputs/apk/debug/output.json: Invalid argument
Environment:
Gitlab runner in Windows PC
Shell
Yaml Code:
assembleDebug:
stage: build
script:
- echo 'start building...'
- cd MediaDrmCts
- ./gradlew clean assemble
artifacts:
paths:
- MediaDrmCts/app/build/outputs/
debugTests:
stage: test
script:
- cd MediaDrmCts
- ./gradlew -Pci --console=plain :app:testDebug
Error Log:
Please help us to resolve the issue?
This could be related to the issues in GitLab with killing processes on Windows:
tl;dr the windows runner (current version is around ~13.6 with no fix yet) can't kill the full tree of processes started in the job properly, so processes holding file locks are left around for the next job/pipeline to fail on when it attempts to clean up
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3185
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3121
I've had similar issues in the past and a workaround is to clean up troublesome directories in the job that makes them, rather than letting the git clean command clean them up in the next job.
One option:
debugTests:
stage: test
script:
- cd MediaDrmCts
- ./gradlew -Pci --console=plain :app:testDebug
after_script:
- if (Test-Path ./MediaDrmCts/app/build) { Remove-Item ./MediaDrmCts/app/build -Recurse -Force; }
...
Another option
If your builds aren't sensitive to how clean the repo folder is, then you can try turning off the git clean -ffdx step in your .gitlab-ci.yml file:
...
variables:
GIT_CLEAN_FLAGS: none
...
which will tell the GitLab runner not to attempt cleaning up the repository of extra files before each run.
Keep in mind that this may have some unintended consequences, such as the wrong files being left over from previous runs on other branches, so be wary, and have good tests!

Travis.yml ./gradlew : Permission denied

Using Travis CI for an existing Android project calling
$ ./gradlew build connectedCheck
I get this error:
/home/travis/build.sh: line 45: ./gradlew: Permission denied
The command "./gradlew build connectedCheck" failed and exited with 126 during .
It depends by the exec-permission to your unix gradlew script.
It can be fixed using the command:
git update-index --chmod=+x gradlew
A little desciption to understand the problem.
First of all you can check your permissions using:
git ls-tree HEAD
You will see:
100644 blob xxxxxxxxxxx gradlew
As you can see the file has 644 permission.
Fix it by setting the executable flag on your gradlew file changing it to 755:
git update-index --chmod=+x gradlew
Just commit and push the changes:
git commit -m "permission access for travis"
[master e80ab1b] gradlew permission access for travis
1 file changed, 0 insertions(+), 0 deletions(-)
mode change 100644 => 100755 gradlew
A last check running git ls-tree again to see the change:
git ls-tree HEAD
You can see:
100755 blob xxxxxxxxxxxxx gradlew
Another way to solve this issue is to use:
before_install:
- chmod +x gradlew
This kind of solution doesn't change the permission in your git repo, but just changes the permission runtime in the execution.
script:
- chmod +x ./gradlew build connectedCheck
Thanks all.
This code is available.
The key focus is on chmod +x

After upgrading Gradle to v2.8 Travis doesn't pass Findbugs

I just updated my gradle from version 2.2 to latest one 2.8. I didn't have any issue with findbugs on version 2.2.
I'm working on an Android project that contains two modules. In order to use find bugs in both modules I have following configuration on main build.gradle file of root directory.
configure(allprojects) {
apply plugin: 'findbugs'
task findbugs(type: FindBugs) {
ignoreFailures = false
effort = "max"
classes = fileTree('build/intermediates/classes/')
source = fileTree('src/main/java')
classpath = files()
excludeFilter = file("exclude.xml")
reportLevel = "high"
reports {
xml.enabled = false
html.enabled = true
}
}
}
When I run ./gradlew findbugs on my local machine everything is fine and build is successful however when I push my PR to Github and Trivis tries to build then I get error:
:findbugs UP-TO-DATE
:passenger-app:findbugs
:passenger-sdk:findbugs FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':passenger-sdk:findbugs'.
> FindBugs rule violations were found. See the report at: file:///home/travis/build/project-name/passenger-android/passenger-sdk/build/reports/findbugs/findbugs.html
I'm really confused why I have no problem on my local machine while Travis shows error! I tried to print out the contents findbugs.html on Travis but I got permission denied :(
I'm using java 1.8 while Travis is using 1.7. Does problem relates to this? Thanks
Update:
In order to print the contents of findbugs.html on Trivis I created a print_findbugs.sh and this is its contents.
#!/usr/bin/env bash
echo '**********************'
echo '*** Print Findbugs ***'
echo '**********************'
echo file:///home/travis/build/company/passenger-android/passenger-sdk/build/reports/findbugs/findbugs.html
Then I set sudo true in my .travis.yml file. What I have in this file.
sudo: true
language: android
android:
components:
- build-tools-23.0.1
- android-23
- extra-android-support
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
env:
global:
// some settings are there
before_cache:
# Delete the gradle lock file which forces creation of a new build cache
- rm ~/.gradle/caches/modules-2/modules-2.lock
cache:
directories:
- ~/.gradle
before_script:
# Overwrite the keystore if it is a pull request
- ./before_script.sh
script:
# Override Travis default script to not run connectedCheck until this bug is fixed:
# https://code.google.com/p/android/issues/detail?id=59592
- ./gradlew clean build findbugs -PdisablePreDex
- ./print_findbugs.sh
before_deploy:
# Clean up the output folder
# Link up the new builds into individual html files
- ./before_deploy.sh
after_deploy:
# Upload to...
and finally my travis prints:
:findbugs UP-TO-DATE
:passenger-app:findbugs
:passenger-sdk:findbugs
FindBugs rule violations were found. See the report at: file:///home/travis/build/company/passenger-android/passenger-sdk/build/reports/findbugs/findbugs.html
BUILD SUCCESSFUL
Total time: 8 mins 9.966 secs
The command "./gradlew clean build findbugs -PdisablePreDex" exited with 0.
$ ./print_findbugs.sh
/home/travis/build.sh: line 41: ./print_findbugs.sh: Permission denied
The command "./print_findbugs.sh" exited with 126.
before_cache
$ rm ~/.gradle/caches/modules-2/modules-2.lock
cache.2
Done. Your build exited with 1.
I don't use it and I need more information about the permission denied.
Html reports
In the past, I printed html reports using Travis-ci, point 5 here. I downloaded lynx using apt-get (it's not possible now using container-infrastructure and sudo: false) and converted and printed the reports.
before_script:
# - echo 'LOGCAT'
# Check logcat debug output: http://developer.android.com/tools/help/logcat.html
# Check debugging log: http://developer.android.com/tools/debugging/debugging-log.html
# Comment the lines belows to debug output and redirect it to a file. Custom tags for your app.
- adb -e logcat *:W | tee logcat.log > /dev/null 2>&1 &
after_failure:
# - echo 'FAILURE'
# Check apt configuration: http://docs.travis-ci.com/user/ci-environment/#apt-configuration
# Comment out the lines below to show log about tests with app name customized on exports section.
- sudo apt-get install -qq lynx
- export MOD_NAME=yourappmodulename
- export LOG_DIR=${TRAVIS_BUILD_DIR}/${MOD_NAME}/build/outputs/reports/androidTests/connected/
- lynx --dump ${LOG_DIR}com.android.builder.testing.ConnectedDevice.html > myConnectedDevice.log
- lynx --dump ${LOG_DIR}com.android.builder.testing.html > myTesting.log
- for file in *.log; do echo "$file"; echo "====================="; cat "$file"; done || true
Xml reports
Can be used in both, legacy and container based infrastructure.
I read you can enable xml reports like this:
reports {
xml.enabled = true
html.enabled = true
}
You can easily print xml reports on Travis-ci using cat like here:
- cat ${TRAVIS_BUILD_DIR}/ui/espresso/*/app/build/outputs/androidTest-results/connected/* # logs
Adding * will include all the subfolders at this point.
You need to first find locally the folder for the xml reports, in my case is not the same folder than html, and add to your travis.yml file something like this:
after_failure:
- cat /home/travis/build/*/passenger-android/passenger-sdk/build/reports/findbugs/*
This doesn't solve your issue but perhaps helps to find reason.
Update:
I suggest you to try to use cat and the xml version without the script first.
A good explanation about the permission issue here and how to solve it making the file executable:
before_script:
- chmod +x yourscript
Update 2:
A better approach to fix the permission denied issue explained here.
Use this and commit the changes:
git update-index --chmod=+x yourscript
In my case, ignoreFailures was true, but nevertheless the findbugs task was failing after upgrading gradle because build.gradle was depending on findbugs:annotations:3.0.0 instead of findbugs:findbugs-annotations:3.0.1. (Note: annotations vs. findbugs-annotations, which is a new artifact.
Finally I was able to get everything passed.
I first used following command rather than simple $ ./gradlew findbugs.
./gradlew clean aGD findbugs -PdisablePreDex
aGD is abbreviation of my task something like assembleDebug.
I could see a lot of complains by gradle. Probably Travis was showing this (afterDebug) but since it prints html page in console is not human readable. So I added filters into Findbug's exclude file (ref) in order to pass Findbugs check.
I was successful! Once I pushed my code, Travis failed again.
But since I printed out Findbug's output on Travis and there was only an issue I could find it in my code and Fix it. After that Travis didn't failed and passed my PR.
So the problem is still exist unfortunately. I can get Findbugs passed on my local project while Travis sometimes finds more issues. I'm suspicious that Travis is able to load recent versions of Findbugs but mine isn't able, due to cache things. But yes, this is my assumption!

Running android unit tests from the command line?

I'm trying to run unit tests on the android platform in accordance with tutorial. Say, for example, I want to run tests for Email application. I open /apps/Email/tests/AndroidManifest.xml file, look for the <manifest> element, and look at the package attribute, which is com.android.email.tests, and in the <instrumentation> element I look at the android:name attribute, which is android.test.InstrumentationTestRunner. Now I open the console, and run
$ . build/envsetup.sh
$ lunch 1
$ adb shell am instrument -w com.android.email.tests/android.test.InstrumentationTestRunner
But that fails:
INSTRUMENTATION_STATUS: id=ActivityManagerService
android.util.AndroidException: INSTRUMENTATION_FAILED: com.android.email.tests/android.test.InstrumentationTestRunner
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.android.email.tests/android.test.InstrumentationTestRunner}
So.. What am I doing wrong?
Please run
python development/testrunner/runtest.py email
and then you will see it works :).
Basically you do not have com.android.email.tests package installed.
You can see what is available for instrumentation
pm list instrumentation
And you should see
instrumentation:com.android.email.tests/android.test.InstrumentationTestRunner
(target=com.android.email)
And when doing
pm list packages
package:com.android.email
package:com.android.email.tests
You may need to setup a test project with the android create test-project command first. Check this page on the Android Dev site: Testing In Other IDE's for more info. I've used this method to enable command line testing with ant.
What I actually forgot to do was building and installing that test packages onto my device/emulator. Discovered that after doing:
$ adb shell
# cd data/packages
# ls
And no com.android.email.tests package there.
My issue was this tag:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for app.under.test.package"
android:targetPackage="app.under.test.package" />
Firstly I had the android:name attribute wrong then the target package wrong (above is the correct solution)
Test Package Not Installed on the Emulator
I had the exact same issue and realized that the test package hadn't been installed on the emulator, which is what #marekdef is saying.
Instead of using the command found in the generated test file, I used the following:
ant debug install test
*I had my test project in <project_home>/tests so the following command is what I ended up using from my project home directory:
(cd tests && ant debug install test;)
Hope that helps.
I received the "Unable to find instrumentation info" error under this condition: I defined my test project with a src package name that was the same as that of the project-under-test. For example, the source for both projects was in package com.mycompany.android. This parallel-src-package setup worked fine in Eclipse, but on the emulator it very much appeared that the test apk was overwriting the app apk.
Fix: I changed the src packge of the test project to test.mycompany.android.
Note that, in either case, the Android manifest for the test project defines:
< manifest package="pkg-of-project-under-test" ...>
and
< instrumentation android:targetPackage="pkg-of-project-under-test" ...>
For gradle user you can use the following tasks:
$ gradle :project:installDebug :project:installDebugAndroidTest
I have this run_all_test.sh script to run all unit and instrumented test:
#!/bin/bash
./gradlew --no-daemon clean test connectedCheck --stacktrace;
if [ $? -eq 0 ]
then
echo "tests are successful"
else
echo "tests FAILED"
exit 1
fi
Explanation:
test -> execute all unit test
connectedCheck -> execute all instrumented test
You can start from here to customize it based on your needs following the documentation here: https://developer.android.com/studio/test/command-line
[Android test types]
To run all tests from Command Line using gradlew[About]
JUnit test (UnitTest suffix)
./gradlew test
./gradlew :<moduleName>:test<variantName>UnitTest
Instrument test(AndroidTest suffix)
./gradlew connectedAndroidTest
./gradlew :<moduleName>:connected<variantName>AndroidTest
If you want just to build tests and don't run them use assemble
//Unit
./gradlew :<moduleName>:assemble<variantName>UnitTest
//functional
./gradlew :<moduleName>:assemble<variantName>AndroidTest

Categories

Resources