Python-for-android: Execution failed for task ':compileDebugJavaWithJavac'. "DialogInterface", "AlertDialog" and "KeyEvent" not found.

Created on 3 Jun 2020  路  14Comments  路  Source: kivy/python-for-android

Checklist

  • [x] the issue is indeed a bug and not a support request
  • [x] issue doesn't already exist: https://github.com/kivy/python-for-android/issues
  • [x] I have a short, runnable example that reproduces the issue
  • [x] I reproduced the problem with the latest development version (p4a.branch = develop)
  • [x] I used the grave accent (aka backticks) to format code or logs when appropriated

Versions

  • Python: 3.8.2
  • OS: Docker
  • Kivy: N/A
  • Cython: 0.29.19
  • OpenJDK: 1.8.0_252

Description

I am trying to package a flask app. Hello World App.

Command:

$ docker run \              
    --interactive \
    --tty \
    --volume "$PWD":/home/user/app/testapps \
    my_p4a_dist bash
$ source venv/bin/activate
$ cd testapps/
$ p4a apk --private . --package=org.example.myapp --name "My WebView Application" --version 0.1 --bootstrap=webview --requirements=flask,feedparser --port=5000         --sdk-dir $ANDROID_HOME/android-sdk         --ndk-dir $ANDROID_HOME/android-ndk --debug

Spec file: N/A

Logs


Log stating some symbols "DialogInterface", "AlertDialog" and "KeyEvent" were not found.

Listing '/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/webview_includes'...
[INFO]:    Detected highest available build tools version to be 28.0.2
[DEBUG]:   -> running gradlew assembleDebug
[DEBUG]:    Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
[DEBUG]:    
[DEBUG]:    > Task :compileDebugJavaWithJavac FAILED
[DEBUG]:    /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:245: error: cannot find symbol
[DEBUG]:        public boolean onKeyDown(int keyCode, KeyEvent event) {
[DEBUG]:                                              ^
[DEBUG]:      symbol:   class KeyEvent
[DEBUG]:      location: class PythonActivity
[DEBUG]:    /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:130: error: package AlertDialog does not exist
[DEBUG]:                    AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(PythonActivity.mActivity);
[DEBUG]:                               ^
[DEBUG]:    /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:130: error: package AlertDialog does not exist
[DEBUG]:                    AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(PythonActivity.mActivity);
[DEBUG]:                                                                   ^
[DEBUG]:    /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:137: error: package DialogInterface does not exist
[DEBUG]:                        new DialogInterface.OnClickListener() {
[DEBUG]:                                           ^
[DEBUG]:    /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:247: error: cannot find symbol
[DEBUG]:            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
[DEBUG]:                            ^
[DEBUG]:      symbol:   variable KeyEvent
[DEBUG]:      location: class PythonActivity
[DEBUG]:    Note: Some input files use or override a deprecated API.
[DEBUG]:    Note: Recompile with -Xlint:deprecation for details.
[DEBUG]:    5 errors
[DEBUG]:    
[DEBUG]:    
[DEBUG]:    FAILURE: Build failed with an exception.
[DEBUG]:    
[DEBUG]:    * What went wrong:
[DEBUG]:    Execution failed for task ':compileDebugJavaWithJavac'.
[DEBUG]:    > Compilation failed; see the compiler error output for details.
[DEBUG]:    
[DEBUG]:    * Try:
[DEBUG]:    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[DEBUG]:    
[DEBUG]:    * Get more help at https://help.gradle.org
[DEBUG]:    
[DEBUG]:    BUILD FAILED in 29s
[DEBUG]:    15 actionable tasks: 3 executed, 12 up-to-date
[DEBUG]:    
[DEBUG]:    
Exception in thread background thread for pid 163:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/app/venv/lib/python3.8/site-packages/sh.py", line 1662, in wrap
    fn(*args, **kwargs)
  File "/home/user/app/venv/lib/python3.8/site-packages/sh.py", line 2606, in background_thread
    handle_exit_code(exit_code)
  File "/home/user/app/venv/lib/python3.8/site-packages/sh.py", line 2304, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/user/app/venv/lib/python3.8/site-packages/sh.py", line 877, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/gradlew assembleDebug

  STDOUT:
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details

> Task :compileDebugJavaWithJavac FAILED
/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:245: error: cannot find symbol
    public boolean onKeyDown(int keyCode, KeyEvent event) {
                                          ^
  symbol:   class KeyEvent
  location: class PythonActivity
/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:130: error: package AlertDialog does not exist
                AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(PythonActivity.mActivity);
                           ^
/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:130: error: package AlertDialog does not exist
                AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(PythonActivity.mActivity);
                                                               ^
/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:137: error: package DialogInterface does not exist
                    new DialogInterface.OnClickListener() {
                                       ^
/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java:247: error: cannot find symbol
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
                        ^
  symbol:   variable KeyEvent
  location: class PythonActivity
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 29s
15 actionable tasks: 3 executed, 12 up-to-date





[INFO]:    STDOUT (last 20 lines of 47):
[DEBUG]:Note: Recompile with -Xlint:deprecation for details.    
5 errors    


FAILURE: Build failed with an exception.    

* What went wrong:  
Execution failed for task ':compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details.    

* Try:  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.    

* Get more help at https://help.gradle.org  

BUILD FAILED in 29s 
15 actionable tasks: 3 executed, 12 up-to-date  

[INFO]:    STDERR:

[INFO]:    COMMAND:
cd /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a && /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/gradlew assembleDebug

[WARNING]: ERROR: /home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/gradlew failed!

Solution (or workaround)

import android.content.DialogInterface;
import android.app.AlertDialog;
import android.view.KeyEvent;

needed to be added to
/home/user/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java
below line

package org.kivy.android;
bug

All 14 comments

That's the type of bug reports I'd like to see more often :muscle: Kudos for the effort to respect the format and the investigation regarding the solution :clap:
So you're saying I introduced a regression in https://github.com/kivy/python-for-android/pull/2187/files#diff-6d13f4ee93e76e3cd43f2bb12409e0b3L20-L22 :sweat_smile:
I think your solution is valid, please make a pull request with it, otherwise I can make it myself later

@sak96 give it a try with p4a.branch = develop and close the issue if that fixes it for you.

Will do tommorrow (late night here).

Does docker build pickup the changes as the command in dockerfile has not changed. Is there any way to start the build from a given step (incremental) ? I have to check this out. I have some data bandwidth issue at my location so not sure if I will be able to download the whole thing. Will close the bug once things work or you may close it if you want.

Thanks for quick responses. It was really helpful.

It depends what you mean with Docker we do have images that get updated automatically on merge to develop and master for both buildozer and python-for-android.
The python-for-android Dockerfile should indeed benefit from incremental update if you pull it as only the last layer should be affected.
Anyway, even with a limited connection buildozer android clean would not delete the dist so it won't need to re-download everything. Mainly the only thing that should get downloaded is the p4a source code update which should indeed be incremental (git pull) and minimal

Ok. Will try it out. I may need a day or two to test it out. Hope the delay is not a issue. If it is you may mark the issue as closed.

@AndreMiras

I think java linter will really be helpful in pipeline. may be this stackoverflow link might help. Not a java developer so I am not sure of any good tools.

The issue i was facing was in pythonforandroid/bootstraps/webview/build/src/main/java/org/kivy/android/PythonActivity.java.

But fixed pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java in #2229.

Note: There is third PythonActivity.java file in the diff you mentioned here.

I did not familiarize with the project structure but now i see how things are structured. I think it is better if you fix the error. I may need more time due some network issue with my ISP.

Thanks

Lesson learned here is test before raising PR. (Again network issue) :sob:

Thanks for testing it. So I understand it's fixed for webview, but some other files still has the issue?
Completely agree for the linter and it's in my task list. I actually have something ready-ish in local, but I'd like my other PR to be approved so I can merge and move forward with more stuff. I don't like piling too many PRs

Sorry for confusing you @AndreMiras

I fixed the issue for sdl2 type of bootstrap. But bug for webview still exists.

ahah true that, I overlooked it. I'll make a PR. Actually the sdl2 one was not needed, so I'll revert :)

I also figured it now.

My bad. I feel so sheepish.

I remember checking it twice weather the keyevent was referenced in same file. I got confused.

Sorry for that.

No worries, that's my bad for also overlooking it. At least you made a comprehensive bug report and you gave it a try to fix it. Thanks again

The current release and latest 'develop' branch both are failed to be built, because of this persisting error, and the only way to make this working was that original way as it was on the day 1:
<< `` import android.content.DialogInterface; import android.app.AlertDialog; import android.view.KeyEvent;

``needed to be added to /home/$USER/.local/share/python-for-android/dists/unnamed_dist_1__armeabi-v7a/src/main/java/org/kivy/android/PythonActivity.java below line package org.kivy.android;` >>>

So this bug is needed to be reopened.

  1. What is the real reason this can't be solved?

I was running into this issue too. @mnba's answer worked for me.

Was this page helpful?
0 / 5 - 0 ratings