Writing Kotlin in Cursor on Ubuntu: can Android Studio install the SDK, and which JDK should Gradle use?

July 15, 2025

I wanted to write a Kotlin Android app in Cursor on Ubuntu. The first instructions I found said to download command-line tools, unpack them into a specific directory, then install packages one at a time. Could I install Android Studio first and let it handle that preparation?

Yes. Android Studio can create the project, install the Android SDK (the tools needed to compile and debug Android apps), and manage emulators. Cursor can open the very same project directory. Both use the project’s Gradle build scripts to produce the same application. Switching editors doesn’t require a second SDK.12

Which steps does installing Android Studio first save?

  1. Start Android Studio following the Linux installation instructions and complete the initial setup wizard so it downloads the recommended SDK components. For a regular Android app, select New Project → Empty Activity and choose Kotlin. The template generates a Jetpack Compose interface. Click Run to deploy the app to the selected device.34
  2. Open Tools → SDK Manager and note the Android SDK Location. In SDK Platforms, install the Android platform version required by the project’s compileSdk. In SDK Tools, check that Build-Tools (for building the installable package) and Platform-Tools (including adb for connecting devices) are present. For a virtual device, also install Android Emulator, then create and start a device with a system image in Device Manager.1
  3. Normally you can add or remove components in SDK Manager. Only if you want to manage packages with sdkmanager in the terminal do you need to make sure Android SDK Command-line Tools (latest) is installed. Select it in SDK Manager without downloading a separate ZIP.5

For a physical Android phone, enable developer options and USB debugging, connect it to the computer, and authorize the computer for debugging on the phone. For a virtual tablet, Linux hardware acceleration requires another host-side check. See Checking whether Android Emulator is using KVM.6

How do I build, install, and see my changes in Cursor?

In Cursor, choose Open Folder and open the outermost directory containing gradlew and settings.gradle.kts. gradlew is the Gradle Wrapper supplied with the project, which uses the Gradle version the project specifies. Edit the template’s greeting in Cursor and save. The rest can all be done in its ordinary terminal. Editor extensions only affect the editing experience.2

First make sure the terminal can find two things. One is the Android SDK from the previous step. The other is a JDK (Java Development Kit), which Gradle needs to run on the computer even for apps written in Kotlin. Android Studio bundles an OpenJDK-based JetBrains Runtime (JBR). If its version meets your project requirements, the terminal can use the same one. For example, if you unpacked Studio’s official archive to /opt/android-studio and the SDK uses Ubuntu’s common location, configure them as follows. Substitute your actual paths in both places.71

export ANDROID_HOME="$HOME/Android/Sdk"
export JAVA_HOME="/opt/android-studio/jbr"
export PATH="$JAVA_HOME/bin:$ANDROID_HOME/platform-tools:$PATH"

./gradlew --version
./gradlew :app:assembleDebug
adb devices

These environment variables apply to the current terminal. To reuse them in new Bash sessions, put the three export lines in ~/.bashrc. The first Gradle command shows the Gradle and Java versions. Its first run may download build tools. The second builds a debug install package for the template’s app module. On success, you’ll see BUILD SUCCESSFUL. This step works without a phone. Once adb devices lists your target with status device, run ./gradlew :app:installDebug, open the app from the device’s app list, and check the greeting. If your module has another name, replace :app with that name.26

They’re all called OpenJDK. Which ones are open source and free for commercial use?

Next I looked into OpenJDK, Microsoft’s distribution, and Eclipse Temurin. I also searched for what to do if Ubuntu couldn’t find temurin-21-jdk. Before choosing one, ask: Which major Java version does my project need, who supplies its updates, and what uses does this particular download permit?

OpenJDK is an open-source project. Different maintainers can build and distribute installable JDKs from its source. Those are the “distributions” discussed here. A common OpenJDK license is GPLv2 with the Classpath Exception, which allows independent programs to link to the covered library under their own licenses. Licensing, what it costs to download the binaries, and how long a vendor commits to updates or support are three separate questions.8

Name on the download page or in the package managerWhat it means for this Ubuntu development machine
Ubuntu’s OpenJDK packagesFor an open-source JDK that’s free for commercial use and updates through the system package manager, check whether Ubuntu’s repositories have the required version. If the project needs 17, for example, use sudo apt install openjdk-17-jdk.98
Eclipse Temurin (Adoptium)Free for development and commercial use, with binaries under GPLv2 plus the Classpath Exception. For temurin-21-jdk, configure the repository for your OS version using Adoptium’s Debian/Ubuntu instructions and update the package index, or choose an official archive.1011
Microsoft Build of OpenJDK, Amazon CorrettoBoth are OpenJDK distributions available free for production use on Ubuntu. If your team has standardized on one, follow its chosen version and update channel.1213
Azul Zulu, Red Hat build of OpenJDKZulu CA community packages are free. SA packages come with a subscription. Red Hat provides an OpenJDK distribution, and enterprise support entitlements can come with a RHEL (Red Hat Enterprise Linux) subscription. Consider the kind of support you need when comparing procurement costs.1415
Oracle OpenJDK, Oracle JDKOracle’s OpenJDK builds use an open-source license. Downloads called Oracle JDK depend on the exact update number. In July 2025, Oracle JDK 21 updates were still under NFTC terms permitting free commercial use. Oracle JDK 17 had switched to OTN terms starting at 17.0.13, allowing free development and testing with separate conditions for general commercial production.16

If the immediate goal is compiling the Android app from Cursor, use the compatible JBR you already have. If you also want a standalone open-source JDK for other terminal projects, Ubuntu’s OpenJDK packages and Temurin both meet the free commercial use requirement. Ubuntu’s package lets you stick with system repositories. Temurin lets developers on different operating systems standardize on one distribution.7109

Why can Android Studio build successfully while Cursor’s terminal reports the wrong Java version?

Android Studio’s build button uses the project’s Gradle JDK setting under Settings → Build, Execution, Deployment → Build Tools → Gradle. The Wrapper in an ordinary terminal checks JAVA_HOME first, then searches PATH if it’s unset. Also check whether the project separately sets a JDK for the Gradle daemon. Point both at the same compatible JDK and inspect ./gradlew --version to locate the discrepancy.7

PatientComm’s first commit, for example, used Android Gradle Plugin (AGP, the plugin that integrates Android projects with the Gradle build) 8.11.1 and Gradle 8.13. That AGP series requires at least JDK 17 to run the build. The project also set jvmTarget = "11", which controls the Java bytecode version generated by the Kotlin compiler. For recreating this project’s environment, JDK 17 and 21 both meet the toolchain’s requirements. For newer versions check the Wrapper’s compatibility table. Java 25, for instance, first gained support for running Gradle in 9.1.0. Once the build JDK is compatible, the app can still emit Java 11 bytecode.17718

That leaves a specific answer for my original setup. PatientComm’s local Android Studio configuration selected GRADLE_LOCAL_JAVA_HOME, and the corresponding file pointed to Studio’s bundled jbr. I read Temurin’s and Microsoft’s installation documentation. What the project confirms is that Studio used JBR. The next day I had a new question: How can I create a Kotlin Multiplatform project when the template is missing from Android Studio on Ubuntu?

References

Footnotes

  1. Google. (n.d.). Command-line tools. Android Developers. SDK 目录、环境变量与各工具包。 ↩ ↩2 ↩3

  2. Google. (n.d.). Build your app from the command line. Android Developers. Build a debug APK。 ↩ ↩2 ↩3

  3. Google. (n.d.). Install Android Studio. Android Developers. Linux 安装与 Setup Wizard。 ↩

  4. Google. (n.d.). Quick start. Android Developers. 创建使用 Compose 的新应用。 ↩

  5. Google. (n.d.). sdkmanager. Android Developers. SDK Manager 与 Command-Line Tools。 ↩

  6. Google. (n.d.). Run apps on a hardware device. Android Developers. 连接设备与 USB 调试。 ↩ ↩2

  7. Google. (n.d.). Java versions in Android builds. Android Developers. Android Studio、Gradle 和终端如何选择 JDK。 ↩ ↩2 ↩3 ↩4

  8. OpenJDK. (n.d.). GNU General Public License, version 2, with the Classpath Exception. OpenJDK. 许可证与文末 Classpath Exception。 ↩ ↩2

  9. Canonical. (n.d.). Available Java versions. Ubuntu for Developers. 各 Ubuntu 版本对应的 OpenJDK 包。 ↩ ↩2

  10. Eclipse Adoptium. (n.d.). Frequently asked questions. Adoptium. Temurin 二进制包的许可与费用。 ↩ ↩2

  11. Eclipse Adoptium. (n.d.). Linux (RPM/DEB/APK) installer packages. Adoptium. Debian/Ubuntu 软件包安装步骤。 ↩

  12. Microsoft. (2021, April). Announcing Microsoft Build of OpenJDK. Microsoft for Java Developers. 发行与使用条件。 ↩

  13. Amazon Web Services. (n.d.). Amazon Corretto FAQs. AWS. 使用成本、许可与长期支持。 ↩

  14. Azul. (2020, October 23). What’s the difference between CA and SA bundles of Azul Zulu Builds of OpenJDK? Azul Support. CA 与 SA 的分发条件。 ↩

  15. Red Hat. (n.d.). OpenJDK life cycle and support policy. Red Hat Customer Portal. OpenJDK 来源与支持权益。 ↩

  16. Oracle. (2026, October 20). Oracle Java SE licensing FAQ. Oracle. Oracle JDK and Oracle OpenJDK LTS License Guide,按更新号列出的历史许可。 ↩

  17. Google. (2025, June). Android Gradle Plugin 8.11.0. Android Developers. Compatibility。 ↩

  18. Gradle. (n.d.). Compatibility matrix. Gradle User Manual. Java Compatibility 表中 Support for running Gradle 一列。 ↩

© 2025 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2025-07-15). Writing Kotlin in Cursor on Ubuntu: can Android Studio install the SDK, and which JDK should Gradle use?. https://caiborui.com/blog/2025-07-15-zh-ubuntu-cursor-android-studio-jdk-entrans

@misc{borui2025-104aea30,
  author = {borui},
  title = {{Writing Kotlin in Cursor on Ubuntu: can Android Studio install the SDK, and which JDK should Gradle use?}},
  year = {2025},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2025-07-15-zh-ubuntu-cursor-android-studio-jdk-entrans}
}