Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Android 10 Developer Changes. #24

Closed
canewsin opened this issue Jan 22, 2020 · 33 comments
Closed

Android 10 Developer Changes. #24

canewsin opened this issue Jan 22, 2020 · 33 comments
Labels

Comments

@canewsin
Copy link

How can we make Android 10 Compatible Binary

Untrusted apps that target Android 10 cannot invoke exec() on files within the app's home directory. This execution of files from the writable app home directory is a W^X violation. Apps should load only the binary code that's embedded within an app's APK file.

Obviously we store the output binaries in home dir of app, because python in bin dir, points to lib folder.

I was currently using termux system for binary compilation they had the same issue, since this is python only bins, I want to migrate build system to this repo. but cannot find solution for it.

related wiki : https://github.com/termux/termux-packages/wiki/Termux-and-Android-10

@canewsin
Copy link
Author

@yan12125
Copy link
Owner

Thank you very much for the info. Most likely the solution will be building libpython.so on PC and load it with dlopen(). However, there are reports that this approach does not work (#18).

@canewsin
Copy link
Author

canewsin commented Jan 22, 2020

Thank you very much for the info. Most likely the solution will be building libpython.so on PC and load it with dlopen(). However, there are reports that this approach does not work (#18).

Can we able to make bin/python and lib/libpython.so as single file ?

@yan12125
Copy link
Owner

I guess you mean making bin/python a standalone executable, so that it can run without loading libpython.so? It's possible (by building python without --enable-shared), but I doubt it will help as you still need to exec() bin/python.

@yan12125
Copy link
Owner

As a side note, iOS has similar exec() restrictions years ago. Efforts on runnuing Python on iOS (https://bugs.python.org/issue23670) may help.

@canewsin
Copy link
Author

Do you have any idea on how can we overcome this ?
References of Issue :

Removed execute permission for app home directory
Untrusted apps that target Android 10 cannot invoke exec() on files within the app's home directory. This execution of files from the writable app home directory is a W^X violation. Apps should load only the binary code that's embedded within an app's APK file.

In addition, apps that target Android 10 cannot in-memory modify executable code from files which have been opened with dlopen(). This includes any shared object (.so) files with text relocations.

@canewsin
Copy link
Author

I'm Curious because your repo obviously doesn't work anymore on android devices when app is targeting android 10, as well as helpful to me.

@yan12125
Copy link
Owner

Do you have any idea on how can we overcome this ?

What to overcome? Building libpython.so, embedding it into APK and load it should still work fine with apps targettong Android 10.

@canewsin
Copy link
Author

canewsin commented Jan 22, 2020

Generally lib-dynload dir contains all native modules can we able to compile them as single so bin file.

@canewsin
Copy link
Author

Thank you very much for the info. Most likely the solution will be building libpython.so on PC and load it with dlopen(). However, there are reports that this approach does not work (#18).

I already compiling them on pc, but their placement is different, lastest update is i compiled python without --enable-shared, but has a doubt that will it contain dynload modules or not !

@yan12125
Copy link
Owner

Generally lib-dynload dir contains all native modules can we able to compile them as single so bin file.

I'm afraid there is no simple way.

@GRRedWings
Copy link

My fork is out of date and not as current as this one, but I embed libPython in the app, and it runs without any problem on Android 10. So embedding it is always an option.

@yan12125
Copy link
Owner

yan12125 commented Feb 1, 2020

I embed libPython in the app, and it runs without any problem on Android 10

Great to hear that! Mind to share an example app for testing? Frankly, I'm not familiar with Java and creating an Android app is somewhat hard to me.

@GRRedWings
Copy link

GRRedWings commented Feb 1, 2020 via email

@yan12125
Copy link
Owner

yan12125 commented Feb 1, 2020

Ah, I was asking for a sample app that works with your fork, not mine :) I hope such an app can me testing this issue and #18.

@GRRedWings
Copy link

GRRedWings commented Feb 1, 2020 via email

@GRRedWings
Copy link

I'm still working on it. I only have an hour or two here and there to work on it so it's slow going.

@yan12125
Copy link
Owner

yan12125 commented Feb 5, 2020

No hurry :)

@canewsin
Copy link
Author

canewsin commented Feb 8, 2020

since python is build as PIE bins there is no problem, and where we put those assuming we load libpython.so while executing python, i now successfully running normal python scripts one thing bothering me is, i was not able to figure how to compile native modules of python like gevent

@GRRedWings
Copy link

GRRedWings commented Feb 8, 2020 via email

@yan12125
Copy link
Owner

yan12125 commented Feb 9, 2020

From termux/termux-app#1072 (comment),

This probably will go away in future, current implementation bans execve() from data but still allows dlopen()ing (System.load in Java) downloaded files

As Python libraries (libpython3.X.so, lib-dynload/*.so) are accessed via dlopen() as demonstrated in @GRRedWings' sample application, Android 10 changes are currently not an issue. If one day dlopen() is also restricted, we can restart this discussion.

@hwangjr
Copy link

hwangjr commented Jul 22, 2021

Anyone have any ideas to execute python download from remote? Now for android 10, the only way is to put the executable python to jniLibs, but the python library is very huge.

@GRRedWings
Copy link

I find using the so adds around 26MB to support 32 and 64 bit arm. Not insignificant, but you're going to need most of that somewhere on the device anyways.

@hwangjr
Copy link

hwangjr commented Jul 22, 2021

now my app is only 6MB, and if add python support, 25MB is very huge for the app. Does android 11 support to exec python downloaded from remote?

@GRRedWings
Copy link

Right, your app is 6 MB, but it's going to need to get Python from somewhere, and that will have a cost of download and space correct?

I have only used it as an embedded library, but I suspect if Android 10 requires it embedded, it is for security and no future release will go back to remote.

@hwangjr
Copy link

hwangjr commented Jul 22, 2021

okay, thanks a lot for your reply.

@GRRedWings
Copy link

Have you tried to target something less than 10. I have found that if you target less than an API version, functionality that was taken away by the OS update will still work.

@hwangjr
Copy link

hwangjr commented Jul 23, 2021

yep, there is no solutions for this issue without make target sdk below 29 or put executable file to libs/ABI folder.

@canewsin
Copy link
Author

currently i put python bin jniLibs and libs in assets dir and serve them as separate files and serve them as dynamic modules even though apk size may not decrease for other than play store builds download size in play store.
see this repo for example
https://github.com/canewsin/python_ide

@hwangjr
Copy link

hwangjr commented Jul 23, 2021

if i put executable file: libpython3.8.so to libs/ABI, and download the dependencies from remote server(now you put them in assets folder), will this work? @canewsin

@canewsin
Copy link
Author

That will work, I do that for non Play Store builds, since dynamic modules are not downloadable outside I pack those as zip files and download and unzip those and chmod +x if necessary.

@yan12125
Copy link
Owner

As a record, there are more discussions about this issue on termux/termux-app#2155. I'm afraid all workarounds will be broken sooner or later. For example,

target something less than 10

The current Google Play Store policy already requires Android 10 as the minimum target, and Android 11 will be required since August. A long term solution might be alternative application stores like F-Droid...

@GRRedWings
Copy link

GRRedWings commented Jul 23, 2021

Another option is expansion files. As @canewsin described, you don't package it in your APK but download it later. This works with the play store. It may be possible you could be smart about your platform and only download the necessary version.

https://developer.android.com/google/play/expansion-files

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants