Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test-app/app/src/main/java/com/tns/RuntimeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ public static Runtime initRuntime(Context context) {
dexDir.mkdirs();
}
if (!dexDir.exists() || !dexDir.canWrite()) {
if (logger.isEnabled()) {
logger.write("Unable to use dex dir: " + dexDir.getAbsolutePath() + ", falling back to files/secondary-dexes");
}
File primary = dexDir;
dexDir = new File(appDir, "secondary-dexes");
if (!dexDir.exists()) {
dexDir.mkdirs();
}
Log.w(logTag, "Unable to use primary dex dir '" + primary.getAbsolutePath()
+ "' (exists=" + primary.exists() + " canWrite=" + primary.canWrite()
+ "); falling back to '" + dexDir.getAbsolutePath()
+ "' (exists=" + dexDir.exists() + " canWrite=" + dexDir.canWrite() + ")");
}
String dexThumb = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,46 @@ private String saveProxy(String proxyName, byte[] proxyBytes) throws IOException
if (parentDir != null && !parentDir.exists()) {
parentDir.mkdirs();
}
file.createNewFile();
FileOutputStream stream = new FileOutputStream(file);
stream.write(proxyBytes);
stream.flush();
stream.close();
try {
file.createNewFile();
FileOutputStream stream = new FileOutputStream(file);
try {
stream.write(proxyBytes);
stream.flush();
} finally {
stream.close();
}
} catch (IOException e) {
throw new IOException("Failed to save proxy dex '" + file.getAbsolutePath()
+ "' (" + proxyBytes.length + " bytes): " + e.getMessage()
+ " | " + describeDexDirState(file, parentDir), e);
}

return file.getAbsolutePath();
}

private static String describeDexDirState(File file, File parentDir) {
StringBuilder sb = new StringBuilder();
sb.append("file.exists=").append(file.exists());
if (parentDir != null) {
sb.append(" parent=").append(parentDir.getAbsolutePath());
sb.append(" parent.exists=").append(parentDir.exists());
sb.append(" parent.isDir=").append(parentDir.isDirectory());
sb.append(" parent.canWrite=").append(parentDir.canWrite());
File grand = parentDir.getParentFile();
if (grand != null) {
sb.append(" grand=").append(grand.getAbsolutePath());
sb.append(" grand.exists=").append(grand.exists());
sb.append(" grand.canWrite=").append(grand.canWrite());
}
try {
sb.append(" parent.freeSpace=").append(parentDir.getFreeSpace());
sb.append(" parent.usableSpace=").append(parentDir.getUsableSpace());
} catch (Throwable ignored) {
}
} else {
sb.append(" parent=null");
}
return sb.toString();
}
}
25 changes: 21 additions & 4 deletions test-app/runtime/src/main/java/com/tns/DexFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class DexFactory {
odexDir.mkdir();
}

if (!dexDir.exists() || !dexDir.canWrite()) {
Log.w("JS", "DexFactory: dexDir unusable at init path=" + dexDir.getAbsolutePath()
+ " exists=" + dexDir.exists() + " canWrite=" + dexDir.canWrite());
}

this.updateDexThumbAndPurgeCache();
this.proxyGenerator.setProxyThumb(this.dexThumb);
this.classStorageService = classStorageService;
Expand Down Expand Up @@ -123,10 +128,22 @@ public Class<?> resolveClass(String baseClassName, String name, String className
}

String dexFilePath;
if (isInterface) {
dexFilePath = this.generateDex(name, classToProxy, methodOverrides, implementedInterfaces, isInterface);
} else {
dexFilePath = this.generateDex(desiredDexClassName, classToProxy, methodOverrides, implementedInterfaces, isInterface);
try {
if (isInterface) {
dexFilePath = this.generateDex(name, classToProxy, methodOverrides, implementedInterfaces, isInterface);
} else {
dexFilePath = this.generateDex(desiredDexClassName, classToProxy, methodOverrides, implementedInterfaces, isInterface);
}
} catch (IOException e) {
String diag = "DexFactory.generateDex failed class=" + className
+ " baseClass=" + baseClassName
+ " isInterface=" + isInterface
+ " dexDir=" + dexDir.getAbsolutePath()
+ " dexDir.exists=" + dexDir.exists()
+ " dexDir.canWrite=" + dexDir.canWrite()
+ " dexThumb=" + dexThumb;
Log.e("JS", diag + " | " + e.getMessage());
throw new IOException(diag + " | " + e.getMessage(), e);
}
dexFile = new File(dexFilePath);
long stopGenTime = System.nanoTime();
Expand Down
Loading