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

Checklist

  • the issue is indeed a bug and not a support request
  • issue doesn’t already exist: https://github.com/kivy/python-for-android/issues
  • I have a short, runnable example that reproduces the issue
  • I reproduced the problem with the latest development version (p4a.branch = develop)
  • 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;

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I tried with this getting started https://python-for-android.readthedocs.io/en/latest/quickstart/ and installed p4a via pip, seems the issue is still there.

Yes. And that should be fixed. But using p4a.branch = develop works right now afaik 😃

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

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: <<<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;`  >>>

So this bug is needed to be reopened.

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

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

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

Sorry for confusing you @AndreMiras

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

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

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.

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