androidflutterdartmobile16kb-page-size

Android 16 KB page size support in a Flutter app


I have a Flutter application where very less code written in Android (push notifications and dynamic links). I am following an Android page and am using Flutter version 3.29.2.

I created an emulator with 16 KB page size support and tried to check the APK file against a script provided by Google.

When I run the script, get the following message:

>   You can install the latest build-tools by running the below command
> and updating your $PATH:
>
>     sdkmanager "build-tools;35.0.0-rc3"
>
> === ELF alignment ===
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libsigner.so:
> \e[32mALIGNED\e[0m (2**14)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libflutter.so:
> \e[32mALIGNED\e[0m (2**16)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libapp.so:
> \e[32mALIGNED\e[0m (2**16)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libmodpng.so:
> \e[31mUNALIGNED\e[0m (2**12)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libmodft2.so:
> \e[31mUNALIGNED\e[0m (2**12)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libc++_shared.so:
> \e[31mUNALIGNED\e[0m (2**12)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libmodpdfium.so:
> \e[31mUNALIGNED\e[0m (2**12)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libdatastore_shared_counter.so:
> \e[32mALIGNED\e[0m (2**14)
> -e /var/folders/dz/250bg7ws2jd88wngwmnp7ch80000gn/T/app-p-release_out_XXXXX.XkyJgo1NUC/lib/arm64-v8a/libjniPdfium.so:
> \e[31mUNALIGNED\e[0m (2**12)

Below is a list of my YAML file dependencies:

dependencies:
  adjust_sdk: ^5.4.2
  app_settings: ^6.1.1
  app_tracking_transparency: ^2.0.6+1
  collection: ^1.19.1
  connectivity_plus: ^6.1.5
  crypto: ^3.0.6
  encrypt: ^5.0.3
  dartz: ^0.10.1
  dio: ^5.2.1+1
  equatable: ^2.0.5
  firebase_analytics: ^12.0.0
  firebase_core: ^4.0.0
  firebase_crashlytics: ^5.0.0
  firebase_messaging: ^16.0.0
  firebase_remote_config: ^6.0.0
  flutter:
    sdk: flutter
  flutter_aepassurance: ^5.0.0
  flutter_aepcore: ^5.0.0
  flutter_aepedge: ^5.0.0
  flutter_aepedgeidentity: ^5.0.0
  flutter_appsize_generator:
    git: https://github.com/my_name/appsize_generator
  flutter_bloc: ^9.1.0
  flutter_cached_pdfview: ^0.4.3
  flutter_downloader: ^1.12.0
  flutter_html: ^3.0.0-beta.2
  flutter_inappwebview: ^6.1.5
  flutter_pdfview: ^1.4.1+1
  flutter_secure_storage: ^9.2.4
  flutter_svg: ^2.2.0
  freezed_annotation: ^3.1.0
  get_it: ^8.0.2
  go_router: ^16.2.0
  hive_flutter: ^1.1.0
  intl: ^0.19.0
  jwt_decoder: ^2.0.1
  logging: ^1.3.0
  lottie: ^3.3.1
  onetrust_publishers_native_cmp: 202507.1.1
  package_info_plus: ^8.3.1
  path_provider: ^2.0.11
  pretty_dio_logger: ^1.1.1
  share_plus: ^11.1.0
  shared_preferences: ^2.0.15
  url_launcher: ^6.1.5
  youtube_player_flutter: ^9.1.2
  custom_localization:
    path: ./packages/custom_localization
  open_file: ^3.5.10
  flutter_file_dialog: ^3.0.2
  dropdown_search: ^6.0.1

dev_dependencies:
  bloc_test: ^10.0.0
  build_runner: ^2.1.11
  flutter_launcher_icons: ^0.14.1
  flutter_lints: ^5.0.0
  flutter_test:
    sdk: flutter
  freezed: ^3.0.0-0.0.dev
  hive_generator: ^2.0.0
  mockito: ^5.3.1

flutter_appsize_generator:
  raster_size: 4
  max_size: 120

flutter:
  uses-material-design: true

How can I identify which package is causing the problem? Also when I run the app, I get the below screen:

Enter image description here

Please guide if any other changes are required in Android settings.


Solution

  • Some .so library files in the command output are 2**12 = 4 KB aligned. So, the message that the ELF alignment check failed.

    Please check this answer for details. I am posting a summary of what you need to do here:

    Steps to support 16 KB page alignment in a Flutter app: (First of all, create a backup of your original project, and try the following steps in a copy of the project. It's always good to have a backup.)

    1. As stated in the official documentation, you need to update the AGP to version 8.5.1 or higher to be able to compile with a 16 KB page size. (Or for some reasons, if you can't upgrade your AGP, then the documentation suggests your app use compressed shared libraries. More about this in the link pointed out by @Ramiro G.M.)

    The documentation says to upgrade NDK version to 28, but the versions 26 and 27 are also compatible. You may leave it to any among 26, 27 or 28. The respective files to edit are: android/settings.gradle and look for the line like id "com.android.application" version "8.7.3" apply false and change to compatible version, and file android/app/build.gradle where you may change the likes of ndkVersion "27.0.12077973".

    1. Your project code, if contains native code, must update to support the 16 KB page size. To check if the shared libraries are aligned to 16 KB or more, and know if any are .so packages are aligned to 4 KB which is not what you want, you can run the command (on Mac or Linux):
    find -type f | grep '\.so$' | xargs -I{} -exec sh -c 'echo  "\n{}"; llvm-objdump-18 -p "{}" | grep "LOAD"'
    

    (The llvm-objdump-18 command may be available in other forms like objdump alias.)

    1. Your project dependencies listed in the pubspec.yaml file, both direct and dev dependencies may need to be updated if they depend on native code.

    If you can identify the individual ones, you may update only those to the appropriate version, or else you should update all the dependency packages in your pubspec.yaml file.

    Also, the transient dependencies should be updated. How: To update the direct and dev dependencies, update the corresponding version number to each packages in the pubspec.yaml file and after that run flutter clean; flutter pub get from the project root which will update the direct and dev dependencies listed in the pubspec.yaml file.

    Now to upgrade the transient dependencies: You can see the table with the command: flutter pub outdated and update the transient dependencies with flutter pub upgrade command (or flutter pub upgrade --major-versions).

    1. After you've updated the dependencies, try to run the project. Additional configuration changes may be asked and displayed as error messages. You should do as suggested. You may update your question if you need help with that.

    After you fix these, check again for the 16 KB alignment of .so packages and also test run in 16 KB compliant emulator or devices.

    Note: To update the dependencies in your pubspec.yaml Visual Studio Code extensions, like Version Lens, can ease the process. Something similar should also exist for Android Studio.

    UPDATE 02:

    I checked the .so files that were not compliant to 16 KB page size, and found that among the packages listed in your pubspec.yaml file, package flutter_pdfview: ^1.4.1+1 was the one that was resulting in these shared libraries. I have also noted that you have the latest version of the package. I also tested with the same latest version, till date, and found the same shared libraries generated that were not 16 KB-compliant. These are:

    libc++_shared.so
    libjniPdfium.so
    libmodft2.so
    libmodpdfium.so
    libmodpng.so
    

    I checked with flutter pub outdated which gave the following output:

    Showing outdated packages.
    [*] indicates versions that are not the latest available.
    
    Package Name              Current  Upgradable  Resolvable  Latest
    
    direct dependencies: all up-to-date.
    
    dev_dependencies:
    flutter_lints             *5.0.0   *5.0.0      6.0.0       6.0.0
    
    transitive dependencies:
    characters                *1.4.0   *1.4.0      *1.4.0      1.4.1
    material_color_utilities  *0.11.1  *0.11.1     *0.11.1     0.13.0
    meta                      *1.16.0  *1.16.0     *1.16.0     1.17.0
    
    transitive dev_dependencies:
    lints                     *5.1.1   *5.1.1      6.0.0       6.0.0
    test_api                  *0.7.6   *0.7.6      *0.7.6      0.7.7
    

    Which is for a simple Flutter project using the flutter_pdfview and path_provider packages, which does not show much of the transient dependencies that we can upgrade to fix the issue. These are mostly normal transient dependencies normally found in simple Flutter projects.

    In conclusion, I don't see much you can do to fix this error of 16 KB page size noncompliance. You should report this to the package maintainer of flutter_pdfview and should he/she fix this, upstream, the only thing the package users would have to do is to upgrade the package to the one that fixes the issue. That is all we can do for now. I hope it gets fixed earlier that Nov. 2025 before the deadline.

    UPDATE 03:

    I see you have already filed an issue in the flutter_pdfview's GitHub page. And for now they have suggested a beta version offering the fix:

    Link to flutter_pdfview beta version offering 16 KB page size fix for Android.