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
Related
My goal is to run an old project. It uses React Native 0.63.3. This is the repository
What I've did:
Setup the environment by following the docs for 0.63
Installed Android Studio a month ago.
did $ brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
did not do $ brew install node because it is already installed.
did $ brew install watchman
Installed Android SDK Platform 29 on Android Studio.
Installed Google APIs ARM 64 v8a System Image under the Android 10 (Q) entry because I use Mac Mini M1 instead of Google APIs Intel x86 Atom System Image not documented on the docs for 0.63
Installed Android SDK Build-Tools 29.0.2 on Android Studio.
Added environment to ~/.zprofile and did $ source ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
export ANDROID_HOME=/Volumes/T7Touch/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:$ANDROID_HOME/platform-tools
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
JAVA_HOME is not documented on the docs for 0.63, this is to fix cd android && ./gradlew clean issue
Then, I tried to run it by $ npm run android
However, it throws an error
...
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException
* 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
BUILD FAILED in 4m 39s
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
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
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.
I created a new project with React Native in Windows 10 but it does not run with the run-android command.
I will summarize what I did because I think all the programs are installed:
I install both npm and node.
Java installation.
React installation.
In the Environment system, these are set.
ANDROID_HOME ---> C:\Users\IHC\AppData\Local\Android\Sdk
JAVA_HOME--> C:\Program Files\Java\jdk-۱۴.۰.۱
path--> C:\Users\IHC\AppData\Local\Android\Sdk\tools
C:\Users\IHC\AppData\Local\Android\Sdk\platform-tools
C:\Program Files\nodejs\
C:\Users\IHC\AppData\Local\Android\Sdk
C:\Users\IHC\AppData\Local\Android\Sdk\emulator
C:\Program Files\Java\jdk-۱۴.۰.۱\bin
The error is:
info Starting JS server...
info Installing the app...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
at org.codehaus.groovy.vmplugin.VMPluginFactory.<clinit>(VMPluginFactory.java:43)
.
.
.
.
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:832)
FAILURE: Build failed with an exception.
* What went wrong:
Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
* 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
BUILD FAILED in 44s
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.bat app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
enter code here
Can you check on the android version installed, for latest version refer https://www.npmjs.com/package/#react-native-community/cli-platform-android and retry.
That is installed, well I did the following
remove jdk-۱۴.۰.۱ and i install jdk-8u261-windows-x64
first of all run Oracle VM VirtualBox next run Genymotion
and in powershell
npm start -- --reset-cache
npm install -g npm#4
react-native run-android
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!
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