How to set the JDK for Android Studio?

77

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:

  1. Find out the java directory:

    $ echo $JAVA_HOME
    /usr/lib/jvm/java-7-oracle
    
  2. Open Android Studio and then File-> Project Structure.

  3. Under SDK Location I past the java directory from above
  4. Wait a couple of seconds and I got "0 errores 0 advertencias"

It worked! :)

Solution 5

Steps I followed:

  1. Opened terminal and enter echo $JAVA_HOME

  2. Copied the path displayed in terminal - Ctrl+Shift+C copy in Ubuntu terminal

  3. In Android studio - Project Structure - Pasted the copied path

  4. Waited for the software to recognize and update the settings

  5. This solved the problem of Invalid Jdk settings

Share:
77

Related videos on Youtube

Safi Mustafa
Author by

Safi Mustafa

Updated on September 18, 2022

Comments

  • Safi Mustafa
    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
      Louis Matthijssen about 10 years
      Have you tried the bin folder?
    • Lucio
      Lucio about 10 years
      I tried with: ./bin | ./jre | ./jre/bin same message for all
    • Jack M
      Jack M over 7 years
      For 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
    Nitesh Verma about 9 years
    i installed it but im unable to set its path variable. can you please tell me how can i do that?
  • Lucio
    Lucio about 9 years
    Yes, 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
    Mateus Viccari almost 8 years
    This 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
    Safi Mustafa over 6 years
    I will need to add this convertor in each TextBlock this way. Is there any generic way of doing it?
  • Kacper Stachowski
    Kacper Stachowski over 6 years
    Just 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
    arkascha over 2 years
    This 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.