How to execute all Android JUnit tests in Appcenter post-build script - android

I am new to Android builds with AppCenter and wish to execute all my Apps JUnits.
My app consists of multiple modules that each have their associated JUnits.
However my main App module has no JUnits.
I've tried creating an appcenter-post-build.sh script to execute command ./gradlew test
which fails as follows:-
[command]/bin/bash /Users/runner/work/1/s/app/appcenter-post-build.sh
/Users/runner/work/1/s/app/appcenter-post-build.sh: line 5: ./gradlew: No such file or directory
##[error]The process '/bin/bash' failed with exit code 127
##[error]Bash failed with error: The process '/bin/bash' failed with exit code 127
is there any way I can execute all my Apps modules JUnits via a post build script?

try to add this in your shell script.
cd $APPCENTER_SOURCE_DIRECTORY
chmod a+x ./gradlew

Related

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!

How to fix cp issue during build with ninja?

I am currently compiling a custom recovery for an android phone. Sources are synced, device tree etc. all set up correctly. Now I am facing a rather banal-looking error during build. cp refuses to copy a directory, because -r is not specified in the build file.
I obviously tried to find the build file (rw_recovery/out/build_omni_daisy.ninja) and add the -r argument, but it seems to be regenerated at the beginning of every build process, as the process still fails and the previously changed line appears unchanged when opening the file after the attempted build.
These are the build steps:
. build/envsetup.sh
lunch omni_daisy-eng #config for the device
mka bootimage #device uses boot.img as recovery
This command leaves me with the following error:
[ 99% 6883/6884] Prebuilt (rw_recovery/out/target/product/daisy/kernel)
FAILED: rw_recovery/out/target/product/daisy/kernel
/bin/bash -c "(rm -f /home/luca/rw_recovery/out/target/product/daisy/kernel) && (cp rw_recovery/out/target/product/daisy/obj/KERNEL_OBJ/arch/arm64/boot/ rw_recovery/out/target/product/daisy/kernel )"
cp: -r not specified; omitting directory 'rw_recovery/out/target/product/daisy/obj/KERNEL_OBJ/arch/arm64/boot/'
ninja: build stopped: subcommand failed.
17:13:06 ninja failed with: exit status 1
I would love to hear any suggestions about how to force ninja to execute the command with -r. Alternatively, suggestions about where to find the file from which the above mentioned build file is recreated after executing mka command are much welcomed as well.

cordova android build failure: processArmv7DebugResources

I'm building a hybrid app with cordova. The setup has been tested with simple application. Both android and iOS build works fine.
After switching to a more complex application, the following error occurred. I googled and found some suggested solution but none of the worked.
I'm new to this so any suggestion appreciated.
:processArmv7DebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':processArmv7DebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/23.0.2/aapt'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 28.659 secs
ERROR building one of the platforms: Error code 1 for command: /Users/wliang/work/hzoom/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/wliang/work/hzoom/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true
You may not have the required environment or OS to build this project
Error: Error code 1 for command: /Users/wliang/work/hzoom/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/wliang/work/hzoom/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true
In my case I discovered the error with the follow command:
cordova build android -- --gradleArg=--info
I have found:
Executing task ':processArmv7DebugResources' (up-to-date check took 0.009 secs) due to:
Input file /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/assets/armv7/debug/www/libs/long/dist/long.min.js.gz has been added.
Starting process 'command '/Users/astaniscia/Library/Android/sdk/build-tools/24.0.2/aapt''. Working directory: /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android Command: /Users/astaniscia/Library/Android/sdk/build-tools/24.0.2/aapt package -f --no-crunch -I /Users/astaniscia/Library/Android/sdk/platforms/android-23/android.jar -M /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/manifests/full/armv7/debug/AndroidManifest.xml -S /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/res/merged/armv7/debug -A /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/assets/armv7/debug -m -J /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/generated/source/r/armv7/debug -F /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/res/resources-armv7-debug.ap_ --debug-mode --custom-package com.navionics.poc -0 apk --output-text-symbols /Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/symbols/armv7/debug --no-version-vectors
Successfully started process 'command '/Users/astaniscia/Library/Android/sdk/build-tools/24.0.2/aapt''
Unable to add '/Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/assets/armv7/debug/www/libs/long/dist/long.min.js.gz': file already in archive (try '-u'?)
ERROR: unable to process assets while packaging '/Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/res/resources-armv7-debug.ap_'
:processArmv7DebugResources FAILED
:processArmv7DebugResources (Thread[Daemon worker Thread 16,5,main]) completed. Took 0.312 secs.
and this line helped me
Unable to add '/Users/astaniscia/Workspace/webapp3.0/webapp3.0/platforms/android/build/intermediates/assets/armv7/debug/www/libs/long/dist/long.min.js.gz': file already in archive (try '-u'?)
for me solve the problem... I removed the gzip and now all work fine!
I had the same issue and this is what I found to be the issue.
The bower components folder - which normally defaults to www/lib/ using cordova - was the culprit in my case.
I had modified one of the bower components, to do that I had to first run npm install inside the specific package that I was updating. After doing that there was a node_modules folder inside the specific component I was updating i.e. www/lib/{name_of_component}/node_modules. Basically this specific node_modules folder is only used for build tools concerning the specific component, and thus it is not needed once you are done updating it and want to build the whole app. Some of the modules inside that specific component's node_modules may conflict with the projects node_modules i.e. {your_app}/node_modules - this can cause problems. In my case the conflict was with the semver module.
So in my case the solution was to delete that specific node_modules folder. After that I could build my app without any issues.
Hopefully this helps.
This is an old issue, but I recently came upon the same one and hope my experience might help someone else in the future.
After a solid day of looking around I realized it had to do with my plugins. For some reason there was an unused dependency in package.json that wouldn't allow it to build.
In my case, it was Firebase, and after removing it from package.json and the plugins folder I ran
cordova platform remove android
and
cordova platform add android
then built it again and all of a sudden it was up and running!
This error shows up because you have one or several accentuated filenames in your project folder. In my case, it was an image with the char "ç".
This topic can help rename automatically: https://superuser.com/questions/617517/remove-all-illegal-characters-from-all-filenames-in-a-given-folder
For me it was the node_modules folder inside www that caused the problem.
The solution is to copy your www to another folder and exclude node_modules and you will be fine.
The thing that worked for me :
cordova plugin add cordova-android-support-gradle-release
Thanks to lohith95
from https://forum.ionicframework.com/t/android-build-broken-after-gradle-dependencies-update-execution-failed-for-task-processdebugresources-com-android-ide-common-process-processexception-failed-to-execute-aapt/109982/170
This is might because you use crosswalk,
You can try the following commands:
sudo ionic cordova platform remove android 
sudo rm -rf ./node_modules
sudo npm install --unsafe-perm=true --allow-root
sudo npm install --unsafe-perm node-sass
sudo ionic cordova platform add android#6.4.0 
sudo ionic cordova plugin add cordova-android-support-gradle-release
sudo ionic cordova build android 

mobile App with ionic

hello
I am trying to build hybrid app with ionic and cordova
at first i run below commands and they run successfully
but after running the last command i get this error
ionic start firtApp
cd firtApp
ionic platform add android
note: it return me android-21 error, and i changed the android-21 to android-18, and it runs successfully
ionic build android
after running the above command i got this error
BUILD FAILED
D:\New folder\android-sdk-final\android-sdk-fully\sdk\tools\ant\build.xml:601: T
he following error occurred while executing this line:
D:\New folder\android-sdk-final\android-sdk-fully\sdk\tools\ant\build.xml:542: U
nable to resolve project target 'android-21'
Total time: 1 second
C:\Users\Mohammad\firstapp\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "ant debug -f C:\Users\Mohammad\f
irstapp\platforms\android\build.xml -Dout.dir=ant-build -Dgen.absolute.dir=ant-g
en"
ERROR building one of the platforms: Error: C:\Users\Mohammad\firstapp\platforms
\android\cordova\build.bat: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: C:\Users\Mohammad\firstapp\platforms\android\cordova\build.bat: Command f
ailed with exit code 8
at ChildProcess.whenDone (C:\Users\Mohammad\AppData\Roaming\npm\node_modules
\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:131:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
please help me with this error
i really like to bulid hybrid apps with my web knowledge
thanks.
You can try this
Go to this directory
C:\Users\Mohammad\.cordova\lib\npm_cache\cordova-android\3.6.4\package\framework
Edit project.properties file. Change target to 19.
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-19
apk-configurations=
renderscript.opt.level=O0
android.library=true
Restart your terminal.
You don't have SDK correctly installed on you computer. (Path or SDK update)
It's write on your error log : You may not have the required environment or OS to build this project
you just need to install ant
sudo apt-get install ant
then do the same as before,its work correctly

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