0Pricing
Kotlin Multiplatform Academy · Lección

Lectura de shared build.gradle.kts

Descifre el bloque kotlin{} y las declaraciones de destinos

Lectura de shared build.gradle.kts es una lección gratuita de Kotlin Multiplatform Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Kotlin Multiplatform Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Kotlin Multiplatform Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

The Module's Recipe

The shared build.gradle.kts is the recipe for your module: which targets to build and which libraries to pull in.

Plugins Come First

At the top, the plugins block turns on multiplatform support. Without it, Kotlin has no idea about targets.

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

The kotlin {} Block

Everything multiplatform lives inside the kotlin block. This is where targets and source sets are declared.

kotlin {
    // targets and source sets go here
}

Declaring Android

The androidTarget line tells Kotlin to produce an Android library artifact from your shared code.

kotlin {
    androidTarget()
}

Declaring iOS

iOS needs a few targets, one per architecture, so it runs on simulators and real devices alike.

iosX64()
iosArm64()
iosSimulatorArm64()

Naming the Framework

A binaries.framework entry names the iOS framework Swift will import. Pick a clean name your iOS team will type often.

iosArm64 {
    binaries.framework {
        baseName = "Shared"
    }
}

Source Set Dependencies

The sourceSets block lists libraries per set. commonMain gets cross-platform deps; platform sets get their own.

sourceSets {
    commonMain.dependencies {
        // shared libraries
    }
}

Common Dependencies Are Shared

A library added to commonMain must support every target. Add it here and all platforms can use it.

commonMain.dependencies {
    implementation("io.ktor:ktor-client-core:2.3.0")
}

Platform Dependencies

Platform-only libraries go in their own set, like an Android engine that only the JVM target understands.

androidMain.dependencies {
    implementation("io.ktor:ktor-client-okhttp:2.3.0")
}

Android Config Block

A separate android block sets the namespace and SDK levels for the Android library half of the module.

android {
    namespace = "com.example.shared"
    compileSdk = 34
}

Read It Top to Bottom

To grok any shared build file, read it as a story: plugins, then targets, then source sets, then platform config. 📖

Quick Check

Where does a cross-platform library belong?

Recap

The shared build.gradle.kts flows plugins to targets to source sets. Common deps for all, platform deps for one.

Preguntas frecuentes

¿La lección «Lectura de shared build.gradle.kts» es gratis?

Sí — el texto completo de «Lectura de shared build.gradle.kts» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Kotlin Multiplatform Academy, actualiza a CoddyKit PRO. El curso de Kotlin Multiplatform Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Lectura de shared build.gradle.kts»?

Descifre el bloque kotlin{} y las declaraciones de destinos Practicas Kotlin Multiplatform Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Kotlin Multiplatform Academy?

No se requiere experiencia previa. Kotlin Multiplatform Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.

¿Cuánto tiempo toma la lección «Lectura de shared build.gradle.kts»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Kotlin Multiplatform Academy?

Sí. Cada lección de Kotlin Multiplatform Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. El módulo shared frente a los módulos de la aplicación
  2. commonMain, androidMain e iosMain
  3. Lectura de shared build.gradle.kts
  4. Dónde viven las pruebas: commonTest y compañía
← Volver a Kotlin Multiplatform Academy