Intellij idea android sdk установка

Блог Андрея Клименко

Установка будет проводится на Windows 7 (x64).

Саму Anddroid SDK берем с официального сайта: http://developer.android.com/sdk/index.html (откройте пункт «USE AN EXISTING IDE» и скачайте инсталлятор. Сразу после запуска возникает проблема с тем, что инсталлятор не может определить где находится Java SDK. Решается следующим образом:

  1. Открываем свойства компьютера, выбираем пункт «Дополнительные параметры системы»
  2. На вкладке «Дополнительно» жмем на кнопку «Переменные среды…»
  3. В верхний список «Переменные среды пользователя…» добавляем новый элемент (нажимаем на кнопку «Создать..»)
  4. В появившемся диалоговом окне в поле «Имя переменной:» вставляем «JAVA_HOME», в поле «Значение переменной»: полный путь к корневой директории Java SDK, например: «D:\Program Files\Java\jdk1.7.0_17»
  5. Снова запускаем инсталлятор (или нажимаем кнопку «Назад», а затем «Вперед») — все должно заработать.

Дальше устанавливаем саму SDK и в конце запускаем Android SDK Manager. В качестве устанавливаемых пакетов необходимо как минимум следующее:

  1. Android SDK Tools
  2. Android SDK Platform-tools
  3. Версия Android для которой будет вестись разработка (можете установить все в пакете, лучше больше, если вам не до конца понятно что там конкретно)
  4. Версия Android для минимальной совместимости (обычно это версия 2.2), также рекомендую поставить версию 3.0, так как там есть некоторые переходные моменты (это как бы минимальная версия для некоторых возможностей 4-й версии)
  5. Жмем «Install packages» и ждем загрузки (размер не маленький сразу предупреждаю)
  6. В открывшемся окне проверяем чтобы для всех пакетов вы приняли лицензию (иначе они не установятся). Т.е. слева пакеты — справа окно лицензии с галкой «Согласен», проверьте чтобы пакеты загорелись зелеными маркерами слева.

Далее необходимо настроить Java SDK и непосредственно Android SDK.Для этого в открывшимся окне выбора проектов IDE нажимаем «Ctrl+Shift+Alt+S» (для настройки платформ) и выбираем пункт «SDKs». Нажимаем кнопку «+» вверху, выбираем «JDK» (без этого Android SDK работать не будет, т.к. IDE не знает для какой версии Java вы настраиваете Android SDK. Указываете где расположена ваш версия Java SDK (SE) и нажимаете «Ok».

Теперь в том же окне добавляем Android SDK — указываем его расположение.

Все, на этом ваша IDE полностью готова к началу разработки приложений для платформы Android.

Источник

Intellij idea android sdk установка

A Software Development Kit , or an SDK , is a collection of tools that you need to develop an application for a specific software framework. For example, to develop applications in Java, you need a Java SDK (JDK). SDKs contain binaries, source code for the binaries, and documentation for the source code. JDK builds also contain annotations.

Generally, SDKs are global. It means that one SDK can be used in multiple projects and modules. After you create a new project and define an SDK for it, you can configure modules in this project to inherit its SDK. You can also specify an SDK for each module individually. For more information, refer to Change module SDK.

Supported SDKs

Define an SDK

To define an SDK means to let IntelliJ IDEA know in which folder on your computer the necessary SDK version is installed. This folder is called an SDK home directory .

Configure global SDKs

From the main menu, select File | Project Structure | Platform Settings | SDKs .

To add an SDK, click , select the necessary SDK and specify its home directory in the dialog that opens.

Only for JDKs: if you don’t have the necessary JDK on your computer, select Download JDK . In the next dialog, specify the JDK vendor, version, change the installation path if required, and click Download .

Set up a project SDK

From the main menu, select File | Project Structure | Project Settings | Project .

If the necessary SDK is already defined in IntelliJ IDEA, select it from the SDK list.

If the SDK is installed on your computer, but not defined in the IDE, select Add SDK | ‘SDK name’ , and specify the path to the SDK home directory.

Only for JDKs: If you don’t have the necessary JDK on your computer, select Add SDK | Download JDK . In the next dialog, specify the JDK vendor, version, change the installation path if required, and click Download .

Set up a module SDK

From the main menu, select File | Project Structure | Project Settings | Modules .

Select the module for which you want to set an SDK and click Dependencies .

If the necessary SDK is already defined in IntelliJ IDEA, select it from the Module SDK list.

If the SDK is installed on your computer, but not defined in the IDE, select Add SDK | ‘SDK name’ , and specify the path to the SDK home directory.

Only for JDKs: If you don’t have the necessary JDK on your computer, select Add SDK | Download JDK . In the next dialog, specify the JDK vendor, version, change the installation path if required, and click Download .

Читайте также:  Как управлять телефоном с помощью голоса андроид гугл

If you want a module to inherit a project SDK, select the Project SDK option from the Module SDK list.

Java Development Kit (JDK)

To develop applications in IntelliJ IDEA, you need a Java SDK (JDK). A JDK is a software package that contains libraries, tools for developing and testing Java applications (development tools), and tools for running applications on the Java platform (Java Runtime Environment — JRE).

The JRE can be obtained separately from the JDK, but it’s not suitable for application development, as it doesn’t have essential components such as compilers and debuggers.

The bundled JRE is used for running the IDE itself, and it’s not sufficient for developing Java applications. Before you start developing in Java, download and install a standalone JDK build.

Due to the changes in the Oracle Java License, you might not have the rights to use Oracle’s Java SE for free. We recommend that you use one of the OpenJDK builds to avoid potential compliance failures.

In IntelliJ IDEA, you can download a JDK package right from the IDE, or you can manually download the necessary JDK distribution and define it in the IDE.

For a manual download, use any available distribution that you like, for example:

If you don’t know which distribution to choose, and you don’t have specific requirements that instruct you to use one of the existing distributions, use Oracle OpenJDK.

Set up the project JDK

From the main menu, select File | Project Structure | Project Settings | Project .

If the necessary JDK is already defined in IntelliJ IDEA, select it from the SDK list.

If the JDK is installed on your computer, but not defined in the IDE, select Add SDK | JDK , and specify the path to the JDK home directory (for example, /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk ).

If you don’t have the necessary JDK on your computer, select Add SDK | Download JDK . In the next dialog, specify the JDK vendor, version, change the installation path if required, and click Download .

Apply the changes and close the dialog.

If you build your project with Maven or Gradle, refer to Change the JDK version in a Maven project and Gradle JVM selection respectively for more information on how to work with JDKs.

Configure SDK documentation

You can add SDK documentation to IntelliJ IDEA so that you can get information about symbols and method signatures right from the editor in the Quick documentation popup.

You can also configure external documentation by specifying the path to the reference information online. External documentation opens the necessary information in a browser so that you can navigate to related symbols and keep the information for further reference at the same time.

Specify SDK documentation paths

To view external SDK documentation, configure the documentation URL first.

In the Project Structure dialog Ctrl+Alt+Shift+S , select SDKs .

Select the necessary SDK version if you have several SDKs configured, and open the Documentation Path tab on the right.

Click the icon, enter the external documentation URL, and click OK .

For example, for Java 14, type https://docs.oracle.com/en/java/javase/14/docs/api/ .

Apply the changes and close the dialog.

Access SDK documentation offline

If you work offline, you can view external documentation locally.

Download the documentation package of the necessary version.

The documentation package is normally distributed in a ZIP archive that you need to unpack once it is downloaded.

For example, you can download the official Java SE Development Kit 14.0.1 Documentation and unzip it.

In the Project Structure dialog Ctrl+Alt+Shift+S , select SDKs .

Select the necessary JDK version if you have several JDKs configured, and open the Documentation Path tab on the right.

Click the icon and specify the directory with the downloaded documentation package (for example, C:\Users\jetbrains\Desktop\docs\api ).

Apply the changes and close the dialog.

When the documentation is configured, you can open it in the editor.

Источник

Tutorial: Create your first Android application

In this tutorial, we will create a simple yet fully-functional Android application that counts how many times you tap a droid image. After that, we will run it on an Android virtual device.

This tutorial covers a simple scenario to help you get started with Android development in IntelliJ IDEA. For comprehensive how-to guides and reference documentation, visit the Android Studio user guide.

Create a new Android project

Create a project

Launch IntelliJ IDEA. On the Welcome screen, click New Project . If you already have a project open, from the main menu select File | New | Project .

In the New Project wizard, select Android on the left.

If you don’t have the Android SDK configured, IntelliJ IDEA will detect this and prompt you to download it:

Select the components you want to install. If you haven’t installed the Android SDK tools before, all the required components will be preselected.

Optionally, modify the location for the Android SDK, and click Next :

Review the installation settings and click Finish to start the download:

When all components have been downloaded and installed, click Finish :

Читайте также:  Huawei band 6 не приходят уведомления whatsapp android

Select Empty Activity as the project template:

On the last step, type HelloDroid as the project name and select Java as the language:

Configure project JDK

Now that we have created our first project, let’s make sure it uses the correct JDK.

From the main menu, choose File | Project Structure and go to Platform Settings | SDKs . Select the Android SDK and make sure that the correct Java version is selected in the Java SDK field.

We recommend that you use Java SE 11 or Java SE 8 for Android development in IntelliJ IDEA. If you don’t have the correct JDK installed, in the Project Structure dialog, click the Add New SDK button on the toolbar and select Download JDK :

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Build, Execution, Deployment | Build Tools | Gradle and select the correct Java version (8.x or 11.x).

Explore the project structure

For Android projects, there’s a dedicated view in the IntelliJ IDEA Project tool window: click Project in the top-left corner and select Android .

This view doesn’t reflect the actual hierarchy of files on your disk — it is organized by modules and file types to ease navigation between source files of your project. Note that it hides project files and directories that you don’t commonly use (to see them, choose the Project view):

The app folder consists of the following subfolders:

manifests : contains the AndroidManifest.xml file, which holds general information about the application processed by the Android operating system. Among other things, it declares the package name that serves as a unique identifier for your application and the minimum version of the Android SDK required for the device where the application will run. It also declares the entry points of the application, along with permissions the application requires. For details, see App Manifest Overview.

java : contains the Java source code files grouped by packages, including JUnit tests.

res : contains all non-code resources, such as XML layout files, UI strings, images, and so on.

The Gradle Scripts folder contains all the project’s build-related configuration files.

Edit the UI layout

At this stage, the user interface of our sample HelloDroid application is based on a very simple layout defined in the activity_main.xml file located in the res/layout folder.

Let us modify the auto-generated user interface and see how the application layout is rendered without running it on any physical or virtual device.

Open the UI designer

In the Android project view, go to the app/res/layout and double-click the activity_main.xml file to open it. Note that since IntelliJ IDEA downloads the components required to render layout files, opening it may take a few seconds.

If the UI designer fails to open, and you get the Design editor is unavailable until after a successful project sync error, press Ctrl+Shift+A , search for the Sync Project with Gradle Files action, and wait for the sync to finish.

By default, IntelliJ IDEA provides a graphical view of the layout file, but you can also switch to the source code view, or view the text and the graphical representation side by side — use the icons in the top-right corner of the UI Designer pane:

This pane shows a rectangular canvas that is synchronized with the layout definition and with the Component Tree , so any changes to the canvas are reflected there accordingly.

Normally, layout files have a layout manager as their root element (for example, LinearLayout , FrameLayout , ConstraintLayout , and so on). In our example, the root element in activity_main.xml is ConstraintLayout that is responsible for positioning the elements of the application interface. For the purpose of this tutorial, we are not going to modify it, but you can learn more about designing interfaces from Build a Responsive UI with ConstraintLayout.

To eliminate distraction and only see how your layout is represented, click the Select Design Surface icon in the top-left corner and choose Design :

Now let’s delete the existing text element. To do this, right-click the text label and choose Delete from the context menu.

Now the UI layout looks like the following, and we are ready to start designing the layout of our application:

Add image to the UI layout

Now let’s add a droid image to our layout.

In the Android project view, expand the app/res folder and drag the image you want to use into the drawable folder. For this tutorial, we’ve downloaded a Hello Droid image from the Internet and saved it with the dimensions 50×50 px.

Return to the activity_main.xml file opened in the Designer pane, from the Palette choose the ImageView element, and drag it to the canvas to the position where you want the image to appear.

In the Pick a Resource dialog that opens, choose the resource file you’ve added and click OK :

Next, we need to modify the default id of the imageView element to be able to reference it later.

Select it in the Component Tree and in the Attributes pane on the right, enter the new identifier in the id field: droidImage . Press Enter ; in the dialog that opens, confirm that you want to update all references to the image element id:

Читайте также:  Как изменить версию андроида без прошивки

Add text to the UI layout

Now let’s add some text to our layout.

In the Palette pane, pick the TextView element and drag it to the canvas below the image.

The widget displays some default text: TextView . To change it and link it to a string, we need to create a new text resource.

Select the textView element in the Component Tree on the left. In the Attributes pane on the right, click the Pick a Resource icon next to the text attribute:

In the dialog that opens, click the Add resource to the module icon in the top left corner and choose String Value .

In the New String Value dialog, enter the resource name ( welcome_text ) and the resource value ( Hello! I’m a droid. ):

Click OK to save the value and then click OK in the Pick a Resource dialog.

Now let’s modify the textView element id the same way we did with imageView .

Select textView in the Component Tree on the left, and in the Attributes pane set the id to a new value: clickCounter .

Add style to text

Now let’s add some style to the text to make it look more appealing.

Pad the text a bit: locate the padding attribute, and set all values to 10dp :

Change the font color: locate the textColor attribute, and click the Pick a Resource icon next to it.

In the dialog that opens, click the Add resource to the module icon in the top left corner and choose Color Value .

Enter the resource name ( text_color ) and the value ( #9C27B0 ):

Change the font size: locate the TextSize property and click the Pick a Resource icon next to it.

In the dialog that opens, click the Add resource to the module icon in the top left corner and choose Dimension Value .

Enter the resource name ( text_size ) and the value ( 24sp ):

As a result, your user interface now looks like the following:

To check what your application UI looks like in landscape orientation, click the Orientation for Preview icon on the Designer toolbar and choose Landscape :

To preview what your layout looks like on different devices, select another device from the device list:

Make the application interactive

Although our sample application is fully functional at this point, it does not support any form of interaction yet. Let’s modify it to support tap events.

In the Android project view, locate the MainActivity file under app\java\com.example.hellodroid and double-click to open it.

MainActivity is not a very meaningful class name, so let’s rename it.

Right-click this file in the Android project view and choose Refactor | Rename from the context menu or press Shift+F6 . In the dialog that opens, change the class name HelloDroidActivity and click Refactor :

All references to this class will be updated automatically, and your application’s source code will look as follows:

Replace the code in HelloDroid.java with the following:

Note that the identifiers we’ve used in the source code correspond to those we’ve set in our layout definition file, otherwise our code would not work.

Build and run the application

Now let’s build our application and run it on a virtual device.

Configure Android virtual device

First of all, to be able to run our application, we need to configure a virtual device.

In the main IntelliJ IDEA toolbar, click the devices list and choose AVD Manager :

On the first step of the wizard, click Create Virtual Device :

On the next step, we need to select the hardware that our virtual device will emulate.

Let’s select Phone on the left, and choose Pixel 2 as the target device:

Choose the system image you want to mimic on the virtual device, that is the OS version, the Android API level, the application binary interface (ABI), and the target SDK version:

Click the Download link next to the system image you want to mimic on the virtual device. For this tutorial, we’ve chosen to download the R system image.

In the License Agreement dialog that opens, read the license agreement and accept it, then click Next and wait for the download to finish. When the system image has been downloaded, select it and click Next in the System Image step of the wizard.

On the last step, you can modify your virtual device name and select the startup size and orientation of the screen. Choose the portrait layout and click Finish :

The newly configured device appears in the Android Virtual Device Manager .

Run the application

On the main IntelliJ IDEA toolbar, make sure the automatically created Run configuration and the virtual device we’ve just configured are selected and click :

The Android emulator will launch after the build has successfully finished, with our application started:

Click the droid image and see how the application processes the tap events, counts them and returns the corresponding message:

For information on how to run the app on a hardware device, refer to Android Studio: Run apps on a hardware device.

Источник

Оцените статью