Fix stub resources load on Android 5

This commit is contained in:
canyie 2023-01-11 15:42:23 +08:00 committed by John Wu
parent 636223b289
commit babdfe80cb

View File

@ -35,6 +35,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
import java.util.zip.ZipFile;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.CipherInputStream; import javax.crypto.CipherInputStream;
@ -187,6 +188,16 @@ public class DownloadActivity extends Activity {
} }
} else { } else {
File dir = new File(getCodeCacheDir(), "res"); File dir = new File(getCodeCacheDir(), "res");
dir.mkdirs();
// addAssetPath requires a directory containing AndroidManifest.xml on Android 5
try (var stubApk = new ZipFile(getPackageCodePath());
var manifest = new FileOutputStream(new File(dir, "AndroidManifest.xml"))) {
var stubManifest = stubApk.getInputStream(
stubApk.getEntry("AndroidManifest.xml"));
APKInstall.transfer(stubManifest, manifest);
}
decryptResources(new FileOutputStream(new File(dir, "resources.arsc"))); decryptResources(new FileOutputStream(new File(dir, "resources.arsc")));
StubApk.addAssetPath(getResources(), dir.getPath()); StubApk.addAssetPath(getResources(), dir.getPath());
} }