Skip to content

Commit 218459f

Browse files
committed
BundleToolNoAbiSplitTests should work now
1 parent 3d89608 commit 218459f

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/native/clr/host/host.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ void Host::gather_assemblies_and_libraries (jstring_array_wrapper& runtimeApks,
264264

265265
int64_t apk_count = static_cast<int64_t>(runtimeApks.get_length ());
266266
bool got_split_config_abi_apk = false;
267+
std::string_view base_apk{};
267268

268269
for (int64_t i = 0; i < apk_count; i++) {
269270
std::string_view apk_file = runtimeApks [static_cast<size_t>(i)].get_string_view ();
@@ -272,9 +273,11 @@ void Host::gather_assemblies_and_libraries (jstring_array_wrapper& runtimeApks,
272273
bool scan_apk = false;
273274

274275
// With split configs we need to scan only the abi apk, because both the assembly stores and the runtime
275-
// configuration blob are in `lib/{ARCH}`, which in turn lives in the split config APK
276+
// configuration blob **should be** in `lib/{ARCH}`, which in turn lives in the split config APK
276277
if (!got_split_config_abi_apk && apk_file.ends_with (Constants::split_config_abi_apk_name.data ())) {
277278
got_split_config_abi_apk = scan_apk = true;
279+
} else if (base_apk.empty () && apk_file.ends_with (Constants::base_apk_name)) {
280+
base_apk = apk_file;
278281
}
279282

280283
if (!scan_apk) {
@@ -284,6 +287,14 @@ void Host::gather_assemblies_and_libraries (jstring_array_wrapper& runtimeApks,
284287

285288
Zip::scan_archive (apk_file, zip_scan_callback);
286289
}
290+
291+
// This apparently can happen now... It seems that sometimes (when and why? No idea) when AAB format is used, bundletool
292+
// won't put the native libraries in a separate split config file, but it will instead put **all** of the ABIs
293+
// in base.apk
294+
if (have_split_apks && !got_split_config_abi_apk) {
295+
abort_unless (!base_apk.empty (), "Split config APKs are used, but no ABI config was found and no base.apk was encountered.");
296+
Zip::scan_archive (base_apk, zip_scan_callback);
297+
}
287298
}
288299

289300
[[gnu::always_inline]]

src/native/clr/include/constants.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ namespace xamarin::android {
112112
static constexpr std::string_view assembly_store_file_name { assembly_store_file_name_array.data () };
113113

114114
static constexpr auto split_config_abi_apk_name = concat_string_views<split_config_abi_apk_name_size> (split_config_prefix, android_abi, split_config_extension);
115+
static constexpr std::string_view base_apk_name = { "/base.apk" };
115116

116117
//
117118
// Indexes must match these of trhe `appDirs` array in src/java-runtime/mono/android/MonoPackageManager.java

src/native/clr/runtime-base/android-system.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ AndroidSystem::setup_apk_directories (unsigned short running_on_cpu, jstring_arr
172172
std::string_view const& abi = android_abi_names [running_on_cpu];
173173
size_t number_of_added_directories = 0uz;
174174

175+
std::string_view base_apk{};
175176
for (size_t i = 0uz; i < runtimeApks.get_length (); ++i) {
176177
jstring_wrapper &e = runtimeApks [i];
177178
std::string_view apk = e.get_string_view ();
@@ -180,12 +181,22 @@ AndroidSystem::setup_apk_directories (unsigned short running_on_cpu, jstring_arr
180181
if (apk.ends_with (Constants::split_config_abi_apk_name.data ())) {
181182
add_apk_libdir (apk, number_of_added_directories, abi);
182183
break;
184+
} else if (base_apk.empty () && apk.ends_with (Constants::base_apk_name)) {
185+
base_apk = apk;
183186
}
184187
} else {
185188
add_apk_libdir (apk, number_of_added_directories, abi);
186189
}
187190
}
188191

192+
// This apparently can happen now... It seems that sometimes (when and why? No idea) when AAB format is used, bundletool
193+
// won't put the native libraries in a separate split config file, but it will instead put **all** of the ABIs
194+
// in base.apk
195+
if (have_split_apks && number_of_added_directories == 0 && !base_apk.empty ()) {
196+
add_apk_libdir (base_apk, number_of_added_directories, abi);
197+
}
198+
199+
log_debug (LOG_DEFAULT, "Number of added dirs: {}", number_of_added_directories);
189200
if (app_lib_directories.size () == number_of_added_directories) [[likely]] {
190201
return;
191202
}

src/native/mono/monodroid/monodroid-glue.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ MonodroidRuntime::gather_bundled_assemblies (jstring_array_wrapper &runtimeApks,
259259
// configuration blob are in `lib/{ARCH}`, which in turn lives in the split config APK
260260
if (!got_split_config_abi_apk && Util::ends_with (apk_file.get_cstr (), SharedConstants::split_config_abi_apk_name)) {
261261
got_split_config_abi_apk = scan_apk = true;
262-
} else if (!application_config.have_assembly_store && !got_base_apk && Util::ends_with (apk_file.get_cstr (), base_apk_name)) {
263-
got_base_apk = scan_apk = true;
262+
} else if (!got_base_apk && Util::ends_with (apk_file.get_cstr (), base_apk_name)) {
263+
scan_apk = got_base_apk = true;
264264
}
265265

266266
if (!scan_apk) {

0 commit comments

Comments
 (0)