You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio创建纯Kotlin业务逻辑库及应用的问题咨询

How to Create a Kotlin Library for Your Android App

Hey there! Since you're new to Android and the JVM platform, let's break down exactly which module option you need to pick, and why the others aren't the right fit for your goal of building a Kotlin-only library for your app's business logic.

The Correct Choice: Android Library

This is the option you want to select—here's why:

  • It’s purpose-built for creating reusable code libraries that integrate seamlessly with Android apps.
  • Android Studio fully supports Kotlin for this module type: when you go through the setup wizard, just make sure to select Kotlin as the language (it’s now the default in most recent versions).
  • It gives you access to Android-specific APIs (like Context, app resources, or lifecycle components) if your business logic needs them, while still letting you write pure Kotlin code that’s separate from your app’s UI layer.

Why the Other Options Aren’t Right for You

Let’s quickly clear up the rest to eliminate confusion:

  • Phone & Tablet module: This creates a full Android app, not a reusable library. You’ll use this for your main app module, not your business logic codebase.
  • Instant App Feature Module: Designed exclusively for building instant app components, not general-purpose business logic libraries.
  • Android Wear/TV/Things Modules: These are for building apps/libraries targeted at specific Android device types (wearables, TVs, IoT devices)—not your standard phone/tablet app’s core business logic.
  • Import Gradle/Eclipse/JAR/AAR Packages: These options are for importing existing code into your project, not creating a new library from scratch.
  • Java Library: This creates a pure JVM library with no Android-specific support. While you can write Kotlin here, it won’t have access to Android APIs if your business logic ever needs to interact with Android framework components. Unless your code is completely decoupled from Android (e.g., pure data processing with no app dependencies), stick with Android Library.

Quick Setup Tip

After selecting Android Library, in the configuration screen:

  • Name your library something descriptive (like app-business-logic)
  • Set the Language dropdown to Kotlin
  • Finish the wizard, and you’ll have a Kotlin-only Android library ready to hold your core business code. You can then add a dependency on this library from your main Phone & Tablet app module to use its functionality.

内容的提问来源于stack exchange,提问作者JamesFaix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:21:20