Visual Studio Cordova build fails - android

When I build any android app with Cordova, it fails with
TypeError: Cannot read property 'prepEnv' of undefined.
I've done all the troubleshooting and checked environment variables (As per MS documentation)
What I found is that if I call bld\Debug\platforms\android\cordova\build --ant --debug from my project folder, the build works.
But when I call "C:\Users\<user>\AppData\Roaming\npm\\node_modules\vs-mda\vs-cli.cmd" build --platform Android --configuration Debug --projectDir . --rojectName Gappy --npmInstallDir C:\Users\<user>\AppData\Roaming\npm --language en-US --buildTarget AndroidDevice, the build fails.
One of the steps of the second method, is to call the first batch file.
This happens with VS2013 and VS2015. 64 and 32 bit versions of Node.JS
Any help / ideas?

I noticed that the build file is called differnetly depending on whether the path to the solution contains spaces:
1> ------ Build configuration options:
1> Running command: C:\Projects\Mobile\AppSolutionName\AppSolutionName\bld\Debug\platforms\android\cordova\build.bat --debug --ant
1> ------ Build configuration options: --debug
1> Running command: cmd "/s /c ""C:\Projects\Mobile Apps\AppSolutionName\AppSolutionName\bld\Debug\platforms\android\cordova\build.bat" --debug --ant ""
It works if there are spaces and it fails with "TypeError: Cannot read property 'prepEnv' of undefined" if there are none. I don't know if this is specific to my environment but with the spaces in the path I can build now.

On Mac OS X Yosemite:
Cleaning the project and rebuilding it with sudo fixed it for me.
On /path/to/your/project/platforms/android/cordova folder:
sudo ./clean
sudo ./build --release

Related

React-Native run-android command cannot find Android Studio and SDK

I am building a React-Native project on Mac OS. My Mac is Mac Mini which is using the new Apple M1 chip. I can build and run my project on iOS simulator using "react-native run-android" command. But when I run "react-native run-android" command, it is not working.
I downloaded and installed the Java JDK. When I type in "java -version" in the terminal, I can see the following output.
openjdk version "17" 2021-09-14 LTS
OpenJDK Runtime Environment Zulu17.28+13-CA (build 17+35-LTS)
OpenJDK 64-Bit Server VM Zulu17.28+13-CA (build 17+35-LTS, mixed mode, sharing)
Then I downloaded and installed the latest version of Android Studio. It is installed and Android SDK is located in the following path.
/Users/waihein/Library/Android/sdk
I have the following content in the ~/.hash_profile file.
export PATH="/usr/local/bin:$PATH"
export ANDROID_HOME=/Users/waihein/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:/Users/waihein/Library/Android/sdk/platform-tools/
Within my react-native project folder, when I run "react-native run-android", I got the following output.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.8/userguide/gradle_daemon.html
Process command line: /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp /Users/waihein/.gradle/wrapper/dists/gradle-6.8-all/9emh0d32e025cam7aasxcw002/gradle-6.8/lib/gradle-launcher-6.8.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.8
Please read the following process output to find out more:
-----------------------
Unrecognized VM option 'MaxPermSize=512m'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
I tried using "sudo react-native run-android" too, I got the same error.
When I run "react-native doctor" command, I got the following output.
But I installed the Android studio correctly. What is wrong with my configuration or installation and how can I fix it?
Although the react native docs don’t specify a range of JDK versions that work with RN, I personally haven’t been able to get anything but OpenJDK8 to work. Try installing that and setting the JAVA_HOME environment variable to its path.
I think the package for it got renamed recently in Homebrew - you’d run ‘brew install temurin8’ now.

ERROR: An error occurred while running subprocess cordova

I build an app on Ionic framework, it works on the browser but when I try to compile it on the emulator I have got this error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\user\AppData\Local\Android\Sdk (DEPRECATED)
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/5.3.1/userguide/gradle_daemon.html
Process command line: C:\Program Files (x86)\Java\jdk1.8.0_201\bin\java.exe -Xmx2048m -Dfile.encoding=windows-1252 -Duser.country=SA -Duser.language=ar -Duser.variant -cp C:\Gradle\gradle-5.3.1\lib\gradle-launcher-5.3.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.3.1
Please read the following process output to find out more:
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
C:\Gradle\gradle-5.3.1\bin\gradle: Command failed with exit code 1
[ERROR] An error occurred while running subprocess cordova.
cordova run android exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
This is because the path to Android Sdk is not set correctly. Please check the correct path for Sdk, tools, platform-tools, emulator and Android build-tools.
Please, realize that the configuration recommended for Ionic has changed a
bit. Now the notation recommended is as follows:
ANDROID_SDK_ROOT=/home/username/Android/Sdk (recommended setting)
ANDROID_HOME=/home/username/Android/Sdk (DEPRECATED)
In Linux or Mac OS X configure the path into the ~/.bashrc, ~/.bash_profile file:
export ANDROID_SDK_ROOT=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/build-tools
At the end, after save the configuration dont forget to do the command:
source ~/.bashrc
or as your case
source ~/.bash_profile
For the Windows users check the global variables.
Try to Run npm cache clean and re-install cordova...worked for me.
I finally found the solution from a related solved topic: The solution is:
ionic platform rm android
ionic platform add android#latest
ionic resources
ionic run android
ionic repair worked for me. Just give it a try and see if that works for you. Good luck!

Execution failed for task ':app:compileDebugJavaWithJavac' react native

I am trying to run react native app on my android device like this in cmd
cd C:\Users\User\Desktop\js
react-native run-android
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not find tools.jar
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: 5.243 secs Could not install the app on the device, read
the error above for details. Make sure you have an Android emulator
running or a device connected and have set up your Android development
environment:
https://facebook.github.io/react-native/docs/android-setup.html
Can anyone please tell me how to fix this problem?
Use the following step once, it may help you:
step 1: open cmd through administrator
step 2: navigate to your application by cd <path to your project>
step 3: run this command: ./gradlew clean
step 4: react-native run-android
Have you installed JDK and Android SDK properly? Are the JAVA_HOME and ANDROID_HOME properly placed in your environment variables?
I faced this issue while working on react-native project on Linux.
In my case issue occured because I linked some external plugin and then removed it without unlink. In that case you can attentively read your console error message. It should point to place that source an error.
The solution if ur version of react-native >= 0.61.0. It shows error as when we add any plugin and use link command then it makes changes in android and ios folder. But when we remove plugin, it gets removed from package.json but inside android changes are not reverted and it gives error. So use below command to generate android folder again.
I hope it will solve the error-
sudo rm -rf android/ ios/
yarn add react-native-eject
npx react-native eject
If you are working with react native, just make sure you set up environment variables correctly for java compiler.
after this goto package.json file in your project:
change this:
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
to:
"react-native": "0.57.5",
save and run npm install
Source: https://github.com/facebook/react-native/issues/21722

Execution failed for task ':CordovaLib:compileDebugJava'

I want to run my ionic app in android emulator. When I try to build ionic app using the following command in terminal:
ionic build android
It shows the following error ::
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':CordovaLib:compileDebugJava'.
> Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.
* 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: 20.383 secs
/home/meutics/ionicapp/ebook- app/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /home/meutics/ionicapp/ebook-app/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/meutics/ionicapp/ebook-app/platforms/android/build.gradle,-Dorg.gradle.daemon=true
Seems JAVA_HOME is not correctly configured, but I think I configure JAVA_HOME correctly.
In terminal window, I run the following command ::
meutics#meutics-pc:~$ echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64
In .bashrc window,vi ~/.bashrc
export PATH=$PATH:/home/meutics/Downloads/android-studio/bin
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export PATH=$PATH:$JAVA_HOME/bin
export ANDROID_HOME=/home/meutics/Android/Sdk
export PATH=$PATH:$ANDROID_HOME:$ANDROID_HOME/tools:$ANDROID_HOME/build-tools
How can I solve this problem?
NB: In /usr/lib/jvm/ directory,
root#meutics-pc:/usr/lib/jvm# ls
java-1.7.0-openjdk-amd64 java-7-openjdk-amd64 java-8-oracle
And java version ::
meutics#meutics-pc:$ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
just restart your CLI/ terminal and run as admin or do sudo on linux ... it worked for me

error in building android app using apache cordova

i have installed cordova on linux mint 17.1 xfce, jdk and android and npm is ok and i can create new cordova application and add android platform to it :
cordova create ...
cordova platform add android ..
but when i want to build android i get a error :
cordova build ...
Running command: /home/nasser/Desktop/app/app01/platforms/android/cordova/build
ANDROID_HOME=/home/nasser/android/sdk
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
Running: /home/nasser/Desktop/app/app01/platforms/android/gradlew cdvBuildDebug -b /home/nasser/Desktop/app/app01/platforms/android/build.gradle -Dorg.gradle.daemon=true
FAILURE: Build failed with an exception.
* Where:
Script '/home/nasser/Desktop/app/app01/platforms/android/CordovaLib/cordova.gradle' line: 64
* What went wrong:
A problem occurred evaluating root project 'android'.
> No installed build tools found. Please install the Android build tools version 19.1.0 or higher.
* 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: 20.222 secs
/home/nasser/Desktop/app/app01/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /home/nasser/Desktop/app/app01/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/nasser/Desktop/app/app01/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /home/nasser/Desktop/app/app01/platforms/android/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project
Error: /home/nasser/Desktop/app/app01/platforms/android/cordova/build: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
what i can do ?
Once you installed the android sdk, configured ANDROID_HOME and updated the path, you have to run the androidcommand to actually download the sdk tools and android platform.
You don't need to download everything. You can uncheck the system images (keep one if you want to use the emulator), the samples, the sources of android, the docs and android apis older than API 22 (latest android cordova version 4 requires api 22).
Not sure if you still need to install ant with android cordova 4, as it seems they switched to graddle wich is installed automatically.
I had the same problem, and this is the solution for the problem referent to:
No installed build tools found. Please install the Android build tools
version 19.1.0 or higher.
1) You have to go to the android sdk tools folder, for example (in my case) I just wrote the command in my console: $ cd android-sdk-linux/tools
2) Inside this folder you have to write the command
$ ./android list sdk --all and after
$ ./android update sdk -u -a -t 20
And that's all! :)
This will install all the tools you need as well as the system images which are quite large, limit them using the --filter flag
android update sdk --no-ui --all

Categories

Resources