How to set the JDK for Android Studio?
Solution 1
It seems that Android Studio does not recognize OpenJDK, so I need to install the OracleJDK.
Then I choose the path to Oracle JDK and it worked!
Solution 2
I'm using OpenJDK 7 with Android Studio and it works just fine. (I don't even have Oracle JDK installed at the moment.)
On that screen that you are showing (Project Structure-->SKD Location) I have the following path for the JDK location: /usr/lib/jvm/java-1.7.0-openjdk-amd64
.
Solution 3
By inspecting studio.sh
, you can also set one of STUDIO_JDK
, JDK_HOME
or JAVA_HOME
environment variables to point to the JDK location.
studio.sh
checks the STUDIO_JDK
, JDK_HOME
, and JAVA_HOME
environment variables in order:
if [ -n "$STUDIO_JDK" -a -x "$STUDIO_JDK/bin/java" ]; then
JDK="$STUDIO_JDK"
elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then
JDK="$JDK_HOME"
elif [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
JDK="$JAVA_HOME"
So you can just set them as appropriate and then Studio will pick it up.
Solution 4
This worked for me:
Find out the java directory:
$ echo $JAVA_HOME /usr/lib/jvm/java-7-oracle
Open Android Studio and then File-> Project Structure.
- Under SDK Location I past the java directory from above
- Wait a couple of seconds and I got "0 errores 0 advertencias"
It worked! :)
Solution 5
Steps I followed:
Opened terminal and enter
echo $JAVA_HOME
Copied the path displayed in terminal - Ctrl+Shift+C copy in Ubuntu terminal
In Android studio - Project Structure - Pasted the copied path
Waited for the software to recognize and update the settings
This solved the problem of Invalid Jdk settings
Related videos on Youtube
Safi Mustafa
Updated on September 18, 2022Comments
-
Safi Mustafa over 1 year
I am trying to apply overall formatting on my application. The application is already build. When showing data in a datagrid, I want to format and right align all the textblocks having amount in them. Is this possible to do it using some trigger or any other way? Is it possible to know if a binding path contains word "amount" and if it does apply the required formatting.
Basically I want to control formatting and alignment based on values in whole app from one location. So that it is easy to change in longer run.
Here is my XAML for view:
<UserControl x:Class="CPOSApplication.UserControls.Sales.SalesFilterResult" xmlns:PaginationControl="clr-namespace:CPOSApplication.GeneralControl.PaginationControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:localConvertor="clr-namespace:CPOSApplication.Convertors" xmlns:com="pagina" xmlns:local="clr-namespace:CPOSApplication.Convertors" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="1000"> <UserControl.Resources> <local:DataGridRowToIndexConvertor x:Key="RowToIndexConvertor"> </local:DataGridRowToIndexConvertor> <localConvertor:PermissionToEnableConvertor x:Key="PermissionToBoolConvertor"/> </UserControl.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="4*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Label x:Name="GridLabel" Grid.Row="0" Style="{DynamicResource HeadingLabelsCustomStyle}" Content="Sales"/> <DataGrid Grid.Row="1" Style="{DynamicResource DataGridStyle}" ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle}" RowStyle="{DynamicResource DataGridRowStyle}" CellStyle="{DynamicResource DataGridCellStyle}" x:Name="SalesGrid"> <DataGrid.Columns> <DataGridTemplateColumn Header="Id" Visibility="Collapsed" Width="Auto" IsReadOnly="True"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Id}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="Index" Width="*" IsReadOnly="True"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock x:Name="IndexCell" Style="{DynamicResource GridTextBlock}" Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource RowToIndexConvertor}}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="Serial Number" Width="*" IsReadOnly="True"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=SerialNumber}" Style="{DynamicResource GridTextBlock}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="Customer" Width="*" IsReadOnly="True" > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=CustomerName}" Style="{DynamicResource GridTextBlock}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="Payment Method" Width="*" IsReadOnly="True" > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=FormattedPaymentType}" Style="{DynamicResource GridTextBlock}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="Sale Date" Width="*" IsReadOnly="True" > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=CreatedDate}" Style="{DynamicResource GridTextBlock}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Header="Sale Amount" Width="*" IsReadOnly="True" > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=TotalAmount}" Style="{DynamicResource GridTextBlock}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Width="*" Header="Actions" IsReadOnly="True"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Style="{DynamicResource ActionPanel}"> <Image x:Name="EditImg" IsEnabled="{Binding Converter={StaticResource PermissionToBoolConvertor}, ConverterParameter='Edit Sale|Sale'}" Visibility="{Binding Converter={StaticResource LiveConnectionToVis}}" Style="{DynamicResource EditImg}" Source="/CPOSApplication;component/Resources/Images/Icons/edit.png" Tag="{Binding}" MouseDown="Edit_Click"></Image> <Image x:Name="DeleteImg" IsEnabled="{Binding Converter={StaticResource PermissionToBoolConvertor}, ConverterParameter='Delete Sale|Sale'}" Visibility="{Binding Converter={StaticResource LiveConnectionToVis}}" Style="{DynamicResource DeleteImg}" Source="/CPOSApplication;component/Resources/Images/Icons/delete.png" Tag="{Binding}" MouseDown="Delete_Click"></Image> </StackPanel> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> <PaginationControl:Paginator Background="#e4e4e4" x:Name="pager" Grid.Row="2" VerticalAlignment="Bottom" Margin="0,10,0,0" Height="30" /> </Grid> </UserControl>
-
Louis Matthijssen about 10 yearsHave you tried the
bin
folder? -
Lucio about 10 yearsI tried with:
./bin
|./jre
|./jre/bin
same message for all -
Jack M over 7 yearsFor me I just had to use the folder above
/jre
in the directory structure, so my path is/usr/lib/jvm/java-8-oracle
and not/usr/lib/jvm/java-8-oracle/jre
. I assumed the path should end in/jre
since the default path (the "embedded" JDK) does, but it turns out if you go look in the default folder, it's a folder called "jre" which contains another folder called "jre".
-
-
Nitesh Verma about 9 yearsi installed it but im unable to set its path variable. can you please tell me how can i do that?
-
Lucio about 9 yearsYes, first make sure that
java -version
output correctly your Java version. Then, on the AS window choose/usr/lib/jvm/jdk1.8.0/
. That was enough for me at that moment :-) -
Mateus Viccari almost 8 yearsThis works for windows too. useful if you have a JDK with DCEVM as default in JAVA_HOME which does not work with android studio.
-
Safi Mustafa over 6 yearsI will need to add this convertor in each TextBlock this way. Is there any generic way of doing it?
-
Kacper Stachowski over 6 yearsJust edited my answer to include applying converter to all TextBlocks. I don't think you should do it on a wider scope than DataGrid (or without setting x:Key to style, because it can cause you some problems with other controls that are using TextBlocks inside them).
-
arkascha over 2 yearsThis should be done only after good consideration: this has massive legal implications, since Oracle changed their licensing terms in quite surprising ways. Typically you do not want to use Oracle java any longer in a comercial environment.