Android builds fail when building with launchctl - java

I am trying to write a script to automate my build process and push builds every so often. So ever everything seems to be working except for my JAVA_HOME environment variable.
When building the app normally from command line I specify my JAVA_HOME as:
/Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home
However if I add this as an environment variable to my launchctl.plist I get the following error:
ERROR: JAVA_HOME is set to an invalid directory: /Applications/"Android Studio.app"/Contents/jre/jdk/Contents/Home
This directory does exist and works fine when building the app normally.
If I do not specify the JAVA_HOME then I get the following error on building my app:
General error during semantic analysis: Unsupported class file major version 60.
Is there something I am doing wrong or can change to allow launchd to either build without the specified JAVA_HOME or to recognize the JAVA_HOME I am setting?

Add the code below to your environment's path .zshenv file in your home directory.
Run source ~/.zshenv to update terminal or Quit the terminal and reopen it again
Android Studio Dolphin and below:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
Android Studio Electric Eel and above:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home

Related

JAVA_HOME is set to an invalid directory- vs code

I have completely followed Setting up the development environment for the react-native project, now when I am running the first app from Andriod studio run BUTTON it installs and runs perfectly. The problem comes when I run the command yarn react-native run-android it throws the following error:
info JS server already running
info Installing the app...
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-15.0.1;C:\Program Files\Java\jdk-15.0.1\bin;
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
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
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this co
snapshot is here
My jdk path:
C:\Program Files\Java\jdk-15.0.1;
C:\Program Files\Java\jdk-15.0.1\bin;
My question is:
If the jdk path is invalid then why it is running in android studio?
It seems the terminal caches the earlier environment variables.
Before moving ahead make sure you have already changed the correct path for JAVA_HOME.
Now, Open Visual code and close the terminal, and reopen it (ctrl + ~)
error should be gone
You should edit your path as "C:\Program Files\Java\jdk-15.0.1" bin is not required.
To set JAVA_HOME
1-Search for Environment Variables
2-Under system variables click new
3-In the variable name enter JAVA_HOME, in the variable value enter the JDK path which is "C:\Program Files\Java\jdk-15.0.1"
I was getting this error in flutter. I deleted the "JAVA_HOME" "C:\Program Files\Java\jre7" value that I wrote earlier in the system variables section under the environment variables menu. I ran the terminal again and ran "flutter doctor --android-licenses" in the terminal. Problem solved.

JAVA_HOME is not defined correctly on Ubuntu when trying to run Ballerina code?

I have already set JAVA_HOME in the environment variables file as shown below.
I also built ballerina from the source and extracted the zip with the Runtime and the tools as per the Ballerina documentation. However when I try to give this distribution as the Ballerina SDK in IntelliJ IDEA or even in the Terminal and try to run a Ballerina program as shown below:
I get the following error:
Error: JAVA_HOME is not defined correctly.
But when I type:
echo $JAVA_HOME
I get the following output:
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
What am I doing wrong?
Note: Ballerina Version: jballerina-tools-2.0.0-Preview3-SNAPSHOT
The value of your JAVA_HOME environment variable is wrong. It should not to point to an executable but to the location (i.e. a directory) of the Java installation.
In your case the correct value seems to be:
/usr/lib/jvm/java-8-openjdk-amd64
See also e.g. How to set JAVA_HOME for Java?.
Normal Ballerina 1.2 distribution doesn't require JAVA_HOME but this might be different in your case as you're building a preview release.
what #user272735 was partly correct but you can see that I have added the correct Java Home path in the environment file. Actually the problem was that I was working on terminator when changing the java home path in the environment file and running the below command.
source /etc/environment
But I was trying to run the ballerina code in the plain-old Terminal where the path change was not registered yet.
How to resolve:
I had to run the below command in the Terminal as well. Then when I echoed the java path it printed the one in the environment file and the ballerina code also ran without a problem.
source /etc/environment

Cordova Android platform - ant installation not recognized

I keep recieving the following error when attempting to add a platform to a cordova project.
ERROR: executing command 'ant', make sure you have ant installed and added to your path.
I have added my JAVA_HOME, ANT_HOME and ANDROID_HOME (both \tools and \platform-tools) environment variables and can confirm they are all installed correctly be executing 'java', 'ant -version' and 'android' commands in my console and getting responses.
Right now, I have the above mentioned environment variables as both User and System variables, but have also tried just having them configured as System variables.
Ant version: 1.9.2
java: jdk1.8.0_11
I'm quite stumped right now because everything seems to be configured/installed correctly. Is there a specific location I should install/un-zip these components?
You have to show full path to bin folder of ANT. see for the variable name path, edit it. add one of the following to the end of it's value.
Suppose your ant folder is in d drive like this D:\ant then your ANT_HOME value should be D:\ant. Then add this to your path variable
%ANT_HOME%\bin
OR add the full path like
D:\ant\bin

Unable to use PhoneGap and not detecting Apache ANT

I have installed PhoneGap via command prompt. I have installed java, ADT and Apache ANT and setup their environment variables as follows:
ANDROID_HOME - C:\Program Files\ADT\adt-bundle-windows-x86_64\sdk\platform-tools
ANT_HOME - C:\Users\myname\Downloads\apache-ant-1.9.3-bin\apache-ant-1.9.3
JAVA_HOME - C:\Program Files\Java\jdk1.7.0_51
When I use command prompt to check on Java via the commands java or javac, I get a list of print out which I believe indicates that it is working.
Similarly when I try to type ant, it is not recognized which I am assuming is the problem. I did look through past questions here from which I have come to the current setup and it is still not working.
When I go into the created PhoneGap project folder and input the command:
phonegap run android
It returns the following error message:
An error occurred during the creation of android sub-project.
Please advice what I am doing wrong. Thanks.
Edit:
adb - it prints out a long list
android - The system cannot find the path specified
Failed to create c:/Program Files/ADT/sdk/add-ons
Error: unable to parse SDK content.
android is returning error as above. I checked the path and it is
correct less the last part. I don't have a folder called add-ons
inside sdk folder.

Cannot determine current directory

I am trying to run a .jar file that was created successfully in Netbeans and I am receiving the following error:
Error occurred during initialization of VM java.lang.Error:
Properties init: Could not determine current working directory. at
java.lang.System.initProperties(Native Method) at
java.lang.System.initializeSystemClass(System.java:1070)
The command that I type to run the .jar is
java -jar "/path to the dist forlder/EOPPrototype.jar"
My classpath is as follows:
CLASSPATH=/opt/netbeans-7.1.2/ide/modules/ext/mysql-connector-java-5.1.13- bin.jar:/h/USERS/local/pagola/NetBeansProjects/mylib/dist/mylib.jar:/h/USERS/local/pagola/NetBeansProjects/EOPPrototype/build/classes:.
What am i missing?
I saw the same error when I was trying to call java -version inside a directory, which I already had deleted from another terminal session. Of course in that case java could not determine the current working directory, simply because it didn't exist.
Solution: cd to another directory and run that command again, that works for me.
See explanation here: https://bugs.openjdk.java.net/browse/JDK-8186434
In Fedora 21, I tried calling the "java -version" after an uninstall and it gave the above error. Close all the terminals and open them again and try.
Should work.
I was getting the same error message, but I'm not sure if it was for the same reason as I don't use Netbeans. I use my terminal and compile with ant.
I cd'd to a directory to run a javafile.class file. The file I want to run is part of a bigger package. The directory structure of the package looked something like this: a/b/c/javafile.class. The a, b, and c directories are all part of a larger package.
To run my javafile.class, I cd'd into a and ran the file from there: java b/c/javafile. After I made some changes and recompiled with my ant script, the directory I was in had been deleted and remade by ant. So, when I ran javafile.class again, I got the error you're getting.
I fixed my problem by cding out of the directories that are deleted and remade by ant and then running my javafile.class again.
maybe you did not config java environment on your workstation correctly
the following configurations were what I did in my mac
vi ~/.bash_profile
and add those in it
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
replace
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
with your jdk version
and then run
source ~/.bash_profile
to use these config immediately
then you can check by
java -version
I got the same error -
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.
by just doing 'java -version' (you would think it wouldn't need to bring up a
virtual machine just to answer a simple question like 'what version are you?')
A higher up element (that between the slashes) of the directory path of the pwd
had spaces in it. When I made the current working directory one which from /
downward didn't have any spaces the 'java -version' command got a proper response.
I'm concluding they didn't account for directories with spaces when they
programmed it. But that was version 1.7. I've now loaded version 8 so hopefully
it has been corrected.
I got this error on Mac OS X and this is a genuine error since the directory has vanished. The directory I was when I am executing the commands is <PROJECT DIR>\target.
The problem was I opened two terminals in the other terminal I ran mvn clean install and the target directory from PROJECT DIR got deleted and recreated.
My old terminal from where I was executing Java commands is not in a valid directory.
The file descriptor is invalid since the directory got deleted by Maven.
When I moved back to the parent directory and the changed back to the target directory, the java command started working correctly as expected.
Under CentOS, rhel, SL or SLC? Not an issue under debian/ubuntu.
I found you need to logout of the shell you are using and log back in. The environment is not set up initially correctly for the current shell. After login I see that: java -version will work.
Also ensure that /etc/alternatives/java actually points to something reasonable like:
ls -lisa /etc/alternatives/java
72645 0 lrwxrwxrwx. 1 root root 46 May 27 11:29 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
Just now, i got the same error. because i use java to setreuid/setregid to apache:apache, when i change back to root:root, i changed gid before uid, the real result is root:apache. everything going wrong, such as the error say "java.lang.Error: Properties init: Could not determine current working directory. "
you can check it.
I was having this error in my mac, when I start tomcat from my eclipse. After setting JAVA_HOME and restarting the eclipse, the error is fixed.
You have to install default-jdk first !
sudo apt install default-jdk
only version 11 does not set all the environment correctly
in place of : sudo apt install openjdk-11-jdk
You may get this error if you issue "java -version" or other java command from a read-only directory. For example using openjdk 8 on centos (as non-root user):
cd /usr/bin
java -version
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.

Categories

Resources