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

Got Errors while load this project to Android Studio "2 modules cannot to be loaded" app.iml demo.iml #22

Closed
hushanhsiang opened this issue Jan 9, 2018 · 16 comments
Labels

Comments

@hushanhsiang
Copy link

hushanhsiang commented Jan 9, 2018

This Error is also happen while load chaquopy-hellp project.

lgurktjn_o

@mhsmith
Copy link
Member

mhsmith commented Jan 9, 2018

You can work around this by loading the project using File > New > Import Project, rather than File > Open.

Thanks for the report, we'll fix this in the next version if possible.

@mhsmith mhsmith closed this as completed Jan 9, 2018
@mhsmith mhsmith reopened this Jan 9, 2018
@mhsmith mhsmith added the bug label Jan 9, 2018
@hushanhsiang
Copy link
Author

OK, it's no error happen now by "import project".
But I don't see any difference between Android's "Hello World" and "chaquopy-hello".
I can find "hello.py" in this project but how to edit it to show "Chaquopy Hello" or other words.
Please help, thanks.

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

Apart from being in Python, the project works just like a normal Android project. The onCreate method calls setContentView to load the layout file here:

https://github.com/chaquo/chaquopy-hello/blob/master/app/src/main/res/layout/activity_main.xml

You can edit the layout file with the visual editor in Android Studio, or by directly editing the XML.

Any tutorials on Android programming in Java should be fairly easy to adapt to Chaquopy, following the pattern of the initial port.

@hushanhsiang
Copy link
Author

This is OscarHu....
"chaquopy-master" project is running well with my HTC phone, so far. I will test more and study how to make my code by learning from this demo, but it's complex for me.
Still need a very simple code running only python with Android.
Thanks.

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

I think the Android user interface API is generally well-designed, but yes, it does take some time to learn. As I said in the other issue, we'll release another example app soon for running text-based Python scripts without a GUI.

@hushanhsiang
Copy link
Author

hushanhsiang commented Jan 10, 2018 via email

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

(Moved from chaquo/chaquopy-hello#2)

I found below code in hello.py:
"class MainActivity(static_proxy(AppCompatActivity)):

@Override(jvoid, [Bundle])
def onCreate(self, state):
    AppCompatActivity.onCreate(self, state)
    self.setContentView(R.layout.activity_main)"

Is it means that I can start my program by "hello.py" directly? Don't need a "MainActivity.java" to start the program?

I'd like to change "Hello World" of the TextView to "Chaquopy Hello World" by Python code then I put "self.findViewById(R.id.txv).setText(R.string.app_name)" in the code but not working, stop by system error.

"class MainActivity(static_proxy(AppCompatActivity)):

@Override(jvoid, [Bundle])
def onCreate(self, state):
    AppCompatActivity.onCreate(self, state)
    self.setContentView(R.layout.activity_main)
    self.findViewById(R.id.txv).setText(R.string.app_name)

"
Already changed the id of "TextView" in "active_main.xml" as below and used the "app_name" string in "string.xml".
TextView
android:id="@+id/txv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

Is it means that I can start my program by "hello.py" directly? Don't need a "MainActivity.java" to start the program?

Yes, the static_proxy mechanism generates the corresponding Java file automatically, so you don't need to deal with that.

Your changes look fine to me. What was the error you received?

@hushanhsiang
Copy link
Author

It can be made an APK code by Android Studio and installed on my HTC phone but got an Error message, "Unfortunately, Chaquopy Hello World has stopped" while running it.
Could you try it on your side since it's very little change of "chaquopy-hello"?

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

I have, and it worked as expected. Please find the error details in the logcat as described here.

@hushanhsiang
Copy link
Author

Split APKs installed
$ adb shell am start -n "com.chaquo.python.hello/hello.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Unexpected error while executing: am start -n "com.chaquo.python.hello/hello.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while Launching activity

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

No, that's the Run window. The details of the error should be in the Logcat window.

@hushanhsiang
Copy link
Author

hushanhsiang commented Jan 10, 2018

I take a screen shot as below link:
https://images2.imgbox.com/62/59/TEkdZ8Ab_o.png
And the text of Logcat error message:

01-11 06:44:20.044 22343-22343/com.chaquo.python.hello E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.chaquo.python.hello, PID: 22343
                                                                         java.lang.ExceptionInInitializerError
                                                                             at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                             at java.lang.Class.newInstance(Class.java:1572)
                                                                             at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:162)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                             at android.os.Looper.loop(Looper.java:209)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5900)
                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:372)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
                                                                          Caused by: com.chaquo.python.PyException: ModuleNotFoundError: No module named 'android'
                                                                             at <python>.java.chaquopy.import_override (.c:59641)(java\import.pxi:18)
                                                                             at <python>.reraise(/data/data/com.chaquo.python.hello/files/chaquopy/chaquopy.zip/java/_vendor/six.py:686)
                                                                             at <python>.java.chaquopy.import_override (.c:60681)(java\import.pxi:53)
                                                                             at <python>.<module>(/android_asset/chaquopy/app.zip/hello.py:7)
                                                                             at <python>.load_module_impl(/data/data/com.chaquo.python.hello/files/chaquopy/chaquopy.zip/java/android/importer.py:155)
                                                                             at <python>.load_module(/data/data/com.chaquo.python.hello/files/chaquopy/chaquopy.zip/java/android/importer.py:91)
                                                                             at <python>._load_backward_compatible(<frozen importlib._bootstrap>:626)
                                                                             at <python>._load_unlocked(<frozen importlib._bootstrap>:656)
                                                                             at <python>._find_and_load_unlocked(<frozen importlib._bootstrap>:955)
                                                                             at <python>._find_and_load(<frozen importlib._bootstrap>:971)
                                                                             at <python>._gcd_import(<frozen importlib._bootstrap>:994)
                                                                             at <python>.import_module(/data/data/com.chaquo.python.hello/files/chaquopy/stdlib.zip/importlib/__init__.py:126)
                                                                             at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule (.c:2790)(chaquopy_java.pyx:128)
                                                                             at com.chaquo.python.Python.getModule(Native Method)
                                                                             at hello.MainActivity.<clinit>(MainActivity.java:13)
                                                                             at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                             at java.lang.Class.newInstance(Class.java:1572) 
                                                                             at android.app.Instrumentation.newActivity(Instrumentation.java:1083) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:162) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                             at android.os.Looper.loop(Looper.java:209) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5900) 
                                                                             at java.lang.reflect.Method.invoke(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800) 

@mhsmith
Copy link
Member

mhsmith commented Jan 10, 2018

Well, there is no import statement at hello.py:7 in the original file, so you must have added something else. If you've added a line simply saying import android or similar, then unfortunately that won't work: please see the notes about the limitations of the import hook.

@hushanhsiang
Copy link
Author

It's interesting, I didn't modify anything but it works well now. Anything change on Chaquopy?
It's great and I can try the others Android feature with Chaquopy~~~

Next topic is how to use python libraries such as json, requests, beautifulsoup......
Any notes to use them? thanks.

@mhsmith
Copy link
Member

mhsmith commented Jan 11, 2018

As of a few minutes ago, the original Android Studio loading errors are fixed for both the demo and "hello" projects. Nothing else has changed on our side.

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

No branches or pull requests

2 participants