Dex动态加载问题

用build-tools的dex打包失败

改用d8即可具体使用方式可参照
https://developer.android.google.cn/studio/command-line/d8

加载时 No such file or directory

private static dalvik.system.DexPathList$Element[] dalvik.system.DexPathList.makeDexElements(java.util.List,java.io.File,java.util.List,java.lang.ClassLoader)

2020-07-20 18:54:58.633 30177-30177/com.dexloadtest E/System: Unable to load dex file: /storage/emulated/0/Android/data/com.dexloadtest/cache/classes3.dex
2020-07-20 18:54:58.641 30177-30177/com.dexloadtest E/System: java.io.IOException: Failed to open dex files from /storage/emulated/0/Android/data/com.dexloadtest/cache/classes3.dex because: Unable to open '/storage/emulated/0/Android/data/com.dexloadtest/cache/classes3.dex' : No such file or directory 

每次加载都会删除掉dex文件,导致no such file

情况分析,Dexclassloader在加载file时,不能直接使用.dex文件,需要是d8或者dex生成的jar包或者apk包,如果直接是dex文件,会失败,然后删除文件,以下是DexClassLoader的解释

/**
     * Creates a {@code DexClassLoader} that finds interpreted and native
     * code.  Interpreted classes are found in a set of DEX files contained
     * in Jar or APK files.
     *
     * <p>The path lists are separated using the character specified by the
     * {@code path.separator} system property, which defaults to {@code :}.
     *
     * @param dexPath the list of jar/apk files containing classes and
     *     resources, delimited by {@code File.pathSeparator}, which
     *     defaults to {@code ":"} on Android
     * @param optimizedDirectory this parameter is deprecated and has no effect since API level 26.
     * @param librarySearchPath the list of directories containing native
     *     libraries, delimited by {@code File.pathSeparator}; may be
     *     {@code null}
     * @param parent the parent class loader
     */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值