Search code examples
androidkotlinkotlin-multiplatformcompose-multiplatform

What is the easiest way to ask for Network Permissions?


I have a Compose Multiplatform app and I require the application to communicate with the server. Hence I have the Ktor-client stuff inside the shared/ module and the Ktor Server on server/ module.

I hosted the server on my local network and installed the application on my module. However, the logcat has the message:

enter image description here

I found out that this is because I do not have any network permissions on my Android app for my android phone. Coming from the native Android development side, I thought I could add this to the Manifest file (at composeApp/src/androidMain/AndroidManifest.xml):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />

    <application>...</application>
</manifest>

In a native android version, this would work. However, the app wouldn't install on my android phone with the uses-permission line.

How do I ask for Network permissions in my Compose Multiplatform application?


Solution

  • You don't want network permissions, you want cleartext permissions. Those are different. Network allows you to make a request to a server. You have that above. Cleartext allows you to make non-HTTPS requests (HTTP requests without encryption). The error you're showing is about not having cleartext permissions. That requires you to request cleartext by adding android:usesCleartextTraffic="true" to the application tag in your manifest. Please note that doing so may make your app rejected from the play store for security reasons.