Skip to content

Commit 534a970

Browse files
committedFeb 4, 2016
Fix (64位手机的问题): 适配64位手机:
1、在64位手机上运行:在宿主apk的lib中,如果没有so,则宿主运行在64位进程中。 2、在64位手机上运行:在宿主apk的lib中,如果有so,但没有64位ABI的so,则宿主运行在32位进程中。 3、在32位手机上运行:在宿主apk的lib中,如果有so,但有64位ABI的so,则宿主运行在64位进程中。 所以:在宿主程序运行在64位进程中的时候,默认插件只能加载64位的so;在宿主程序运行在32位进程中的时候,插件只是加载32位的so。 目前,插件so的abi必须与宿主一致,即,宿主64位,插件必须64位;宿主32位,插件必须32位。否则插件是无法加载对应的so的。
1 parent 4950792 commit 534a970

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed
 

‎project/Libraries/DroidPlugin/src/com/morgoo/droidplugin/pm/IPluginManagerImpl.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import android.content.pm.Signature;
4242
import android.net.Uri;
4343
import android.os.Binder;
44-
import android.os.Build;
4544
import android.os.Build.VERSION;
4645
import android.os.Build.VERSION_CODES;
4746
import android.os.RemoteException;
@@ -54,8 +53,10 @@
5453
import com.morgoo.droidplugin.pm.parser.IntentMatcher;
5554
import com.morgoo.droidplugin.pm.parser.PluginPackageParser;
5655
import com.morgoo.helper.Log;
57-
import com.morgoo.helper.compat.PackageManagerCompat;
5856
import com.morgoo.helper.Utils;
57+
import com.morgoo.helper.compat.BuildCompat;
58+
import com.morgoo.helper.compat.PackageManagerCompat;
59+
import com.morgoo.helper.compat.VMRuntimeCompat;
5960

6061
import java.io.File;
6162
import java.io.FileOutputStream;
@@ -1009,9 +1010,9 @@ private void copyNativeLibs(Context context, String apkfile, ApplicationInfo app
10091010
}
10101011

10111012
for (String soName : soList.keySet()) {
1012-
Log.e(TAG, "==========so name=" + soName);
1013+
Log.e(TAG, "try so =" + soName);
10131014
Set<String> soPaths = soList.get(soName);
1014-
String soPath = findSoPath(soPaths);
1015+
String soPath = findSoPath(soPaths, soName);
10151016
if (soPath != null) {
10161017
File file = new File(nativeLibraryDir, soName);
10171018
if (file.exists()) {
@@ -1061,17 +1062,26 @@ private void copyNativeLibs(Context context, String apkfile, ApplicationInfo app
10611062
}
10621063
}
10631064

1064-
private String findSoPath(Set<String> soPaths) {
1065+
1066+
private String findSoPath(Set<String> soPaths, String soName) {
10651067
if (soPaths != null && soPaths.size() > 0) {
1066-
for (String soPath : soPaths) {
1067-
if (!TextUtils.isEmpty(Build.CPU_ABI) && soPath.contains(Build.CPU_ABI)) {
1068-
return soPath;
1068+
if (VMRuntimeCompat.is64Bit()) {
1069+
//在宿主程序运行在64位进程中的时候,插件的so也只拷贝64位,否则会出现不支持的情况。
1070+
for (String soPath : soPaths) {
1071+
String abi = soPath.replaceFirst("lib/", "");
1072+
abi = abi.replace("/" + soName, "");
1073+
if (!TextUtils.isEmpty(abi) && Arrays.binarySearch(BuildCompat.SUPPORTED_64_BIT_ABIS, abi) >= 0) {
1074+
return soPath;
1075+
}
10691076
}
1070-
}
1071-
1072-
for (String soPath : soPaths) {
1073-
if (!TextUtils.isEmpty(Build.CPU_ABI2) && soPath.contains(Build.CPU_ABI2)) {
1074-
return soPath;
1077+
} else {
1078+
//在宿主程序运行在32位进程中的时候,插件的so也只拷贝64位,否则会出现不支持的情况。
1079+
for (String soPath : soPaths) {
1080+
String abi = soPath.replaceFirst("lib/", "");
1081+
abi = abi.replace("/" + soName, "");
1082+
if (!TextUtils.isEmpty(abi) && Arrays.binarySearch(BuildCompat.SUPPORTED_32_BIT_ABIS, abi) >= 0) {
1083+
return soPath;
1084+
}
10751085
}
10761086
}
10771087
}
@@ -1347,12 +1357,12 @@ public void onDestroy() {
13471357
}
13481358

13491359
@Override
1350-
public void onActivtyOnNewIntent(ActivityInfo stubInfo, ActivityInfo targetInfo, Intent intent) throws RemoteException{
1360+
public void onActivtyOnNewIntent(ActivityInfo stubInfo, ActivityInfo targetInfo, Intent intent) throws RemoteException {
13511361
mActivityManagerService.onActivtyOnNewIntent(Binder.getCallingPid(), Binder.getCallingUid(), stubInfo, targetInfo, intent);
13521362
}
13531363

13541364
@Override
1355-
public int getMyPid(){
1365+
public int getMyPid() {
13561366
return android.os.Process.myPid();
13571367
}
13581368

0 commit comments

Comments
 (0)
Please sign in to comment.