I have a jenkins job that is supposed to create a cordova app but it's failing some reason that I can't quite identify. The jenkins job simply does this:
cordova platform add android
cordova prepare android
cordova build android --debug --verbose
The first command (cordova platform add android) is resulting in the following error:
ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
Error: ENOENT: no such file or directory, mkdir 'platforms/android/app/src/main'
at Object.mkdirSync (fs.js:738:3)
at Object.module.exports.makeDirSync (/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/fs-extra/lib/mkdirs/make-dir.js:23:13)
at /Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/node_modules/cordova-android/lib/create.js:231:16
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova prepare android
(node:23901) ExperimentalWarning: The fs.promises API is experimental
Discovered platform "android". Adding it to the project
EEXIST: file already exists, mkdir '/Users/me/Documents/Jenkins/sharedspace/apps/my-app/cordova/platforms'
+ /Users/me/.nvm/versions/node/v16.13.2/bin/cordova build android --debug --verbose
(node:23902) ExperimentalWarning: The fs.promises API is experimental
No platforms added to this project. Please use `cordova platform add <platform>`.
CordovaError: No platforms added to this project. Please use `cordova platform add <platform>`.
at Object.preProcessOptions (/Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/util.js:275:15)
at /Users/me/.nvm/versions/node/v16.13.2/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/build.js:29:31
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
at startup (internal/bootstrap/node.js:236:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:560:3)
Build step 'Execute shell' marked build as failure
When I look inside the platforms directory on the jenkins box it is empty. It is able to create the platforms folder itself, just nothing else under. It doesn't seem to be a permission issue as far as I can tell. If I ssh into the box as the same user that jenkins in using I can run the cordova commands fine and everything works.
Furthermore, if I add the platform manually by sshing into the box and then let jenkins take over after the android folder already exists, the job works fine. So I guess for some reason it's not able to add the android project.
If it helps, this is what cordova requirements gives:
cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-30,android-29,android-28
Gradle: installed /usr/local/Cellar/gradle/7.3.3/bin/gradle
Okay, I finally figured this SOB out! After taking a few weeks off and coming back to this I noticed that there is a setting in the job config called "Shared Workspace" and I had it set to the value (). I don't know what that means, but it had the effect of putting the code for this project in the
/Users/me/Documents/Jenkins/sharedspace
folder, which apparently was causing problems with cordova. Once I set the Shared Workspace value to NONE, it moved the project to the
/Users/trident/Documents/Jenkins/workspace/my-app
folder which is more what I would expect. After that, lo and behold, everything works.
Related
I have a problem in my vuejs + cordova project, when there is an edit file for example (login.vue) the changes only appear when running the 'npm run serve' command but when running the command 'cordova run browser / android' the login.vue file is not updated. I've tried clear cache 'npm clear cache' and 'cordova clean / cordova prepare' the results are still the same.
Command Before run/build cordova :
npm run serve
npm run build
cd cordova_app
cordova run/build android or browser
it is because the latest changes you made to files need to be brought to the platform folder (E.g. $projectroot/platform/android/www).
For this you have two options:
you can edit the file here directly
$projectroot/platform/$platform_name/www, but as a result, if you delete the platform, then that change will get lost.
Or you can make also make the changes in $projectroot/www/ but you will need to run few commands: cordova platform remove android and cordova platform add android if it is for Android. Please note that this will also overwrite any special configuration you have made in your IDE (xCode for iOS or Android Studio for Android) because it regenerates from your code, a new workspace for your app to be compiled, including your latest code, all in the platform folder.
Good luck!
I am trying to create a mobile application from my angular app and am using cordova for converting the web app to mobile. I had followed all requirements given on the apache cordova official guide and installed Android studio as well using this online guide.
I had also followed this youtube tutorial which explained to easily convert the angular app into a cordova application using these steps:
- Create a cordova project within the angular project using cordova create <proj_name>
- Create a soft link, adding a link between www folder in cordova project and dist folder of angular project
- Create build
- Add android to cordova project
- Cordova run android
Everything goes fine until cordova run android where it gives me the following error:
Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
I checked to see on stackoverflow of any errors and there were in fact a few similar issues, which should have been resolved by editing the ~/.bashrc file and adding:
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
However, even after logging out and logging in again, several times, using source ~/.bashrc as well hasn't helped, the same error keeps popping up. I have also installed android studio and checked all paths the Sdk is installed and shows on the Sdk Manager in studio.
If I try to enter android in terminal it gives me an unknown command error, same goes with sdkmanager.
when I run echo $ANDROID_HOME it gives me the correct path:
/home/username/Android/Sdk
when I run cordova requirements it gives me the following:
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
android: Command failed with exit code ENOENT
Gradle: installed /opt/gradle/gradle-5.2.1/bin/gradle
Some of requirements check failed
running cordova platform version android in the project gives the following:
form version android
Installed platforms:
android 8.1.0
Available platforms:
browser ^6.0.0
electron ^1.0.0
ios ^5.0.0
osx ^5.0.0
windows ^7.0.0
I do not understand what seems to be missing? I have looked several times but can't seem to find the problem with my installation. Am i doing something naive here?
For anyone facing the same issue: For some reason data was being fetched from npm cache. To clear it, simply:
sudo npm cache clean -f
Maybe not the best approach, but for now it was the only way out
everyone. I want to build an app for one of my clients. It's the first time I develop an app on Ionic 4 and at the time of building the apk, I couldn't do it.
I checked all the errors that the console prompted to me. At first, it seemed to be moving on, however, at a moment, the console prompted the following:
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/Cris/Library/Android/sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[ERROR] An error occurred while running subprocess cordova.
cordova build android --release exited with exit code 1.
I have already done a research about this topic, and even though there are similar questions here on this website, I couldn't find any answer that solved my problem.
I have already defined the ANDROID_SDK_ROOT, the ANDROID_HOME and GRADLE_HOME. I checked all of those dirs to see if they worked, and they did so. I have already downloaded and set up the JDK variable and path as well.
I have installed Android Studio with the version of sdk API that I need for this development. Also, when I researched about gradle, I installed it with npm and manually (without counting the time it got installed automatically with Android Studio). HOWEVER!!! The console tells that gradle isn't installed, that Android paths aren't set or that they are deprecated (both options, actually), and that I have to do what I have already done several times.
Here I let you see the variables set:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${JAVA_HOME}/bin:$PATH
export ANDROID_HOME=/Users/Cris/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export GRADLE_HOME=/Users/Cris/Library/Gradle.0/bin
export PATH=$PATH:$GRADLE_HOME
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
Do you guys have any idea of how to proceed? Thank you before hand
GRADLE_HOME should be the root folder of the <gradle installation folder>, currently its pointing to <gradle installation folder>/bin it should look like following
export GRADLE_HOME=/Users/Cris/Library/Gradle.0
I have already overcame the problem with the following instructions:
When you want to build your app for Android with Ionic 4 on MAC, install Java (JDK), install Android Studio, install the API version you want to work with, install Homebrew (on its website there is a so easy-to-follow guide to install it) and install Gradle by writing the following command:
brew install gradle
Then, write the following command and copy the route of the gradle directory:
brew info gradle
Go to Ionic Framework Developer Resources for MAC
And follow the instructions to set up the paths. Don't forget to check if the example paths work just fine on your computer by doing it as the following example:
ls /Users/your-user/Library/gradle-5.4
If the "echo" of that line says that the directory exists, then it's okay and you must set that path the way it is. If the directory doesn't exists (as it'll happen in the case of the $GRADLE_HOME's path, you should paste the route that you copied some steps ago.
To corroborate that those paths exist on your MAC, besids saving them on your MAC's ~/.bash_profile, enter them one by one (exporting the variable and exporting its path) inside the MAC's terminal.
Then, as one of the last steps (I'm not going to describe how to sign your app, because it's explained on the link above), write on a console opened inside your project the following line:
sudo ionic cordova build android --prod
It's going to build your app for production, which releases you from signing your app in order to install it on your mobile device
IMPORTANT NOTE:
If you want to sign your app, you should run the following command before signing it (it replaces the last command I wrote above):
sudo ionic cordova build --release android
You can find more information about releasing your app without a signed key and how to sign it on this website's section:
Publishing Your App - Ionic Framework
Thank you for checking this answer out! :D
I have an older cordova project that I am updating. As a part of this process, I removed the android platform and readded it.
Now when I try to build the project I get the following error:
C:\App>cordova build android --verbose
No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\App\platforms\android\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Found "merges/android" folder. Copying its contents into the android project.
Merging and updating files from [www, platforms\android\platform_www, merges\android] to platforms\android\assets\www
Wrote out android application name "App" to C:\App\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.20): 10020
Wrote out Android package name "com.nge.app" to C:\App\platforms\android\src\com\nge\bca\MainActivity.java
Updating icons at platforms\android\res
Updating splash screens at platforms\android\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
Error: Cannot read property 'length' of undefined
This did work before I removed the platform so I am guessing it is a bug or a config file that changed.
There is a similar issue here: https://pt.stackoverflow.com/questions/219442/cordova-build-android-error-cannot-read-property-length-of-undefined
I found another solution by downgrading Android to version 6.1.2, since the suggestions here (and many other suggestions on various forums, like reinstalling plugins, etc.) didn't work for me:
cordova platform update android#6.1.2 --save
If that doesn't work at first hand, try the following:
First remove android platform:
cordova platform remove android
Add Android version 6.1.2:
cordova platform add android#6.1.2
Build Android:
cordova build android
Here are some additional steps I took prior to above (on Mac), just to make sure:
Download the latest JDK and install.
Add JAVA_HOME this way:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
Restart shell (CMD+Q and open again)
Make sure echo $JAVA_HOME equals to Android Studio -> File -> Project Structure -> JDK Location
For me, this is the following path and version:
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
Update Android Studio and all of the SDK packages
Update npm
npm update -g
Note: On OS X 10.11 El Capitan or greater, run:
sudo npm update -g --unsafe-perm=true
Update Cordova
npm update -g cordova
If all of this didn't work for you and you are left with no other choice, I suggest you try downgrading Cordova to version 6.4.0:
npm update -g cordova#6.4.0
You can downgrade cordova cli using
npm install -g cordova#6.4.0
and build the project with give command
ionic cordova build android
no need to add platform, it'll automatically add.
If it ask to update cordova cli, then choose no
Resolved an error by following:
Hi all,
Resolved problem to run cordova run android via command prompt for cordova project attached problem screenshot.
To resolve this problem removed all environment variables under Advanced System settings.
Uninstalled java and installed again, downloaded old sdk tools to avoid prompt for eclipse now.
Under user variable added
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_131
Under System variable
ANDROD_HOME = C:\cordova\android-sdk
Path = C:\Program Files\Android\Android Studio2\gradle\gradle-3.2\bin\;%JAVA_HOME%\bin to avoid error:
No installed build tools found. Install the Android build tools version 19.1.0 or higher.
Problem resolved now 😊
The problem was that my gradle version was 2.1 where Cordova wanted 3.2. Updating Android Studio (It was at 2.1) and making sure the environment variables are upto date was the main trick to get it to work again.
While trying to do a release using the following command:
code-push release-cordova myApp android
I'm getting the following error in the terminal:
Running "cordova prepare" command:
[Error] Unable to prepare project. Please ensure that this is a Cordova project and that platform "android" was added with "cordova platform add android"
Any one knows what might be wrong? The project is a cordova project created using the command:
cordova create myApp
And also has android platform added.
UPDATE :
Running cordova prepare android --verbose returns the following output :
Executing "before_prepare" hook for all plugins.
Searching PlatformJson files for differences between project vs. platform installed plugins
No differences found between project and android platform. Continuing...
Generating config.xml from defaults for platform "android"
Wrote out Android application name to "HelloCordova"
Wrote out Android package name to "io.cordova.hellocordova"
This app does not have launcher icons defined
updated project successfully
Executing "after_prepare" hook for all plugins.
Make sure your Nodejs is the last version.
code-push-cli required "child_process"
That error indicates that the current working directory didn't represent the root of a Cordova project at the time that you ran the release-cordova command. Can you make sure that you CD into the directory that contains the www, platforms, plugins, etc. directories, and then run the release-cordova command? That should do the trick for you