Inicie o Koin no Android e no iOS
Inicialize o grafo a partir do ponto de entrada de cada plataforma
Inicie o Koin no Android e no iOS é uma aula grátis de Kotlin Multiplatform Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Kotlin Multiplatform Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Kotlin Multiplatform Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
A Module Needs Starting
Declaring modules is only half the job. Each platform must start Koin at launch so the container is ready before anything asks for a dependency.
A Shared Init Helper
Put the common startup in shared code with a small initKoin function. Both platforms call it, so the wiring never drifts apart.
fun initKoin() = startKoin {
modules(appModule())
}Pass Extra Platform Config
Give initKoin a parameter so each platform can append its own setup, like Android needing the application context.
fun initKoin(extra: KoinAppDeclaration = {}) =
startKoin { extra(); modules(appModule()) }Start Koin on Android
On Android, call initKoin from your Application class so the graph exists for the whole process lifetime.
class App : Application() {
override fun onCreate() {
super.onCreate()
initKoin()
}
}Give Android the Context
Android modules often need a Context. Pass it through the extra block using androidContext so definitions can resolve it.
initKoin { androidContext(this@App) }Register the Application Class
Remember to point your manifest at the custom Application class, or onCreate never runs and Koin never starts.
Start Koin on iOS
On iOS you call the same initKoin through the generated framework, typically from your SwiftUI App init or AppDelegate.
Call It from Swift
Koin exposes a tiny helper so Swift can launch the graph in one clean line at app startup. 🍎
// Swift
KoinKt.doInitKoin()Start Only Once
Call startKoin a single time per app launch. Starting it twice throws an error, so keep init in one obvious entry point.
Add Logging While Learning
Turn on printLogger during development so Koin prints what it builds, making missing-definition mistakes easy to spot.
startKoin {
printLogger()
modules(appModule())
}One Graph, Two Entry Points
The key idea: the same modules load from two platform entry points. Android uses its Application, iOS uses its App init, both share the wiring.
Quick Check
Where should startup logic live?
Recap
You exposed a shared initKoin, called it from Android's Application and iOS's App init, and learned to start it once with optional logging. The graph is live on both. ✅
Perguntas Frequentes
A aula “Inicie o Koin no Android e no iOS” é grátis?
Sim — o texto completo de “Inicie o Koin no Android e no iOS” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Kotlin Multiplatform Academy, atualize para CoddyKit PRO. O curso de Kotlin Multiplatform Academy inclui 4 aulas no total.
O que vou aprender em “Inicie o Koin no Android e no iOS”?
Inicialize o grafo a partir do ponto de entrada de cada plataforma Você pratica Kotlin Multiplatform Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Kotlin Multiplatform Academy?
Nenhuma experiência prévia é necessária. Kotlin Multiplatform Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.
Quanto tempo leva a aula “Inicie o Koin no Android e no iOS”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Kotlin Multiplatform Academy?
Sim. Cada aula de Kotlin Multiplatform Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Declare um módulo Koin compartilhado
- Scopes single versus factory
- Inicie o Koin no Android e no iOS
- Injete em ViewModels e repositórios