Skip to content

Commit 67c0170

Browse files
ankithbti52509meta-codesync[bot]
authored andcommitted
Fixed for library loader in SoLoader sdk. (#148)
Summary: Adding all supported abi path to load library from apk lib/[abi]/. Currently its adding path only for first supported abi. Due to this, few apps Lego Builder and Lingo Kids apps which uses library from arm64-v8a, but Soloader tries to load from first supported abi x86_64. Pull Request resolved: #148 Test Plan: ~~Imported from GitHub, without a `Test Plan:` line.~~ - Add new test case `testPreferredAbiOrder()` to verify ABI ordering is preserved `buck2 test fbsource//fbandroid/javatests/com/facebook/soloader:soloader -- SoLoaderDirectApkTest` Reviewed By: adicatana, michalgr Differential Revision: D94558731 Pulled By: danjin250 fbshipit-source-id: 9c024193e0157b69942ece2b6d90716e3415449d
1 parent 7cd9cc7 commit 67c0170

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

java/com/facebook/soloader/DirectApkSoSource.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Enumeration;
2626
import java.util.HashMap;
2727
import java.util.HashSet;
28+
import java.util.LinkedHashSet;
2829
import java.util.Map;
2930
import java.util.Set;
3031
import java.util.zip.ZipEntry;
@@ -117,27 +118,27 @@ public String getLibraryPath(String soName) throws IOException {
117118
}
118119

119120
/*package*/ static Set<String> getDirectApkLdPaths(ApplicationInfo aInfo) {
120-
Set<String> directApkPathSet = new HashSet<>();
121+
Set<String> directApkPathSet = new LinkedHashSet<>();
121122

122123
final String apkPath = aInfo.sourceDir;
123-
final @Nullable String fallbackApkLdPath = getFallbackApkLdPath(apkPath);
124-
if (fallbackApkLdPath != null) {
125-
directApkPathSet.add(fallbackApkLdPath);
124+
final @Nullable Set<String> fallbackApkLdPath = getFallbackApkLdPath(apkPath);
125+
if (fallbackApkLdPath != null && !fallbackApkLdPath.isEmpty()) {
126+
directApkPathSet.addAll(fallbackApkLdPath);
126127
}
127128

128129
if (aInfo.splitSourceDirs != null) {
129130
for (String splitApkPath : aInfo.splitSourceDirs) {
130-
final @Nullable String fallbackSplitApkLdPath = getFallbackApkLdPath(splitApkPath);
131-
if (fallbackSplitApkLdPath != null) {
132-
directApkPathSet.add(fallbackSplitApkLdPath);
131+
final @Nullable Set<String> fallbackSplitApkLdPath = getFallbackApkLdPath(splitApkPath);
132+
if (fallbackSplitApkLdPath != null && !fallbackSplitApkLdPath.isEmpty()) {
133+
directApkPathSet.addAll(fallbackSplitApkLdPath);
133134
}
134135
}
135136
}
136137

137138
return directApkPathSet;
138139
}
139140

140-
private static @Nullable String getFallbackApkLdPath(String apkPath) {
141+
private static @Nullable Set<String> getFallbackApkLdPath(String apkPath) {
141142
final String[] supportedAbis = SysUtil.getSupportedAbis();
142143
if (apkPath == null || apkPath.isEmpty()) {
143144
LogUtil.w(
@@ -152,7 +153,11 @@ public String getLibraryPath(String soName) throws IOException {
152153
+ ((supportedAbis == null) ? "null" : "empty"));
153154
return null;
154155
}
155-
return apkPath + "!/lib/" + supportedAbis[0];
156+
Set<String> apkLdPaths = new LinkedHashSet<>();
157+
for (String supportedAbi : supportedAbis) {
158+
apkLdPaths.add(apkPath + "!/lib/" + supportedAbi);
159+
}
160+
return apkLdPaths;
156161
}
157162

158163
private void loadDependencies(

0 commit comments

Comments
 (0)