I am trying to import a custom tool into the pipeline Jenkinsfile script (specifically, the Android SDK). From the build console, it says that I need to set the ANDROID_HOME environment variable to build my Android app. However, when I tried adding the SDK download and set it to the ANDROID_HOME variable, it's telling me that the directory does not exist:
Caused by: java.lang.RuntimeException: The SDK directory '/var/jenkins_home/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/Android_SDK_CLI_tools_4333796/bin' does not exist.
In the global tools configuration page, here's how I added the Android SDK:
Name: Android_SDK_CLI_tools_4333796
Tool home: bin
Command: (below)
if [ ! -f "Android_SDK_tools_4333796/" ]; then
echo "curl"
curl -O https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
echo "unzip"
yes | unzip -q sdk-tools-linux-4333796.zip
rm sdk-tools-linux-4333796.zip
echo "licenses"
yes | tools/bin/sdkmanager --licenses
fi
Below is how I set my Jenkinsfile:
pipeline {
agent any
environment {
ANDROID_HOME = tool 'Android_SDK_CLI_tools_4333796'
//ANDROID_HOME = tool name: 'Android_SDK_CLI_tools_4333796', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool' //alternative but still has the same results.
//env.PATH = "${env.PATH}:${androidSDKHome}"
}
tools {
jdk 'JDK_9.0.4'
}
stages {
stage('Pre-build') {
steps {
// seeing if Java JDK installed correctly
sh 'java --version'
print (env.ANDROID_HOME) // prints: /var/jenkins_home/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/Android_SDK_CLI_tools_4333796/bin
}
}
stage('Test') {
steps {
echo 'Testing stage...'
sh './gradlew clean --stacktrace' //ERROR (above)
}
}
}
}
My question is, am I pulling in this custom tool into the build properly? It seems Jenkins can't find it the custom tool even though I trying to access the absolute path.
I tried referencing this SO question; However, this is for me to obtain the executable whereas I'm looking to set the env var for Gradle to pick up the ANDROID_HOME env var automatically.
Ok, after struggling with this for the past few days, I realized many new things, the most important was how the dir structure has to be for commands to work.
The folder structure should be in this layout:
/<unpacked_location>
/tools
/bin
...
/build-tools
/licenses
/platforms
From there, everything should fall like dominos. My problem was, when Jenkins unpacks the Android SDK cli tools download, I was setting the home to bin. That's wrong since when you unpack the Android SDK, /bin is located inside the /tools dir. Jenkins kinda confused me by not allowing me to leave the home dir blank (makes sense since you can also set absolute paths if needed), so I set it to the present working dir (. in this case).
The other major thing that I was missing was installing the latest Android SDK version. I just added this to the global tool config script for Android SDK:
yes | tools/bin/sdkmanager "build-tools;28.0.3"
Related
MacOS Monterey version 12.4
I'm trying to run a simple pipeline script on my jenkins job
pipeline {
agent any
stages {
stage('Build') {
steps {
sh('emulator -list-avds')
}
}
}
But it throws an error:
/Users/<my_username>/.jenkins/workspace/<my_job_name>#tmp/durable-22217e91/script.sh: line 1: emulator: command not found
My question is: why is it executing commands in the tmp folder? Anything "emulator" related does work when I run commands via terminal.
Following this answer, I've confirmed I'm in the correct dir
Why Jenkins mounts a temporary volume in addition to the workspace?
You are getting this error because the emulator executable is not set in the PATH. Try something like the below.
Try setting your PATH variable to add emulator executable.
environment {
PATH = "/PATH_EMULATOR/bin:${env.PATH}"
}
or something like the below.
withEnv(["PATH+EMULATOR=/PATH_EMULATOR/bin"]) {
sh('emulator -list-avds')
}
or you can also use the full qualified path to the executable
sh('/PATH_TO_EMULATOR/bin/emulator -list-avds')
In the Android project that I am working on, we are using GitLab CI/CD to automatically build and upload in Diawi the .apk file. In current settings build application's name is static because it needs to be known and sent to the Diawi framework as a curl request. The script looks like this:
- ./gradlew assembleRelease && cp app/build/outputs/apk/release/app-release.apk app-release.apk && curl -v --http1.1 https://upload.diawi.com/ -F token=$DIAWI_TOKEN -F file=#app-release.apk -F find_by_udid=0 -F callback_emails="mymail#company.com"
But this causes some troubles during the manual testing because the .apk files with the same name can be easily mistaken or overwritten.
My idea is to add some metadata in the .apk file's name to be unique and to avoid such errors. Do you have any ideas about how this could be done?
First thing you can do is create version bump functionality. You can do it via version bumping tool and git sync.
For version bumping you can use our open source tool - https://github.com/relizaio/versioning . Now, assuming that you sync via a file called apk_version, you first initialize this file with the current version like:
docker run --rm relizaio/versioning -s YY.0M.Patch > apk_version
Then in your CI context, you can bump it with something like
docker run --rm relizaio/versioning -s YY.0M.Patch -v $(cat apk_version) -a bump > apk_version
Now, in GitLab CI you need to have a block that resolves this. Note, that you also need to commit apk_version file at the end of the bump.
For inspiration - see this question How to grant permission for semantic-release to push code to master and also our sample CD project on GitLab - https://gitlab.com/taleodor/sample-helm-cd/-/blob/master/.gitlab-ci.yml
Also my article here may be helpful (note it's a bit outdated at this point): https://worklifenotes.com/2020/02/27/automatic-version-increments-with-reliza-hub-2-strategies/
Finally, for other things that you can add to version GitLab has a list of pre-defined env variables that you can use in whole or partially as modifiers: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
I'm working on Ionic project now whereby I want to zipalign the android-release-unsigned.apk file. I followed this guide by Ionic.
When I run zipalign -v 4 /Users/zulhilmizainudin/Desktop/kl-parking/platforms/android/build/outputs/apk/android-release-unsigned.apk android-release.apk command, I get -bash: zipalign: command not found error.
This is where zipalign sit in my system:
/Users/zulhilmizainudin/Library/Android/sdk/build-tools/21.1.2
I tried to copy zipalign inside it and put it inside my Ionic project folder and run the zipalign command again. But still get the same command not found.
What should I do now?
Solved!
I copied zipalign file from my Library/Android/sdk/build-tools/21.1.2 into my Ionic project folder
I add ./ in front of the zipalign command like this - ./zipalign -v 4 /Users/zulhilmizainudin/Desktop/kl-parking/platforms/android/build/outputs/apk/android-release-unsigned.apk android-release.apk
Done. Now I get android-release.apk inside my Ionic project folder.
Thanks to Michael for the solution!
If you're using Windows, the right way is to add path to zipalign.exe as PATH environment variable.
Finding where zipalign.exe is located in your PC, in my case this was
C:\Users\random-username\AppData\Local\Android\sdk1\build-tools\24.0.1
Then add this location as one of the entries in your PATH environment variable.
To avoid specifying or navigating to your sdk/build-tools/* directories each time you intend to build release version, you can simply add the path to your environment variable.
$ sudo nano ~/.bash_profile
copy and paste the below:
export PATH=${PATH}:/Library/Android/sdk/build-tools/21.1.2
You can then save and exit:
control + o // to save to file
control + x // to close the file
$ source ~/.bash_profile
You can then run your zipalign command from your project CLI directory.
This worked for me on Mac. Install and run Android Studio (important to start it one time).
Then find zipalign:
find ~/Library/Android/sdk/build-tools -name "zipalign"
Windows
the right way is to add path to zipalign.exe as PATH environment variable.
Finding where zipalign.exe is located in your PC, in my case this was
C:\Users\username\AppData\Local\Android\sdk1\build-tools\29.0.2
Then add this location as one of the entries in your PATH environment variable.
MAC
To avoid specifying or navigating to your SDK/build-tools/* directories each time you intend to build a release version, you can simply add the path to your environment variable.
$ sudo nano ~/.bash_profile
copy and paste the below:
export PATH=${PATH}:/Library/Android/sdk/build-tools/21.1.2
You can then save and exit:
control + o // to save to file
control + x // to close the file
$ source ~/.bash_profile
You can then run your zipalign command from your project CLI directory.
if you are making ionic release build then you can make build.json file on your app's root folder with these information given below
{
"android": {
"release": {
"keystore": "Your keystore",
"storePassword": "password",
"alias": "alias name",
"password" : "password",
"keystoreType": ""
}
} }
make sure that you can place your keystore on your app's root folder or provide full path of your keystore at keystore object
now just you can run this command as below
ionic cordova build android --release
this command automatically find your build.json and make signed release build.
Solved!
I copied zipalign file as Michael Said
( from my Library/Android/SDK/build-tools/28.0.3 into my Ionic project folder)
BUT when I run
./zipalign -v 4 app-release-unsigned.apk botellamovil.apk
I got
./zipalign: ERROR while loading shared libraries: libc++.so: cannot open shared object file: **No such file or directory**
So, I also copied lib & lib64 files, and then it Works!!
I hope it will be helpful :) (and sorry for my English)
You should do (align, sign, and verify)for APK.
In mac, you should do the following steps:
A - Aligning APK:
1- you should locate zipalign your build tools inside android SDK:
/Users/mina/Downloads/sdk/build-tools/29.0.3/zipalign
2- you should locate your unsigned apk:
/Users/mina/Desktop/apks/app_unsigned.apk
3- you should run command contains:
zipalign_path + -v -p 4 + unsigned_apk_path + output_aligned_apk_name
/Users/mina/Downloads/sdk/build-tools/29.0.3/zipalign -v -p 4
/Users/mina/Desktop/apks/app-unsigned.apk app_aligned.apk
4- output is Verification successful
B - Signing APK:
1- you should locate apksigner your build tools inside android SDK:
/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner
2- you should locate your release-Keystore in your pc:
/Users/mina/Desktop/keys/release-Keystore.jks
3- you should run command contains:
apksigner_path + sign --ks + release-Keystore_path + --out + output_signed_apk_name + from_aligned_apk_name
/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner sign --ks
/Users/mina/Desktop/keys/release-keystore.jks
--out app_signed.apk app_aligned.apk
4- enter your key store password
C- Verifying APK:
1- run the following command : apksigner_path + verify + app_signed.apk
/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner verify
app_signed.apk
Notes: you may find some warnings:
WARNING: META-INF/....
Here is some description about that:
Apk Metainfo Warning
In practice, these files are not important, they're mostly versions of libraries you depend on, so even if someone modified those, it wouldn't have any impact on your app. That's why it's only a warning: those files in your APK can be modified by someone else while still pretending that the APK is signed by you, but those files don't really matter.
D- find your signed APK:
/Users/mina/app_signed.apk
I solved this problem by making the zipalign path an environment variable:
export ZIPALIGN_PATH=~/Library/Android/sdk/build-tools/30.0.3/zipalign
Then I replaced zipalign with $ZIPALIGN_PATH in the script I was trying to run
I'm running into several problems since I installed Kali from the USB live installer.
I found out that I needed to add this into my sources.list file in /etc/apt folder.
Just replace the content of sources.list with:
deb http://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free
deb http://old.kali.org/kali sana main non-free contrib
deb http://ftp.de.debian.org/debian wheezy main
C:\Users\saurabh.trivedi\.cordova\lib\android\cordova\3.3.0\bin\node_modules\q\q
.js:126
throw e;
^
Error: ERROR : executing command 'ant', make sure you have ant installed and add
ed to your path.
at C:\Users\saurabh.trivedi\.cordova\lib\android\cordova\3.3.0\bin\lib\check
_reqs.js:47:27
I faced similar error. To overcome the issue I downloaded and installed apache-ant-1.9.2 into the "C:\Program Files\apache-ant-1.9.2\" folder and added the "C:\Program Files\apache-ant-1.9.2\bin\;" to the "Path" environment variable.
Note, that additional environment variables (ANDROID_HOME) and paths to JRE, and Android SDK are also should be set for correct Cordova CLI operation under Windows for me:
ANDROID_HOME = C:\Program Files (x86)\ADT\sdk
Path = ...<some paths for other programs>... + C:\Windows\Microsoft.NET\Framework\v4.0.30319\;C:\Program Files\apache-ant-1.9.2\bin\;C:\Program Files (x86)\Java\jre7\bin\;C:\Program Files (x86)\ADT\sdk\tools\
I faced the same issue. here is the exact solution.
Control Panel\System and Security\System\
click advanced system settings
click Environment variables
In system variables :
ANT_HOME: C:\ant
path: %ANT_HOME%\bin;
This will work..
Config Details:
Windows 8 Pro 32bit
adt-bundle-windows-x86-20130717
jdk-6u26-windows-i586 32bit
Directories:
For Java - C:\Program Files\Java\jdk1.6.0_26
For Android Root - Z:\Program Files\Android
For Android SDK - Z:\Program Files\Android\sdk
Environmental Variables:
var_name: JAVA_HOME
var_value: C:\Program Files\Java\jdk1.6.0_26\
var_name: JDK_HOME
var_value: C:\Program Files\Java\jdk1.6.0_26\
var_name: Path
var_value: C:\Program Files\Java\jdk1.6.0_26\bin
Modification:
1)
set java_exe=
"%JAVA_HOME%\bin\java.exe"
if not defined java_exe goto :EOF
2)
for /f %%a in ('"%~dps0\find_java.exe" -s') do set java_exe=%%a
3)
for /f %%a in ('"%~dps0\find_java.exe" -s -w') do set javaw_exe=%%a
First i downloaded adt-bundle then extracted into Android Root directory (i installed java far earlier) then i installed ADT Plugins from https://dl-ssl.google.com/android/eclipse/ and successfully connected Eclipse IDE with Android SDK. Now i am trying to Android SDK Components but when i clicked on Window-> Android SDK Manager in Eclipse a dialogue box opened said SDK Manager will open in a while but it didn't. Whenever i try to open SDK Manager everytime a cmd prompt for a second then disappear and nothing happened while AVD Manager open properly.
Then i went through some solution in several forums and modified some line of code (as of modification 1 in tools\android.bat ; 2 and 3 in tools\lib\find_java.bat)
Now in command line
Z:\Program Files\Android\sdk\tools>android
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
Z:\Program Files\Android\sdk\tools>
As you can see that my attempts are successful and android.bat is executing but the problem is when i try to open SDK Manager directly or via IDE again nothing happened but executing in cmd. I cannot understand what happening actually and i am unable to found anything related with this in any forum. Please Help. Thanks in advance.
In your PATH environmental variable, move *C:\Program Files\Java\jdk1.6.0_26\bin* to the beginning of the collection, and see if that addresses the issue.
Most likely the directory structure of your sdk installation changed. Try running android.bat from the sdk directory
Z:\Program Files\Android\sdk>tools\android.bat
If the sdk Manager opens (close it) and set the work_dir in android.bat to the sdk directory. In android.bat change line
set work_dir="%cd%"
to
set work_dir="Z:\Program Files\Android\sdk"
or to
set work_dir="%~dp0.."
If the above does not work try to get more information what is wrong in calling java, output the java call to the console. In android.bat change line
call %java_exe% .....
to
echo call %java_exe% .....
Good luck
android.bat seems to have a problem running from a samba share mounted on my windows system. This fixes the problem for me.
V:\>android
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
[snip]
V:\>c:
C:\Users\me>android
I had this same problem and I found that none of the "set" commands in beginning of the batch file worked correctly.
prog is set to ~f0.
work_dir is empty
cd /d ~dp0 results in an error "The filename, directory name, or volume label syntax is incorrect."
Android.bat requires command extensions enabled in order to run correctly.
Restore the original batch file and edit this line
from...
setlocal
to...
setlocal enableExtensions
This should set all the environment variables correctly so that they don't need to be hard coded.
You can also enable command extensions in the registry. Reboot after making this change.
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions = 1