I have a React Native
project where I have a script in which I need to change the Java
versions before and after the script has been executed. I basically need to change to Java 1.8
to run commands connected to the android
sdkmanager
, and then switch back to Java 11
when done.
I am currently using jenv
to manage Java
versions. If I do this in the Terminal at the root of the project using either of the following commands, it works:
jenv local 1.8
jenv local 11.0
However if I use the same in my bash script files, which I run via yarn
, it doesn't work. The script file looks something like, <project_root>/scripts/my_script.sh
:
jenv local 1.8;
java -version;
# Some code here involving sdkmanager...
jenv local 11.0;
java -version;
The java -version
correctly displays that the Java version has changed, but the instructions in between with the sdkmanager
don't pick up on the change. Not sure what I'm missing here. Any help/insights are welcome.