# Targeting Android in a Kotlin/Multiplatform Mobile library

DevFeed: [Targeting Android in a Kotlin/Multiplatform Mobile library](<https://devfeed.tech/articles/targeting-android-in-a-kotlin-multiplatform-mobile-library-22866.md>)

Original publisher: [Read original article](<https://medium.com/kodein-koders/targeting-android-in-a-kotlin-multiplatform-mobile-library-b6ab75469287?source=rss----f311f45ef54---4>)

Author: Salomon BRYS

Published: 2021-04-26T14:32:30Z

Content type: tutorial

Language: en

Sources: [Kodein Koders - Medium](<https://devfeed.tech/sources/kodein-koders-medium.md>)

Topics: [Kotlin Multiplatform](<https://devfeed.tech/topics/kotlin-multiplatform.md>), [Android](<https://devfeed.tech/topics/android.md>), [Android Gradle Plugin](<https://devfeed.tech/topics/android-gradle-plugin.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android Library](<https://devfeed.tech/topics/android-library.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [Library](<https://devfeed.tech/topics/library.md>), [Mobile](<https://devfeed.tech/topics/mobile.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-gradle-plugin](<https://devfeed.tech/tags/android-gradle-plugin.md>), [build](<https://devfeed.tech/tags/build.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [kotlin-multiplatform-mobile](<https://devfeed.tech/tags/kotlin-multiplatform-mobile.md>), [library](<https://devfeed.tech/tags/library.md>), [mobile](<https://devfeed.tech/tags/mobile.md>), [multiplatform](<https://devfeed.tech/tags/multiplatform.md>), [plugin](<https://devfeed.tech/tags/plugin.md>)

## AI overview

This tutorial explains how to target Android APIs from a Kotlin Multiplatform Mobile library. It advises developers to distinguish Android APIs from JVM APIs, then outlines an official approach using the Android Gradle plugin and Kotlin's Android target, as well as a lighter but more restrictive alternative. The official approach publishes an AAR instead of a JAR and supports Android resources such as images, XML files, and JNI native libraries.

## Source excerpt

https://medium.com/media/6c54678f49c79a047a73b582f72c478e/href So far, we've seen how to create a Kotlin/Multiplatform Mobile library, how to access iOS Swift APIs in it, and how to push it to Maven Central. We haven't discussed how to access Android APIs. Kotlin is the main Android programming language, so how difficult can it be ? Well, it turns out that the Android platform is not as simple as the JVM, so there are multiple strategies you can use to access Android APIs in your KMM libraries. Let's discuss them! First and foremost, you need to make sure that you actually need an Android API, and not a JVM API. You should not have your library target Android if the API you want to access is actually provided by the JVM. Most of the file access, date time, cryptography, and many more APIs are JVM APIs, and even if your library is supposed to be used especially on mobile targets, it is way simpler to target the JVM rather than adding the entire Android toolchain to your build. OK, so you're positive you need Android APIs? The way I see it, there are two ways you can add the Android APIs to the classpath of your library: There's the official way, which enables all Android capabilities to your library. There's the lighter way, a hack, really, which is more restrictive, but a lot simpler, which we'll discuss at the end of this video. The official way consists in adding the Android Gradle plugin to your build, as well as its corresponding Kotlin target & Android configuration. https://medium.com/media/b40d2cd887b34d8002fb3861463fd19b/href Adding the com.android.library plugins and defining an Android target, rather than a regular JVM target, has a notable effect: what will be published is an AAR (for Android ARchive) rather than a JAR (for Jvm ARchive). This means that the library can package Android resources, such as images, XMLs, or JNI native libraries. As you can see, most of the Android configuration is not happening in the kotlin block, but in the android block. T