Skip to content

Commit 84f6568

Browse files
authored
fix: support android 15 16k page size for template plugin_ffi (#155508)
Android 15 support 16k page sizes, it need [enable 16kb elf alignment](https://developer.android.com/guide/practices/page-sizes#compile-r26-lower). the current plugin_ffi template will have below error if run on android 15 16k emulator ``` Failed to load dynamic library 'libffigen_app.so': dlopen failed: empty/missing DT_HASH/DT_GNU_HASH in "/data/app/~~Ixsgxu2mj5fKxP1cXpjV6Q==/com.example.ffigen_app_example-6d_efR__WGu 4dsF4tLIaHw==/lib/arm64/libffigen_app.so" (new hash type from the future?) ```
1 parent e3828ec commit 84f6568

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

packages/flutter_tools/templates/plugin_ffi/src.tmpl/CMakeLists.txt.tmpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ set_target_properties({{projectName}} PROPERTIES
1515
)
1616

1717
target_compile_definitions({{projectName}} PUBLIC DART_SHARED_LIB)
18+
19+
if(ANDROID)
20+
# Support Android 15 16k page size
21+
target_link_options({{projectName}} PRIVATE "-Wl,-z,max-page-size=16384")
22+
endif()

packages/flutter_tools/test/commands.shard/permeable/create_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,33 @@ void main() {
31493149
expect(buildGradleContent.contains('namespace = "com.bar.foo.flutter_project"'), true);
31503150
});
31513151

3152+
testUsingContext('Android FFI plugin contains 16kb page support', () async {
3153+
Cache.flutterRoot = '../..';
3154+
3155+
final CreateCommand command = CreateCommand();
3156+
final CommandRunner<void> runner = createTestCommandRunner(command);
3157+
3158+
await runner.run(<String>[
3159+
'create',
3160+
'--no-pub',
3161+
'-t',
3162+
'plugin_ffi',
3163+
'--org',
3164+
'com.bar.foo',
3165+
'--platforms=android',
3166+
projectDir.path
3167+
]);
3168+
3169+
final File cmakeLists =
3170+
globals.fs.file('${projectDir.path}/src/CMakeLists.txt');
3171+
3172+
expect(cmakeLists.existsSync(), true);
3173+
3174+
final String cmakeListsContent = await cmakeLists.readAsString();
3175+
const String expected16KbFlags = 'PRIVATE "-Wl,-z,max-page-size=16384")';
3176+
expect(cmakeListsContent, contains(expected16KbFlags));
3177+
});
3178+
31523179
testUsingContext('Android Kotlin plugin contains namespace', () async {
31533180
Cache.flutterRoot = '../..';
31543181

0 commit comments

Comments
 (0)