Skip to content
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

Android module import error #2930

Open
ateshkoul opened this issue Oct 25, 2024 · 3 comments
Open

Android module import error #2930

ateshkoul opened this issue Oct 25, 2024 · 3 comments
Labels
android The issue relates to Android mobile support. awaiting details More details are needed before the issue can be triaged. bug A crash or error in behavior.

Comments

@ateshkoul
Copy link

ateshkoul commented Oct 25, 2024

Describe the bug

While building and running the app for an android phone, I am trying to get sensor data. From the documentation, I am trying to import the android intents. However, during the execution of the app, I receive the error "ModuleNotFoundError: No module named 'android'".

Steps to reproduce

  1. use 'from android.content import Intent' in the App.py
  2. briefcase create android
  3. briefcase build android
  4. briefcase run android

Expected behavior

import of the android module

Screenshots

No response

Environment

  • Operating System: Windows 10
  • Python version: 3.9
  • Software versions:
    toga = 0.4.8
    briefcase = 0.3.20
    python = 3.9
    toga_android = 0.4.7

Logs

←[31mE/AndroidRuntime: FATAL EXCEPTION: main←[0m
←[31mE/AndroidRuntime: Process: com.example.walkman, PID: 1399←[0m
←[31mE/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.walkman/org.beeware.android.MainActivity}: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'android'←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3781)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3943)←[0m
←[31mE/AndroidRuntime:   at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)←[0m
←[31mE/AndroidRuntime:   at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)←[0m
←[31mE/AndroidRuntime:   at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2348)←[0m
←[31mE/AndroidRuntime:   at android.os.Handler.dispatchMessage(Handler.java:106)←[0m
←[31mE/AndroidRuntime:   at android.os.Looper.loopOnce(Looper.java:233)←[0m
←[31mE/AndroidRuntime:   at android.os.Looper.loop(Looper.java:344)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.main(ActivityThread.java:8191)←[0m
←[31mE/AndroidRuntime:   at java.lang.reflect.Method.invoke(Native Method)←[0m
←[31mE/AndroidRuntime:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)←[0m
←[31mE/AndroidRuntime:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)←[0m
←[31mE/AndroidRuntime: Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'android'←[0m
←[31mE/AndroidRuntime:   at <python>.walkman.app.<module>(app.py:33)←[0m
←[31mE/AndroidRuntime:   at <python>.java.chaquopy.import_override(import.pxi:60)←[0m
←[31mE/AndroidRuntime:   at <python>.__main__.<module>(__main__.py:1)←[0m
←[31mE/AndroidRuntime:   at <python>.runpy._run_code(runpy.py:87)←[0m
←[31mE/AndroidRuntime:   at <python>.runpy._run_module_code(runpy.py:97)←[0m
←[31mE/AndroidRuntime:   at <python>.runpy.run_module(runpy.py:225)←[0m
←[31mE/AndroidRuntime:   at <python>.chaquopy_java.call(chaquopy_java.pyx:352)←[0m
←[31mE/AndroidRuntime:   at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:324)←[0m
←[31mE/AndroidRuntime:   at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method)←[0m
←[31mE/AndroidRuntime:   at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232)←[0m
←[31mE/AndroidRuntime:   at com.chaquo.python.PyObject.callAttr(PyObject.java:221)←[0m
←[31mE/AndroidRuntime:   at org.beeware.android.MainActivity.onCreate(MainActivity.java:85)←[0m
←[31mE/AndroidRuntime:   at android.app.Activity.performCreate(Activity.java:8129)←[0m
←[31mE/AndroidRuntime:   at android.app.Activity.performCreate(Activity.java:8109)←[0m
←[31mE/AndroidRuntime:   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1344)←[0m
←[31mE/AndroidRuntime:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3750)←[0m
←[31mE/AndroidRuntime:   ... 12 more←[0m
←[32mI/Process : Sending signal. PID: 1399 SIG: 9←[0m

Additional context

No response

@ateshkoul ateshkoul added the bug A crash or error in behavior. label Oct 25, 2024
@mhsmith
Copy link
Member

mhsmith commented Oct 25, 2024

from android.content import Intent

That should work fine, so my guess is that isn't actually the code that's producing the exception.

  • Is that actually line 33 of app.py?
  • Have you updated your app by adding -u to the briefcase run command line, as explained here?

If neither of those work, please post at least the first 33 lines of app.py.

@ateshkoul
Copy link
Author

ateshkoul commented Oct 26, 2024

I tried both checks as well as verified the same error on android emulator as well. Here are the first 33 lines of app.py:

"""
app for music 
"""

# TODO: validation of the input in subject details
# TODO: webplayer needs to be physically made active 
# So, to be implemened. 

import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW
import os
import pdb 
import json
import asyncio
import numpy as np
import random
import spotipy
from walkman.eye_tracker.device import Device,StatusUpdateNotifier
from walkman.eye_tracker.models import Recording
from walkman.eye_tracker.discovery import Network
from datetime import datetime,timedelta
from meteostat import Point, Hourly


from walkman.spotify_class import walkman_spotify
import time

from toga.platform import get_current_platform

if not get_current_platform() == 'windows':
    from java import jclass
    from android.content import Intent (this is the line 33)

Thanks a lot!

@freakboy3742 freakboy3742 added android The issue relates to Android mobile support. awaiting details More details are needed before the issue can be triaged. labels Oct 27, 2024
@mhsmith
Copy link
Member

mhsmith commented Oct 31, 2024

toga = 0.4.8
toga_android = 0.4.7

All Toga packages must be the same version. Are they actually different, or was this just a typo in the issue?

I tried the following:

  • Install Briefcase 0.3.20
  • Copy this code into a project of my own
  • Add requirements for spotipy, numpy and meteostat
  • Comment out the walkman lines, which I assume are your own modules.

And it worked fine.

Here are some more things to try:

  • Rerun briefcase create android, then briefcase run android again.

  • Replace from android.content import Intent with Intent = jclass("android.content.Import"). If that works, does your other code do anything related to Java or Android which could be interfering with the import?

If neither of those work, then you'll need to provide a complete minimal example project which reproduces the issue, push it to GitHub, and post the link here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android The issue relates to Android mobile support. awaiting details More details are needed before the issue can be triaged. bug A crash or error in behavior.
Projects
None yet
Development

No branches or pull requests

3 participants