ここで説明されているように、ApplicationWrapepr アプローチを使用して、アプリケーションで multidex を使用したいと思いますhttps://plus.google.com/104023661970539138053/posts/YTMf8ADTcFg
--minimal-main-dex オプションを次のような保持ファイルとともに使用しました。
android/support/multidex/ZipUtil.class
android/support/multidex/ZipUtil$CentralDirectory.class
android/support/multidex/MultiDex$V14.class
android/support/multidex/MultiDexExtractor$1.class
android/support/multidex/MultiDexExtractor.class
com/<mypackage>/common/MyApplication.class
com/<mypackage>/common/MyApplicationWrapper.class
com/<mypackage>/common/ui/DashboardActivity.class
android/support/multidex/MultiDexApplication.class
android/support/multidex/MultiDex.class
android/support/multidex/MultiDex$V19.class
android/support/multidex/MultiDex$V4.class
これにより、メインのdexファイルにリストされたクラスが表示されますが、これは問題ありません。次のコードを使用してdexfile内のすべてのクラスをリストするライブラリを使用しますが、新しいDexFileは「classes.dex」のみをチェックするため、メインの「clesses.dex」のエントリを取得し、他のすべてのロードされたdexファイルのエントリは取得しません。 :
private static List<String> getPaths(final String[] sourcePaths) {
List<String> result = new ArrayList<String>();
for (String s : sourcePaths) {
try {
DexFile dexfile = new DexFile(s);
Enumeration<String> entries = dexfile.entries();
while (entries.hasMoreElements()) {
result.add(entries.nextElement());
}
} catch (IOException ioe) {
Log.w(TAG, "cannot open file=" + s + ";Exception=" + ioe.getMessage());
}
}
return result;
}
今のところ単一のパスは次のように決定されます。
application.getApplicationContext().getApplicationInfo().sourceDir;
/data/../myapplicationname.apk のような結果になります
リストされたdexファイルのすべてのクラスを取得する別の可能性はありますか? または、現在 ClassLoaders にあるすべてのクラスですか? ライブラリはプロジェクトに不可欠であり、このアプローチを使用して、後でリフレクションを介してコンポーネントの実装を見つけます。
EDIT1 : classes2.dex ファイルが /data/data/com./code_cache/secondary-dexes/com.-1.apk.classes2.dex の下に配置されていることがわかった場合
ただし、このパスで new DexFile() を使用すると、IOEsxception がスローされ、「dexfile を開けません」というメッセージが表示されます。