Travis.yml ./gradlew : Permission denied - android

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

Related

Github actions ./gradlew test can't find directory to run unit test

I set up a simple CI work in Github Action for my Android project (Kotlin) that would init unit testing before merging with the master (main) branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout#v3
# Setup JAVA
- name: set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
# Execute unit tests
- name: Unit Test
run: chmod +x ./gradlew test
But whenever i push any commit into directory, i receive next error which fails Unit tests and block merging:
Run chmod +x ./gradlew test
chmod +x ./gradlew test
shell: /usr/bin/bash -e {0}
env:
JAVA_HOME_8.0.342_x64: /opt/hostedtoolcache/jdk/8.0.342/x64
JAVA_HOME: /opt/hostedtoolcache/jdk/8.0.342/x64
JAVA_HOME_8_0_342_X64: /opt/hostedtoolcache/jdk/8.0.342/x64
chmod: cannot access 'test': No such file or directory
Error: Process completed with exit code 1.
I tried to manually set up a directory with tests using working-directory: app/src/ but it throws the same type of error.
What I am doing wrong?
Will provide more info on request. Thanks in advance.
ANSWER: To run unit test in pre-merge, you need to set the correct directory, with the working-directory:, In my case it's :
./app/src/
Changes in workflow .yaml
# List all files (Optional)
- name: ls
run: ls -alrth
- name: add permisiion to gradlew
run: chmod +x ./gradlew
# Execute unit tests
- name: run unit tests
working-directory: ./app/src/
run: chmod +x ./test
I would make multiple RUN commands to ensure where I am and what is in the current folder:
run: pwd
run: ls -alrth
run: chmod +x ./gradlew
run: chmod +x ./test
AS noted by the OP GremlinShX, a working-directory: ./app/src was missing.

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!

CircleCI ./gradlew: Permission denied

I have a Github repository, which is builded on CircleCI. I get following error:
export TERM="dumb" if [ -e ./gradlew ]; then ./gradlew
dependencies;else gradle dependencies;fi bash: line 2: ./gradlew:
Permission denied
export TERM="dumb" if [ -e ./gradlew ]; then ./gradlew
dependencies;else gradle dependencies;fi returned exit code 126
Action failed: gradle dependencies
I can't get what is this caused by, because I give necessary permissions in circle.yml file.
test:
override:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-21.1.2,android-21,extra-google-m2repository,extra-google-google_play_services,extra-android-support
- chmod 777 gradlew
- chmod a+x gradlew
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
- ./gradlew testVanillaDebugUnitTest -PdisablePreDex
- echo "y" | sudo /opt/google-cloud-sdk/bin/gcloud beta test android run --app app/build/outputs/apk/app-vanilla-debug.apk --test app/build/outputs/apk/app-vanilla-debug-androidTest.apk --device-ids Nexus5 --os-version-ids 22 --locales en --orientations portrait
run: chmod +x gradlew
run: ./gradlew assemble
So, first set permission, then run the command you want
Looking at you circle.yml (found here), the failure is not from lines #25 or #26, it's line #14.
Please notice that order of execution is
dependencies:pre
dependencies:post
test:override
test:post
So what you need to do is remove lines 23, 24 and add chmod +x gradlew as the first command in dependencies:pre

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

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

Categories

Resources