@@ -2024,13 +2024,27 @@ inline plan plan_for(options opt = {}) {
20242024 { std::error_code ec; fs::remove_all (work, ec); }
20252025 std::vector<std::string> libInputs;
20262026 // A library reaches `lib/<abi>/` stripped, as an action of its own, or
2027- // copied as it is when the debug information is kept.
2027+ // copied as it is when the debug information is kept. A file that is not
2028+ // an ELF object -- an archive can carry anything under `jni/` -- is copied
2029+ // as it is with a warning, as the Android Gradle plugin packs a library it
2030+ // cannot strip.
2031+ const auto is_elf = [](const std::string& path) {
2032+ std::ifstream in (path, std::ios::binary);
2033+ char magic[4 ] = {};
2034+ return in.read (magic, 4 ) && magic[0 ] == 0x7f && magic[1 ] == ' E' && magic[2 ] == ' L' && magic[3 ] == ' F' ;
2035+ };
20282036 const auto place_library = [&](const std::string& so, const std::string& abi) {
20292037 const fs::path dst = work / " lib" / abi / fs::path (so).filename ();
20302038 if (llvmStrip.empty ()) {
20312039 collect_tree (so, dst, libInputs);
20322040 return ;
20332041 }
2042+ if (!is_elf (so)) {
2043+ mcpp::warning (std::format (
2044+ " mcpp.dist.apk: {} is not an ELF object, so it is packed without being stripped." , so).c_str ());
2045+ collect_tree (so, dst, libInputs);
2046+ return ;
2047+ }
20342048 std::error_code ec;
20352049 fs::create_directories (dst.parent_path (), ec);
20362050 step strip;
0 commit comments