Comments (1)
原因:异步复制,但在主线程关闭了文件。问题语句:zip.close();
修改:
/**
* copy so lib to specify directory(/data/data/host_pack_name/pluginlib)
*
* @param dexPath
* plugin path
* @param cpuName
* cpuName CPU_X86,CPU_MIPS,CPU_ARMEABI
*/
public void copyPluginSoLib(Context context, String dexPath, String nativeLibDir) {
String cpuName = getCpuName();
String cpuArchitect = getCpuArch(cpuName);
sNativeLibDir = nativeLibDir;
Log.d(TAG, "cpuArchitect: " + cpuArchitect);
long start = System.currentTimeMillis();
try {
ZipFile zipFile = new ZipFile(dexPath);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry zipEntry = (ZipEntry) entries.nextElement();
if (zipEntry.isDirectory()) {
continue;
}
String zipEntryName = zipEntry.getName();
if (zipEntryName.endsWith(".so") && zipEntryName.contains(cpuArchitect)) {
final long lastModify = zipEntry.getTime();
if (lastModify == DLConfigs.getSoLastModifiedTime(context, zipEntryName)) {
// exist and no change
Log.d(TAG, "skip copying, the so lib is exist and not change: " + zipEntryName);
continue;
}
mSoExecutor.execute(new CopySoTask(context, zipFile, zipEntry, lastModify));
}
}
} catch (IOException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
Log.d(TAG, "### copy so time : " + (end - start) + " ms");
}
/**
* @author mrsimple
*/
private class CopySoTask implements Runnable {
private String mSoFileName;
private ZipFile mZipFile;
private ZipEntry mZipEntry;
private Context mContext;
private long mLastModityTime;
CopySoTask(Context context, ZipFile zipFile, ZipEntry zipEntry, long lastModify) {
mZipFile = zipFile;
mContext = context;
mZipEntry = zipEntry;
mSoFileName = parseSoFileName(zipEntry.getName());
mLastModityTime = lastModify;
}
private final String parseSoFileName(String zipEntryName) {
return zipEntryName.substring(zipEntryName.lastIndexOf("/") + 1);
}
private void writeSoFile2LibDir() {
InputStream is = null;
FileOutputStream fos = null;
try {
is = mZipFile.getInputStream(mZipEntry);
fos = new FileOutputStream(new File(sNativeLibDir, mSoFileName));
} catch (IOException e) {
e.printStackTrace();
}
copy(is, fos);
try {
mZipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 输入输出流拷贝
*
* @param is
* @param os
*/
public void copy(InputStream is, OutputStream os) {
if (is == null || os == null)
return;
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(os);
byte[] buf = null;
try {
buf = new byte[getAvailableSize(bis)];
} catch (IOException e) {
e.printStackTrace();
}
int i = 0;
try {
while ((i = bis.read(buf)) != -1) {
bos.write(buf, 0, i);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
bos.flush();
bos.close();
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private int getAvailableSize(InputStream is) throws IOException {
if (is == null)
return 0;
int available = is.available();
return available <= 0 ? 1024 : available;
}
@Override
public void run() {
writeSoFile2LibDir();
DLConfigs.setSoLastModifiedTime(mContext, mZipEntry.getName(), mLastModityTime);
Log.d(TAG, "copy so lib success: " + mZipEntry.getName());
}
}
from dynamic-load-apk.
Related Issues (20)
- main-plugin-a无法启动 HOT 1
- android插件化交流群 25475643 HOT 3
- DLProxyService奇怪空指针 HOT 1
- main-plugin-b运行出错 HOT 2
- java.lang.reflect.InvocationTargetException
- 编译错误,使用jdk1.8依然报这个错
- 加载插件成功,但是插件中的布局文件不显示
- Cannot call preDexLibrary() before setTargetInfo() is called
- R.drawable.xxx HOT 2
- 插件apk需要怎样配置? HOT 2
- 插件apk中含有tablayout,无法加载 HOT 1
- 新人请问下这个库还在维护吗?
- 插件混淆后就无法正常加载了,为什么? HOT 1
- 模式3的 宿主在vivo x7手机上居然会报毒,被人举报的?
- 如何处理插件中的浮窗尼?资源问题如何解决?
- 插件的服务中,xml中资源找不到 HOT 1
- 在插件里使用fragment的问题
- 不支持theme
- Attempt to invoke interface method 'void com.ryg.dynamicload.DLPlugin.onWindowAttributesChanged(android.view.WindowManager$LayoutParams)' on a null object reference HOT 1
- Berhadbitsafer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynamic-load-apk.