flutter-tflite icon indicating copy to clipboard operation
flutter-tflite copied to clipboard

[Android] 16KB Page Sizes support

Open contestormi opened this issue 4 months ago • 32 comments

Android 15 will offer an option for OEMs to use 16KB page sizes [1][2]. According to [1], all shared libraries shipped with Android apps must be recompiled to support 16KB page sizes.

[1] https://developer.android.com/guide/practices/page-sizes [2] https://source.android.com/docs/core/architecture/16kb-page-size/16kb

When will the library get its update?

contestormi avatar Aug 14 '25 08:08 contestormi

This is an important issue that will impact apps work

prudok avatar Aug 14 '25 08:08 prudok

Same here. Google requires support this for Android 15 otherwise my app will be restricted for updates. Ironic situation when google libraries doesn't met google requirements. For now this issue possibly affects on installations on Android 15 Samsung devices

Gradergage avatar Aug 14 '25 09:08 Gradergage

I've done digging and can confirm the plugin is enforcing -max-page-size=4096

This needs an immediate update, otherwise, a bunch of apps are being forced offline.

peazz avatar Aug 28 '25 17:08 peazz

@peazz is there any way we can change the page size Enforcing by our own and recompile it for our use case till there is any Official Update ?

Honestly, I am not sure, I done some digging and found this library is the culprit but that is all, I am overwhelmed handling my business alone. right now, I my circle back but this will likely need a update from the repo managers.

peazz avatar Aug 30 '25 16:08 peazz

Any update on when 16 KB support will be available?

bhanuka96 avatar Sep 06 '25 04:09 bhanuka96

When will it be updated to support 16 KB?

imrajdev avatar Sep 06 '25 09:09 imrajdev

any updates?

aleksandr-innsightful avatar Sep 17 '25 04:09 aleksandr-innsightful

any update?

dipu-polygontech avatar Sep 17 '25 12:09 dipu-polygontech

This package has not been updated since I started using it and even then, it's not fully functional.

I'm willing to bet that unless this is forked, we won't be getting 16kb page support which would only enable Google to collect on AI costs.

peazz avatar Sep 17 '25 12:09 peazz

did you find any better option?

dipu-polygontech avatar Sep 17 '25 12:09 dipu-polygontech

Any update? Because Google play console gives deadline time to 1 November 2025.

MdSharafat0 avatar Sep 18 '25 16:09 MdSharafat0

Any update or is there any fork we can use, because the deadline is till 1 November 2025

NOTtheKRish avatar Sep 20 '25 03:09 NOTtheKRish

any update?

nishit-dave avatar Sep 24 '25 10:09 nishit-dave

You can make it work if you skip the x86_64 libraries while keeping the ARM versions. Very few phones use them. Add this to build.gradle.kts in the android section:

        jniLibs {
            excludes.addAll(listOf(
                "**/x86_64/**",
                "**/x86/**",
                "lib/x86_64/**",
                "lib/x86/**"
            ))
            // Keep ARM versions of TensorFlow Lite
            pickFirsts.addAll(listOf(
                "**/arm64-v8a/libtensorflowlite_jni.so",
                "**/armeabi-v7a/libtensorflowlite_jni.so",
                "**/arm64-v8a/libtensorflowlite_gpu_jni.so",
                "**/armeabi-v7a/libtensorflowlite_gpu_jni.so"
            ))
        }
    }

and this to the defaultConfig section:

            noCompress.add(".tflite")
            noCompress.add(".lite")
        }
        // Only specify ndk filters, no splits
        ndk {
            abiFilters.clear()
            abiFilters.add("armeabi-v7a")
            abiFilters.add("arm64-v8a")
            // Explicitly exclude x86 architectures
        }

This is my buildTypes

        release {
            signingConfig = signingConfigs.getByName("release")
            isMinifyEnabled = true                    // Re-enable minification
            isShrinkResources = true                  // Re-enable resource shrinking
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

where progurard-rules.pro contains

-keep class org.tensorflow.lite.gpu.** { *; }
-dontwarn org.tensorflow.lite.gpu.**

# Additional TensorFlow Lite rules (if needed)
-keep class org.tensorflow.lite.** { *; }
-dontwarn org.tensorflow.lite.**

Now when I inspect the aab in Google Play I see

Native platforms  arm64-v8a, armeabi-v7a
API levels  24+
Target SDK  36
OpenGL ES versions  0.0+
OpenGL textures  No textures required
Memory page size  Supports 16 KB

BoHellgren avatar Sep 25 '25 19:09 BoHellgren

You can make it work if you skip the x86_64 libraries while keeping the ARM versions. Very few phones use them. Add this to build.gradle.kts in the android section:

        jniLibs {
            excludes.addAll(listOf(
                "**/x86_64/**",
                "**/x86/**",
                "lib/x86_64/**",
                "lib/x86/**"
            ))
            // Keep ARM versions of TensorFlow Lite
            pickFirsts.addAll(listOf(
                "**/arm64-v8a/libtensorflowlite_jni.so",
                "**/armeabi-v7a/libtensorflowlite_jni.so",
                "**/arm64-v8a/libtensorflowlite_gpu_jni.so",
                "**/armeabi-v7a/libtensorflowlite_gpu_jni.so"
            ))
        }
    }

and this to the defaultConfig section:

            noCompress.add(".tflite")
            noCompress.add(".lite")
        }
        // Only specify ndk filters, no splits
        ndk {
            abiFilters.clear()
            abiFilters.add("armeabi-v7a")
            abiFilters.add("arm64-v8a")
            // Explicitly exclude x86 architectures
        }

This is my buildTypes

        release {
            signingConfig = signingConfigs.getByName("release")
            isMinifyEnabled = true                    // Re-enable minification
            isShrinkResources = true                  // Re-enable resource shrinking
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

where progurard-rules.pro contains

-keep class org.tensorflow.lite.gpu.** { *; }
-dontwarn org.tensorflow.lite.gpu.**

# Additional TensorFlow Lite rules (if needed)
-keep class org.tensorflow.lite.** { *; }
-dontwarn org.tensorflow.lite.**

Now when I inspect the aab in Google Play I see

Native platforms  arm64-v8a, armeabi-v7a
API levels  24+
Target SDK  36
OpenGL ES versions  0.0+
OpenGL textures  No textures required
Memory page size  Supports 16 KB

Hi. It looks like a solution, but arm64-v8a library doesn't support 16KB page sizes either.

Image

rickgrotavi avatar Sep 26 '25 06:09 rickgrotavi

The app works on my Samsung Galaxy S24, which uses arm64-v8a. Google says the app supports 16KB, as you can see. So does Profile or Debuge APK in Android Studio. Are you maybe using an old version of the plugin (tensorflow_lite_flutter: ^3.0.0)?

Den fre 26 sep. 2025 kl 08:55 skrev rickgrotavi @.***>:

rickgrotavi left a comment (tensorflow/flutter-tflite#287) https://github.com/tensorflow/flutter-tflite/issues/287#issuecomment-3337037418

You can make it work if you skip the x86_64 libraries while keeping the ARM versions. Very few phones use them. Add this to build.gradle.kts in the android section:

    jniLibs {
        excludes.addAll(listOf(
            "**/x86_64/**",
            "**/x86/**",
            "lib/x86_64/**",
            "lib/x86/**"
        ))
        // Keep ARM versions of TensorFlow Lite
        pickFirsts.addAll(listOf(
            "**/arm64-v8a/libtensorflowlite_jni.so",
            "**/armeabi-v7a/libtensorflowlite_jni.so",
            "**/arm64-v8a/libtensorflowlite_gpu_jni.so",
            "**/armeabi-v7a/libtensorflowlite_gpu_jni.so"
        ))
    }
}

and this to the defaultConfig section:

        noCompress.add(".tflite")
        noCompress.add(".lite")
    }
    // Only specify ndk filters, no splits
    ndk {
        abiFilters.clear()
        abiFilters.add("armeabi-v7a")
        abiFilters.add("arm64-v8a")
        // Explicitly exclude x86 architectures
    }

This is my buildTypes

    release {
        signingConfig = signingConfigs.getByName("release")
        isMinifyEnabled = true                    // Re-enable minification
        isShrinkResources = true                  // Re-enable resource shrinking
        proguardFiles(
            getDefaultProguardFile("proguard-android-optimize.txt"),
            "proguard-rules.pro"
        )
    }
}

where progurard-rules.pro contains

-keep class org.tensorflow.lite.gpu.** { ; } -dontwarn org.tensorflow.lite.gpu.*

Additional TensorFlow Lite rules (if needed)

-keep class org.tensorflow.lite.** { ; } -dontwarn org.tensorflow.lite.*

Now when I inspect the aab in Google Play I see

Native platforms arm64-v8a, armeabi-v7a API levels 24+ Target SDK 36 OpenGL ES versions 0.0+ OpenGL textures No textures required Memory page size Supports 16 KB

Hi. It looks like a solution, but arm64-v8a library doesn't support 16KB page sizes either. default.png (view on web) https://github.com/user-attachments/assets/fb7a4b5d-e9f9-44a3-96a6-117400bddb8c

— Reply to this email directly, view it on GitHub https://github.com/tensorflow/flutter-tflite/issues/287#issuecomment-3337037418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEN5JJIRBIXZYTGP6WKZ6633UTPORAVCNFSM6AAAAACD4A2QCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGMZXGAZTONBRHA . You are receiving this because you commented.Message ID: @.***>

BoHellgren avatar Sep 26 '25 07:09 BoHellgren

No, it's not an app issue. The library works fine on every device, but when you upload to the Play Store, they give me a November 1 deadline to fix this. It means the library does not support 16 KB page sizes

nishit-dave avatar Sep 26 '25 09:09 nishit-dave

The only purpose of the gradle stuff described is to get rid of these Google Play notifications: To ensure that your app works correctly on the latest versions of Android, Google Play requires all apps targeting Android 15+ to support 16 KB memory page sizes. From 1 Nov 2025, if your app updates do not support 16 KB memory page sizes, you won't be able to release these updates. For my app, this was caused by the tensorflow_lite_flutter 3.0.0 not supporting 16KB on x86_64. Which should be ok since there are no x86-64 devices with 16kb page size. But Google Play is not intelligent enough to figure out that.

BoHellgren avatar Sep 26 '25 12:09 BoHellgren

https://github.com/bhanuka96/flutter-tflite/commit/f6e2c80e52f8ccfa3c0ec75cea4d1d8a6af76bba - does this address the issue?

dewball345 avatar Sep 26 '25 17:09 dewball345

Hi everyone,

I've submitted PR #294 to address 16KB page size support ahead of the Google Play deadline on November 1, 2025.

What it delivers:

  • Android Gradle Plugin 8.6.1 (meets Google's requirements)
  • SDK compatibility: Android 15+ (API 36)
  • All 14 example projects tested and working
  • 100% backward compatibility maintained

Testing completed:

  • All examples build successfully
  • APK generation verified
  • Modern Gradle build system implemented

Current status: PR #294 prepares the infrastructure for 16KB support. TensorFlow Lite libraries still need updates from Google's team; this PR provides the foundation to adopt 16KB libraries as soon as they become available.

Notes:

  • @BoHellgren's x86 exclusion workaround is useful for immediate needs, but PR #294 provides a comprehensive solution.
  • @dewball345: this PR directly addresses the infrastructure requirements for 16KB support.

See PR #294 for technical details.

bhanuka96 avatar Sep 27 '25 09:09 bhanuka96

I’m forking from PR #294 to complete the 16KB page size support. Google has recompiled TensorFlow Lite with 16KB alignment and moved the artifacts from org.tensorflow to com.google.ai.edge.litert.

I’ve updated the dependencies accordingly:

// Old

def tflite_version = "2.12.0"

implementation("org.tensorflow:tensorflow-lite:${tflite_version}")
implementation("org.tensorflow:tensorflow-lite-gpu:${tflite_version}")

// New

def tflite_version = "1.4.0"

implementation("com.google.ai.edge.litert:litert:${tflite_version}")
implementation("com.google.ai.edge.litert:litert-gpu-api:${tflite_version}")

These LiteRT libraries are officially aligned for 16KB page size and fully compatible with existing TensorFlow Lite APIs, so this should resolve the remaining alignment warnings and meet the Google Play requirement for November 2025.

You can test it directly by updating your pubspec.yaml:

  tflite_flutter:
    git:
      url: https://github.com/nguyenvantuyen98/flutter-tflite
      ref: main

I have created a PR — please check it @bhanuka96 🙏

nguyenvantuyen98 avatar Oct 09 '25 03:10 nguyenvantuyen98

@nguyenvantuyen98 your fork compiled fine except X86_64 architecture. For Google Play we can build app without X86_64 temporarily with edited build.gradle config. Add after kotlinOptions

packaging {
        jniLibs {
            excludes.add("**/x86_64/**")
            excludes.add("**/x86/**")
            excludes.add("lib/x86_64/**")
            excludes.add("lib/x86/**")
        }
    }

LegionLH avatar Oct 15 '25 15:10 LegionLH

This has been solved, please update the plugin.

bhanuka96 avatar Oct 28 '25 06:10 bhanuka96

@bhanuka96 Hi, I have updated tflite_flutter dependency to 0.12.0 in my project... I tried uploading an appbundle in Play Store to check if the 16KB page size issue is fixed... But in bundle explorer, i still find this issue...

libraries that do not support 16 kb: base/lib/arm64-v8a/libtensorflowlite_gpu_jni.so base/lib/arm64-v8a/libtensorflowlite_jni.so base/lib/x86_64/libtensorflowlite_c.so base/lib/x86_64/libtensorflowlite_gpu_jni.so base/lib/x86_64/libtensorflowlite_jni.so

Am i missing something? is there anything I need to upgrade or remove in my project??

NOTtheKRish avatar Oct 28 '25 06:10 NOTtheKRish

@NOTtheKRish Oh, thanks for reporting this! Let me check and get back to you.

bhanuka96 avatar Oct 28 '25 06:10 bhanuka96

in a new flutter project i just added this dependency v0.12.0 and ran it on an emulator with system image being pre-release 16kb page size and api 36 and when the project launches its showing this app is not 16kb compatable. @bhanuka96

VarunMistry88 avatar Oct 28 '25 13:10 VarunMistry88

@NOTtheKRish @VarunMistry88 Please update the dependency to tflite_flutter: 0.12.1 and try again.

bhanuka96 avatar Oct 28 '25 17:10 bhanuka96

@NOTtheKRish @VarunMistry88 Please update the dependency to tflite_flutter: 0.12.1 and try again.

Not working, I have only just added 0.12.1 update to my pubspec, sent it out to Google and it still;

Libraries that do not support 16 KB: base/lib/arm64-v8a/libsqlite3.so base/lib/x86_64/libsqlite3.so

peazz avatar Oct 29 '25 22:10 peazz

@NOTtheKRish @VarunMistry88 Please update the dependency to tflite_flutter: 0.12.1 and try again.

I've updated to latest version, also removed the jniLabs folder from my project and the appbundle is now supporting 16KB page size (verified with Bundle Explorer in Play Console)

NOTtheKRish avatar Oct 30 '25 02:10 NOTtheKRish

@NOTtheKRish @VarunMistry88 Please update the dependency to tflite_flutter: 0.12.1 and try again.

I've updated to latest version, also removed the jniLabs folder from my project and the appbundle is now supporting 16KB page size (verified with Bundle Explorer in Play Console)

I don't have any jniLibs folder and I am on the latest version and bundle explorer is still telling me 16kb is not supported

peazz avatar Oct 30 '25 02:10 peazz