Skip to content

AndroidClassLoadingStrategy "load" method let dex file not be writen after jar deleted #1722

Closed
@anonyein

Description

@anonyein
public Map<TypeDescription, Class<?>> load(@MaybeNull ClassLoader classLoader, Map<TypeDescription, byte[]> types) {
        DexProcessor.Conversion conversion = dexProcessor.create();
        for (Map.Entry<TypeDescription, byte[]> entry : types.entrySet()) {
            conversion.register(entry.getKey().getName(), entry.getValue());
        }
        File jar = new File(privateDirectory, randomString.nextString() + JAR_FILE_EXTENSION);
        try {
            if (!jar.createNewFile()) {
                throw new IllegalStateException("Cannot create " + jar);
            }
            JarOutputStream outputStream = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jar)));
            try {
                outputStream.putNextEntry(new JarEntry(DEX_CLASS_FILE));
                conversion.drainTo(outputStream);
                outputStream.closeEntry();
            } finally {
                outputStream.close();
            }
            FILE_PROCESSOR.accept(jar);
            return doLoad(classLoader, types.keySet(), jar);
        } catch (IOException exception) {
            throw new IllegalStateException("Cannot write to zip file " + jar, exception);
        } finally {
            if (!jar.delete()) {
                Logger.getLogger("net.bytebuddy").warning("Could not delete " + jar);
            }
        }
    }

jar.delete() and the local odex/vdex of doLoad(classLoader, types.keySet(), jar) have not be finish writen.
also jar and other files below
app_libs.zip
the new class cannot be created by getConstructor(String.class).newInstance("aaa")

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions