Skip to content

Reduce python-for-android initial loading. #681

tito opened this Issue Sep 18, 2012 · 2 comments

2 participants

Kivy member
tito commented Sep 18, 2012

Reducing the loading time is a challenge, and here is my brainstorming so far. The android APK is a zip file. Importing from a zip usually mean that we cannot import dynamic libraries too (.so).

The egg file format resolve that issue: by replacing distutils to setuptools in kivy, we can build a .egg. The native files are extracted on demand from the .egg. To use a .egg, you just need to copy it from the right python directory, or add it in the sys.path. But the .egg is a file too.

  • Is python would be able to load .egg from a .apk, without any decompression?
  • android can load dynamic library directly from the APK. would we be able to do the same? instead of letting the .egg extracting the file outside the egg for dlopen, could we try to use android API instead?
  • both approach don't resolve the data access, but it look like pkg_resources.resource_filename('kivy', 'data/glsl/header.vs') is automaticaly extract the file in the temporary dir, and ready to be used afterwise with open(). is pkg_resources.resource_filename() is sufficient? do we need to patch open()? do we need to make kivy pkg_resources dependant ?

That's all, i'll check all of thoses points and wrote the result here.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Kivy member
tito commented Sep 18, 2012

It seem that aapt doesn't remove file with custom extensions, as .py. So it seem possible that we can package the assets directly, without a .tar + uncompress.

Also, here is the code needed to get the APK location (taken from renpy project):

// Figure out the source path.
String apkFilePath;
ApplicationInfo appInfo;
PackageManager packMgmr = mActivity.getApplication().getPackageManager();

try {
    appInfo = packMgmr.getApplicationInfo(mActivity.getPackageName(), 0);
    apkFilePath = appInfo.sourceDir;
} catch (NameNotFoundException e) {
    apkFilePath = "";
Kivy member
tito commented Sep 18, 2012

@akshayaurora put also a good remarq about another approach: if Android would be able to mount a zip, then it would resolve the resources loading issue. We need to explore and ZipResourceFile.

@dessant dessant modified the milestone: 2.0, 2.0.0 Jan 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.