Skip to content

Commit e51bfcb

Browse files
committed
修复5.x、64位系统so安装失败的问题
1 parent 9b05cf1 commit e51bfcb

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

PluginCore/src/com/plugin/core/PluginLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public static synchronized int installPlugin(String srcPluginFile) {
191191
// 第3步,检查插件是否已经存在,若存在删除旧的
192192
PluginDescriptor oldPluginDescriptor = getPluginDescriptorByPluginId(pluginDescriptor.getPackageName());
193193
if (oldPluginDescriptor != null) {
194-
LogUtil.e("已安装过,先删除旧版本", srcPluginFile);
194+
LogUtil.e("已安装过,先删除旧版本", pluginDescriptor.getInstalledPath());
195195
remove(pluginDescriptor.getPackageName());
196196
}
197197

@@ -220,13 +220,14 @@ public static synchronized int installPlugin(String srcPluginFile) {
220220
pluginDescriptor.setInstalledPath(destPluginFile);
221221
boolean isInstallSuccess = pluginManager.addOrReplace(pluginDescriptor);
222222

223+
new File(srcPluginFile).delete();
224+
223225
if (!isInstallSuccess) {
224-
new File(srcPluginFile).delete();
225226
LogUtil.d("安装插件失败", srcPluginFile);
226227
return INSTALL_FAIL;
227228
} else {
228229
changeListener.onPluginInstalled(pluginDescriptor.getPackageName(), pluginDescriptor.getVersion());
229-
LogUtil.d("安装插件成功", srcPluginFile);
230+
LogUtil.d("安装插件成功", destPluginFile);
230231
return SUCCESS;
231232
}
232233
}

PluginCore/src/com/plugin/util/FileUtil.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,43 @@ public static boolean copySo(File sourceDir, String so, String dest) {
7979

8080
try {
8181

82-
String name = "lib" + File.separator + Build.CPU_ABI + File.separator + so;
83-
File sourceFile = new File(sourceDir, name);
82+
boolean isSuccess = false;
83+
84+
if (Build.VERSION.SDK_INT >= 21) {
85+
String[] abis = Build.SUPPORTED_ABIS;
86+
if (abis != null) {
87+
for (String abi: abis) {
88+
LogUtil.d(abi);
89+
String name = "lib" + File.separator + abi + File.separator + so;
90+
File sourceFile = new File(sourceDir, name);
91+
if (sourceFile.exists()) {
92+
isSuccess = copyFile(sourceFile.getAbsolutePath(), dest + File.separator + so);
93+
break;
94+
}
95+
}
96+
}
97+
} else {
98+
LogUtil.d(Build.CPU_ABI, Build.CPU_ABI2);
8499

85-
if (!sourceFile.exists() && Build.CPU_ABI2 != null) {
86-
name = "lib" + File.separator + Build.CPU_ABI2 + File.separator + so;
87-
sourceFile = new File(sourceDir, name);
100+
String name = "lib" + File.separator + Build.CPU_ABI + File.separator + so;
101+
File sourceFile = new File(sourceDir, name);
88102

89-
if (!sourceFile.exists()) {
90-
name = "lib" + File.separator + "armeabi" + File.separator + so;
103+
if (!sourceFile.exists() && Build.CPU_ABI2 != null) {
104+
name = "lib" + File.separator + Build.CPU_ABI2 + File.separator + so;
91105
sourceFile = new File(sourceDir, name);
92-
}
93-
}
94106

95-
if (sourceFile.exists()) {
96-
copyFile(sourceFile.getAbsolutePath(), dest + File.separator + so);
97-
} else {
98-
LogUtil.d(Build.CPU_ABI, Build.CPU_ABI2);
99-
if (Build.VERSION.SDK_INT >= 21) {
100-
String[] abis = Build.SUPPORTED_ABIS;
101-
if (abis != null) {
102-
for (String abi:
103-
abis) {
104-
LogUtil.d(abi);
105-
}
107+
if (!sourceFile.exists()) {
108+
name = "lib" + File.separator + "armeabi" + File.separator + so;
109+
sourceFile = new File(sourceDir, name);
106110
}
107111
}
108-
Toast.makeText(PluginLoader.getApplicatoin(), "安装" + so + "失败:NO_MATCHING_ABIS", Toast.LENGTH_LONG).show();
112+
if (sourceFile.exists()) {
113+
isSuccess = copyFile(sourceFile.getAbsolutePath(), dest + File.separator + so);
114+
}
115+
}
116+
117+
if (!isSuccess) {
118+
Toast.makeText(PluginLoader.getApplicatoin(), "安装" + so + "失败: NO_MATCHING_ABIS", Toast.LENGTH_LONG).show();
109119
}
110120
} catch(Exception e) {
111121
e.printStackTrace();
-2 Bytes
Binary file not shown.

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ buildscript {
55
}
66
dependencies {
77
classpath 'com.android.tools.build:gradle:1.3.0'
8+
//编译时注解
9+
//classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2', http://blog.csdn.net/zjbpku/article/details/22976291
810
}
911
}
1012

0 commit comments

Comments
 (0)