CircleCI ./gradlew: Permission denied - android

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

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.

How to run ./gradlew command from folder?

to build apk I'm running the command from terminal:
> ./gradlew app:assembleDebug
So I put the command to MyProject/myBashFile.shand run from terminal:
> bash myBashFile.sh
File myBashFile.sh:
#!/bin/bash
./gradlew app:assembleDebug
But when I put the file to dir MyProject/bushFiles/myBashFile.sh and trying to run the command:
> bash bushFiles/myBashFile.sh
Error is:
./gradlew: No such file or directory
Found solution in result MyProject/bushFiles/myBashFile.sh is:
#!/bin/bash
././gradlew app:assembleDevelop

CircleCI "Some errors occurred while attempting to infer information about your code"

I'm trying to build an Android project using CircleCI, but every time I run a build, the build completes in the Configure Build task and I get this message:
Some errors occurred while attempting to infer information about your code.
Also, when this occurs, CircleCI automatically tries to rebuild the branch, causing a loop, because every new build keeps failing.
Here's my circle.yml file
version: 1
machine:
java:
version: oraclejdk8
environment:
# Java options
JAVA_OPTS: "-Xms512m -Xmx2048m"
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
dependencies:
pre:
# Install the android packages
- echo y | android update sdk --no-ui --all --filter "build-tools-25.0.3"
test:
pre:
override:
# Generate a debug-apk
- ./gradlew assembleAppseeOffDebug -PdisablePreDex
# Copy the generated apk files to Circle-CI Artifacts
- cp -r app/build/outputs/apk/ $CIRCLE_ARTIFACTS
# Copy the test results to Circle-CI Artifacts
- cp -r app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
Solved the problem by following this circle.yml example
In 1, after the test tag there's an override tag, but in my circle.yml file there's a pre tag. Removing that pre tag solved the problem.
Final circle.yml file
version: 1
machine:
java:
version: oraclejdk8
environment:
# Java options
JAVA_OPTS: "-Xms512m -Xmx2048m"
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
dependencies:
pre:
# Install the android packages
- echo y | android update sdk --no-ui --all --filter "build-tools-25.0.3
test:
# REMOVED pre TAG
override:
# Generate a debug-apk
- ./gradlew assembleAppseeOffDebug -PdisablePreDex
# Copy the generated apk files to Circle-CI Artifacts
- cp -r app/build/outputs/apk/ $CIRCLE_ARTIFACTS
# Copy the test results to Circle-CI Artifacts
- cp -r app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS

How to setup CircleCI environment JAVA7_HOME for RetroLambda

I am using retrolambda in my Android application, and using circleci.com as continuous integration for my github repo.
the problem is I have configured my local mac environment for Java_Home and Java7_Home, and everything is okay, but I don't know how to config circleci yml file for this problem.
here is my application repo:
https://github.com/mmirhoseini/weather_app
here is my local configurations on .bash_profile file:
export JAVA_HOME=`/usr/libexec/java_home`
export JAVA7_HOME=`/usr/libexec/java_home -v 1.7`
this is my circleci.yml file:
#
# Build configuration for Circle CI
#
general:
artifacts:
- /home/ubuntu/weather_app/app/build/outputs/apk/
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
java:
version: openjdk8
dependencies:
override:
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-23.0.3,android-23,extra-google-m2repository,extra-google-google_play_services,extra-android-support
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
test:
override:
- (./gradlew assemble):
timeout: 360
- (./gradlew test):
timeout: 360
and here is the circleci error log:
> Building 10%When running gradle with java 8, you must set the path to the old jdk, either with property retrolambda.oldJdk or environment variable JAVA5_HOME/JAVA6_HOME/JAVA7_HOME
please help...
finally problem solved, I prepared environment by downloading older java version and setting Java6_home and after that build and run my tests.
here is my circleci.yml file:
#
# Build configuration for Circle CI
#
general:
artifacts:
- /home/ubuntu/weather_app/app/build/outputs/apk/
- /usr/lib/jvm/
machine:
environment:
ANDROID_HOME: /usr/local/android-sdk-linux
JAVA6_HOME: /usr/lib/jvm/java-6-openjdk-amd64
java:
version: openjdk8
dependencies:
override:
- echo y | sudo apt-get update
- echo y | sudo apt-get install libpango-1.0-0
- echo y | sudo apt-get install openjdk-6-jre
- echo y | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-23.0.3,android-23,extra-google-m2repository,extra-google-google_play_services,extra-android-support
- ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies
test:
override:
- (./gradlew assemble):
timeout: 360
- (./gradlew test):
timeout: 360

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

Categories

Resources