free geoip
34

Kotlin App Not Supporting Android 13 or 14

Many developers face the issue where their Kotlin app is not supporting Android 13 or 14. This usually happens due…

Many developers face the issue where their Kotlin app is not supporting Android 13 or 14. This usually happens due to changes in the Android SDK, permissions system, and compatibility settings. If your app crashes, fails to install, or certain features are broken on Android 13 or Android 14, then you need to check your project configuration, SDK targets, and permissions. This article will guide you through the steps to fix compatibility issues with Android 13 and 14 in Kotlin-based Android apps.

Kotlin App Not Supporting Android 13 or 14

Why Your Kotlin App Does Not Support Android 13 or 14

Google introduced major changes in Android 13 (API level 33) and Android 14 (API level 34). Some of the most common causes why a Kotlin app fails to support these versions include:

  • Target SDK not updated: Your app still targets API level 31 or below.
  • New runtime permissions: Android 13 introduced POST_NOTIFICATIONS and other permission changes.
  • Exported attribute missing: Starting from Android 12, you must declare android:exported in your manifest.
  • Deprecated methods: Some APIs are no longer available or behave differently in Android 13 and 14.

Step 1: Update Your Gradle and SDK Versions

First, you must update your Gradle files to target Android 13 or 14 properly. In your build.gradle (app level), make sure you have:

android {
    namespace "com.example.myapp"
    compileSdk 34

    defaultConfig {
        applicationId "com.example.myapp"
        minSdk 21
        targetSdk 34
        versionCode 1
        versionName "1.0"
    }
}

Explanation:

  • compileSdk 34 ensures you can use Android 14 features.
  • targetSdk 34 tells Google Play that your app is compatible with Android 14.
  • minSdk defines the minimum Android version supported.

Step 2: Add Required Permissions

On Android 13, notification permissions became mandatory. If your app uses push notifications or local notifications, you must request POST_NOTIFICATIONS at runtime. Add this to your AndroidManifest.xml:

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

In Kotlin, request the permission:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
    if (ContextCompat.checkSelfPermission(
            this,
            android.Manifest.permission.POST_NOTIFICATIONS
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        ActivityCompat.requestPermissions(
            this,
            arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),
            101
        )
    }
}

Step 3: Declare android:exported in Activities

Starting from Android 12, you must declare android:exported for activities, services, and receivers with intent filters. Example:

<activity
    android:name=".MainActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Without this, your app may crash on Android 12, 13, or 14.

Step 4: Handle Foreground Services

Android 14 enforces stricter rules for foreground services. If your Kotlin app runs background tasks like location tracking or media playback, you must declare the correct foreground service type:

<service
    android:name=".MyForegroundService"
    android:foregroundServiceType="location|mediaPlayback"
    android:exported="false" />

And in Kotlin:

class MyForegroundService : Service() {
    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        val notification = NotificationCompat.Builder(this, "channel_id")
            .setContentTitle("Running Service")
            .setContentText("Service is active")
            .setSmallIcon(R.drawable.ic_launcher_foreground)
            .build()

        startForeground(1, notification)
        return START_STICKY
    }

    override fun onBind(intent: Intent?): IBinder? = null
}

Step 5: Test on Real Devices or Emulator

After updating your project configuration, test your app on Android 13 and Android 14 devices or emulators. Use Android Studio’s Emulator Manager to create devices running API 33 (Android 13) and API 34 (Android 14). This ensures your app behaves correctly under new restrictions.

Comparison Table: Before vs After Fixing

IssueBefore FixAfter Fix
Target SDKAPI 30 (Android 11)API 34 (Android 14)
Notification PermissionNot requested, app crashesPOST_NOTIFICATIONS requested at runtime
Activity DeclarationNo exported attributeandroid:exported=”true”
Foreground ServiceDeclared without typeDeclared with proper type (e.g., location)

Conclusion

If your Kotlin app is not supporting Android 13 or 14, the issue likely lies in outdated SDK targets, missing permissions, or new restrictions on services and activities. By updating your Gradle, requesting new permissions like POST_NOTIFICATIONS, declaring android:exported, and configuring foreground services properly, your app will run smoothly on the latest Android versions. Always test your app thoroughly on both emulators and physical devices to ensure compatibility before publishing updates to the Google Play Store.

For more information, you can check the official Android Developer Documentation.

rysasahrial

Leave a Reply

Your email address will not be published. Required fields are marked *