Skip to content

Base: Failed to import "android" module. Could not remove android presplash. #1153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Zen-CODE opened this issue Oct 27, 2017 · 11 comments
Closed

Comments

@Zen-CODE
Copy link
Member

This occurs after removing the .buildozer folder, and using the latest master checkouts of buildozer and python-for-android. This occurs when trying to use the 'android_old' target (the 'android' gives us this error: #1142)

python-for-android: commit 2136e0f
buildozer: commit 3a93783aa8cbfb0605e4b46f977f8c9951c1a043

This means our python service does not start and our background downloads to not start.

This happens even if we add android to the requirements. From the buildozer.spec file.

requirements = python, sqlite3, kivy==1.10.0, openssl, pyjnius, android

I can see where this error is throw (kivy.base) but the only files containing that text in the .buildozer folder are pyc and pyo files.

.buildozer/android/platform/python-for-android/dist/xxx/python-install/lib/python2.7/site-packages/kivybase.py

Any ideas' on how to solve this? Or where one makes changes to alter this?

@inclement
Copy link
Member

This is just a notification, it shouldn't actually cause anything to fail.

The actual reason for the warning is that Kivy actually does from android import remove_presplash, which is not present when the android module is compiled with pygame. I guess the notification should be made clearer, on general principle.

@Zen-CODE
Copy link
Member Author

The reason for concern is that our android service is now not starting. I thought this might be the reason, but let me eliminate the possible of the service breaking for other reasons...

@Zen-CODE
Copy link
Member Author

@inclement

From https://python-for-android.readthedocs.io/en/latest/services/

Is there a way to add --service=myservice:/path/to/myservice.py argument to p4a via the buildozer.spec, or do we need to user the Service folder method?

@Zen-CODE
Copy link
Member Author

Zen-CODE commented Oct 28, 2017

@the buildozer log is showing the following:

# Application pushed.
# Run on 0123456789ABCDEF
# Run '/home/kivy/.buildozer/android/platform/android-sdk-23/platform-tools/adb shell am start -n speedtest.maths.xxx.com/org.renpy.android.PythonActivity -a org.renpy.android.PythonActivity'
# Cwd /home/kivy/.buildozer/android/platform
Starting: Intent { act=org.renpy.android.PythonActivity cmp=speedtest.maths.xxx.com/org.renpy.android.PythonActivity }
Error type 3
Error: Activity class {speedtest.maths.xxx.com/org.renpy.android.PythonActivity} does not exist.
# Application started.

I see somewhere that that has been renamed to PythonService? This is building with the android_old.

@inclement
Copy link
Member

I think the services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY line is for new-style python-for-android services, although these will only work with the sdl2 bootstrap.

I don't know what's up with your intent error. Is this just what happens when you run buildozer android_old debug run? It looks like buildozer might just have some wrong assumption about the activity name, although it does look right to me.

@Zen-CODE
Copy link
Member Author

Yes, that's the command which produces this. I'll do some more digging and come back....

@Zen-CODE
Copy link
Member Author

Zen-CODE commented Oct 30, 2017

We are using SDL, but I can't seem to get the service working. As well as the conventional:

from android import AndroidService
upd_process = AndroidService('CAMI-Apps service', 'running')
upd_process.start('CAMI-Apps service started')

we also tried service creation as below. It does not throw an error in the app but still does not run:

    service = autoclass('org.renpy.android.PythonActivity')
    service.start_service(
        'CAMI-Apps Content Service',
        'Installs CAMI-Apps Educational Content',
        'argument to service')

Also, adding the below to the buildozer.spec file,

services = myservice:service/main.py

we still get the 'class not found error'

    service = autoclass('xxx/ServiceMyservice' + )

throws

    Could not create service: Class not found 'xxx/ServiceMyservice',

How to get this working? This is getting quite critical for us as it's been over 2 weeks since we could put out a working build. Using the new toolchain is not an option as we get the libpythonxxx SDLError both our testing tablets. How to go forward?

@inclement
Copy link
Member

inclement commented Oct 31, 2017

it's been over 2 weeks since we could put out a working build

Did you have a working build before that and something broke? Or that is just when you started trying to use this functionality?

we also tried service creation as below. It does not throw an error in the app but still does not run:

Is there definitely nothing in the log here? Would you be able to post it? Given how the android module is structured, I would have expected at least some kind of notification about what's going on.

Also, adding the below to the buildozer.spec file,
...
we still get the 'class not found error'

This method will definitely only work with the sdl2 bootstrap, so that's at least an okay error.

@Zen-CODE
Copy link
Member Author

Zen-CODE commented Oct 31, 2017

Trying

    @staticmethod
    def try_orig():
        """
        This holds the code used to create the original python service using the
        old toolchain.
        """
        try:
            from android import AndroidService
            upd = AndroidService("CAMI-Apps Service", "running")
            upd.start("CAMI-Apps service started.")
            return True
        except Exception as e:
            Logger.error(
                "androidservice.py: try_orig failed with {0}".format(e))
            return False

Now produces the following log and the error trap above is never reached:

https://gist.github.com/Zen-CODE/e6a9b303e08324d91786bb4a89fd0181

Search for 'androidservice.py' to find the point where it tries to call the above code.

[INFO   ] [androidservice.py] Trying <function try_orig at 0x57136fb0>

Now the error is different. Is "No JNI_OnLoad found" indicative of something?

@Zen-CODE
Copy link
Member Author

I am happy to report we found the issue. The service dies the moment it calls this code, but it works in the app

        from jnius import autoclass, cast
        # https://developer.android.com/reference/android/content/res/Configuration.html#keyboard
        python_activity = autoclass('org.renpy.android.PythonActivity')
        current_activity = cast('android.app.Activity',
                                python_activity.mActivity)
        config = current_activity.getResources().getConfiguration()

        Logger.info("localos.py: jnius imported.")
        if config.keyboard != 1 and config.hardKeyboardHidden != 2:
            # For .keyboard:
            #     KEYBOARD_UNDEFINED = 0
            #     KEYBOARD_NOKEYS = 1
            #     KEYBOARD_QWERTY = 2
            # For .hardKeyboardHidden
            #     HARDKEYBOARDHIDDEN_UNDEFINED = 0
            #     HARDKEYBOARDHIDDEN_NO = 1
            #     HARDKEYBOARDHIDDEN_YES = 2
            #
            # They have a keyboard and it's not hidden/folded back
            return True
        else:
            return False

Not sure why as there is not message I could detect, but moving this outside the service makes it work again. Yay

@inclement. Thanks

@AndreMiras
Copy link
Member

Failed to import "android" module. Could not remove android presplash.

This message to me looks like a regression even though it doesn't crash. I remember adding android module to buildozer.spec requirements fixed it before (AndreMiras/PyWallet@68952ef), but now not anymore (AndreMiras/EtherollApp@5a8c41c).
The main difference between the two apps, is the first one is still on Python2 and was build with older dependencies (like p4a) and the other one is on Python3 CrystaX and run with everything more recent.
This is also a bit annoying because it spams my Sentry logs, I may investigate further.

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

No branches or pull requests

3 participants