How to fix 16 KB page size / ELF alignment error in Flutter on Android 14+


Flutter APK fails on Android 14+ with 16 KB page size error after SDK upgrade – how to fix 16 KB alignment?

What are the required steps to make a Flutter app compatible with Android 14 (16 KB page size)?

Specifically:

  • Which Android Gradle Plugin and Gradle versions are required?

  • Do I need a specific NDK version?

  • How do I fix native .so library alignment issues coming from Flutter plugins?

  • Is there a way to identify which dependency is causing the 16 KB error?

Any guidance or best practices to fully resolve 16 KB alignment issues in Flutter would be appreciated.

PS C:\abhisek\spay> flutter --version

Flutter 3.32.4 • channel [user-branch] • unknown source

Framework • revision 6fba2447e9 (8 months ago) • 2025-06-12 19:03:56 -0700

Engine • revision 8cd19e509d (8 months ago) • 2025-06-12 16:30:12 -0700

Tools • Dart 3.8.1 • DevTools 2.45.1

app/build.gradle

plugins {
    id "com.android.application"
    // ...
    id "kotlin-android"
    // Make sure that you have the Google services Gradle plugin
    id 'com.google.gms.google-services'

    // Add the Crashlytics Gradle plugin
    id "com.google.firebase.crashlytics"
    id "dev.flutter.flutter-gradle-plugin" // <--- Add this
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
//apply plugin: 'kotlin-android'
//apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'dev.flutter.flutter-gradle-plugin'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
kotlin {
    jvmToolchain(17)
}
android {
    namespace 'app.spayindia.com'
    compileSdkVersion 36
    ndkVersion "29.0.13599879 rc2"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17//changed
        targetCompatibility JavaVersion.VERSION_17
        coreLibraryDesugaringEnabled true
    }

    kotlinOptions {
        jvmTarget = '17'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    kotlin {
        jvmToolchain(17)
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    //added
    buildFeatures {
        buildConfig = true
    }

    defaultConfig {
        applicationId "app.spayindia.retailer"
        // applicationId "app.spayindia.com"
        minSdkVersion 24
        targetSdkVersion 36
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        ndk {
            abiFilters 'arm64-v8a', 'x86_64'  // Keep only arm64-v8a for now
        }
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {

            shrinkResources false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug
//            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"//changed
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'  //changed
    implementation 'com.google.android.material:material:1.3.0'
    implementation platform('com.google.firebase:firebase-bom:29.0.3')
    implementation('com.google.firebase:firebase-analytics') {
        exclude module: "play-services-safetynet"
    }

    //firebase
    implementation("com.google.firebase:firebase-crashlytics")
    implementation("com.google.firebase:firebase-analytics")

    //micro atm service

    implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.56'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.2'
    implementation files('../libs/matm.aar')
    implementation files('../libs/mosambeelib.aar')
    implementation files('../libs/morefun.jar')

    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.squareup.okio:okio:1.14.0'

    //credopay sdk:3.0.10'
//    implementation('in.credopay.payment.sdk:vm30-payment-sdk:3.0.10')
    implementation 'in.credopay.payment.sdk:vm30-payment-sarata-sdk:4.0.37'
    implementation "org.slf4j:slf4j-android:1.7.36"
}
//added
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
    kotlinOptions {
        jvmTarget = "17"
    }
}
configurations.all {
    exclude group: 'com.google.android.gms', module: 'play-services-safetynet'
}

android/build.gradle

buildscript {
    ext.kotlin_version = '2.2.0'//changed
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.5.1'  //changed
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        maven { url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/' }
       
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
    configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute module("io.flutter:arm64_v8a_debug") using module("io.flutter:arm64_v8a_debug:1.0.0-8cd19e509d6bece8ccd74aef027c4ca947363095") because "Exclude from Jetifier"
            substitute module("io.flutter:armeabi_v7a_debug") using module("io.flutter:armeabi_v7a_debug:1.0.0-8cd19e509d6bece8ccd74aef027c4ca947363095") because "Exclude from Jetifier"
            substitute module("io.flutter:x86_debug") using module("io.flutter:x86_debug:1.0.0-8cd19e509d6bece8ccd74aef027c4ca947363095") because "Exclude from Jetifier"
            substitute module("io.flutter:x86_64_debug") using module("io.flutter:x86_64_debug:1.0.0-8cd19e509d6bece8ccd74aef027c4ca947363095") because "Exclude from Jetifier"
        }
    }
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}








settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
    id "com.android.application" version "8.5.1" apply false
    id "org.jetbrains.kotlin.android" version "2.2.0" apply false
}

include ":app"


pubspec.yaml


name: spayindia
description: Spay India a money response based fintech application service

version: 2.0.0+20

environment:
  sdk: '>=3.2.0 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
 # qr_code_scanner:
  #  git:
   #   url: https://github.com/juliuscanute/qr_code_scanner.git
    #  ref: master
  share_plus: ^7.2.1
  get: ^4.6.6
  shared_preferences: ^2.2.2
  device_info_plus: ^9.0.3
  freezed: ^2.5.2
  freezed_annotation:
  dio: ^5.8.0+1
  encrypt: ^5.0.1
  font_awesome_flutter: ^10.8.0
  pretty_dio_logger: ^1.1.1
  connectivity_plus: ^6.0.3
  screenshot: ^3.0.0
  path_provider: ^2.0.6
  lottie: ^3.1.3
  dropdown_search: ^5.0.6
  cupertino_icons: ^1.0.2
  geolocator: ^11.1.0
  app_settings: ^6.1.1
  image_picker: ^1.2.1
  image_cropper: 8.0.2
  intl: ^0.18.1
  flutter_image_compress: ^2.1.0
  infinite_scroll_pagination: ^4.1.0
  qr_flutter: ^4.0.0
  #image_gallery_saver: ^2.0.3
  permission_handler: ^11.3.1
  countdown_progress_indicator: ^0.1.2
  dotted_border: ^2.0.0+2
  #flutter_html_to_pdf: ^0.7.0
  open_filex: ^4.3.4
  number_to_words: ^1.0.0

  in_app_update: ^4.2.3
  #upgrader: ^4.1.2
  #new_version: ^0.3.0
  flutter_svg: ^2.0.10+1
  dart_ipify: ^1.1.1
  webview_flutter: ^4.5.0
  local_auth: ^2.1.8
  carousel_slider: ^5.1.1
  smooth_page_indicator: ^1.0.0+2
  cached_network_image: ^3.3.0

  #safe_device: ^1.1.1
  #palestine_trusted_device: ^0.1.flutter clean
  #flutter pub upgrade
  #flutter pub get1
  win32: ^5.1.0  # Try an older compatible version

  url_launcher: ^6.2.5
  firebase_core: ^2.27.0
  firebase_crashlytics: ^3.4.18
  #firebase_crashlytics: ^2.6.2
  #cloud_firestore: ^3.1.6
  #firebase_core: ^1.18.0
  flutter_ringtone_player: ^4.0.0+4
  animated_widgets: ^1.1.0
  #htmltopdfwidgets: ^0.0.9+1
  flutter_native_html_to_pdf: ^1.0.1
  package_info_plus: 9.0.0
  installed_apps: ^1.5.0
  geocoding: ^3.0.0
  mobile_scanner: ^3.5.1
  sqflite: ^2.4.2



dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner:
  flutter_lints: ^4.0.0
  flutter_native_splash: ^2.3.6


flutter:

  uses-material-design: true
  assets:
    - assets/image/
    - assets/svg/
    - assets/lottie/
    - assets/json/
    - assets/html/
    - assets/sound/






-2
Feb 3 at 8:44 AM
User AvatarAbhisek pattnaik
#android#flutter#kotlin#gradle#android-ndk

No answer found for this question yet.