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?)
```
This commit is contained in:
lizhuo
2024-10-01 00:56:25 +09:00
committed by GitHub
parent e3828ec940
commit 84f65686d9
2 changed files with 32 additions and 0 deletions

View File

@@ -15,3 +15,8 @@ set_target_properties({{projectName}} PROPERTIES
)
target_compile_definitions({{projectName}} PUBLIC DART_SHARED_LIB)
if(ANDROID)
# Support Android 15 16k page size
target_link_options({{projectName}} PRIVATE "-Wl,-z,max-page-size=16384")
endif()

View File

@@ -3149,6 +3149,33 @@ void main() {
expect(buildGradleContent.contains('namespace = "com.bar.foo.flutter_project"'), true);
});
testUsingContext('Android FFI plugin contains 16kb page support', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[
'create',
'--no-pub',
'-t',
'plugin_ffi',
'--org',
'com.bar.foo',
'--platforms=android',
projectDir.path
]);
final File cmakeLists =
globals.fs.file('${projectDir.path}/src/CMakeLists.txt');
expect(cmakeLists.existsSync(), true);
final String cmakeListsContent = await cmakeLists.readAsString();
const String expected16KbFlags = 'PRIVATE "-Wl,-z,max-page-size=16384")';
expect(cmakeListsContent, contains(expected16KbFlags));
});
testUsingContext('Android Kotlin plugin contains namespace', () async {
Cache.flutterRoot = '../..';