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

Build failed with an exception in Cordova 12 #3

Open
dariov1988 opened this issue Feb 20, 2024 · 4 comments
Open

Build failed with an exception in Cordova 12 #3

dariov1988 opened this issue Feb 20, 2024 · 4 comments

Comments

@dariov1988
Copy link

When I add the plugin to my project with: cordova plugin add https://github.com/FWiner/cordova-plugin-android-background-mode and try to build it, I get the following error:

/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:36: error: cannot find symbol
import android.support.v4.app.NotificationCompat;
                             ^
  symbol:   class NotificationCompat
  location: package android.support.v4.app
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:38: error: cannot find symbol
  import android.support.v4.app.NotificationManagerCompat;
                               ^
  symbol:   class NotificationManagerCompat
  location: package android.support.v4.app
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:346: error: package NotificationCompat does not exist
    private void setColor(NotificationCompat.Builder notification,
                                            ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:204: error: package NotificationCompat does not exist
        NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                          ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:204: error: package NotificationCompat does not exist
        NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                                                                        ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:220: error: package NotificationCompat.Action does not exist
            NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
                                     ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:220: error: package NotificationCompat.Action does not exist
            NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
                                                                                         ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:230: error: package NotificationCompat does not exist
                    new NotificationCompat.BigTextStyle().bigText(text));
                                          ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:341: error: cannot find symbol
    NotificationManagerCompat notification = NotificationManagerCompat.from(activity);
    ^
  symbol:   class NotificationManagerCompat
  location: class BackgroundModeExt
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:341: error: cannot find symbol
    NotificationManagerCompat notification = NotificationManagerCompat.from(activity);
                                             ^
  symbol:   variable NotificationManagerCompat
  location: class BackgroundModeExt
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
10 errors

FAILURE: Build failed with an exception.

Cordova version: 12

Please let me know if more information is required. Thanks!

@FWiner
Copy link
Owner

FWiner commented Feb 22, 2024

When I add the plugin to my project with: cordova plugin add https://github.com/FWiner/cordova-plugin-android-background-mode and try to build it, I get the following error:

/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:36: error: cannot find symbol
import android.support.v4.app.NotificationCompat;
                             ^
  symbol:   class NotificationCompat
  location: package android.support.v4.app
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:38: error: cannot find symbol
  import android.support.v4.app.NotificationManagerCompat;
                               ^
  symbol:   class NotificationManagerCompat
  location: package android.support.v4.app
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:346: error: package NotificationCompat does not exist
    private void setColor(NotificationCompat.Builder notification,
                                            ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:204: error: package NotificationCompat does not exist
        NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                          ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:204: error: package NotificationCompat does not exist
        NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                                                                        ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:220: error: package NotificationCompat.Action does not exist
            NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
                                     ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:220: error: package NotificationCompat.Action does not exist
            NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
                                                                                         ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:230: error: package NotificationCompat does not exist
                    new NotificationCompat.BigTextStyle().bigText(text));
                                          ^
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:341: error: cannot find symbol
    NotificationManagerCompat notification = NotificationManagerCompat.from(activity);
    ^
  symbol:   class NotificationManagerCompat
  location: class BackgroundModeExt
/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:341: error: cannot find symbol
    NotificationManagerCompat notification = NotificationManagerCompat.from(activity);
                                             ^
  symbol:   variable NotificationManagerCompat
  location: class BackgroundModeExt
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
10 errors

FAILURE: Build failed with an exception.

Cordova version: 12

Please let me know if more information is required. Thanks!

Hi dariov , i was tried to install this plugin to a clear cordova project(cordova version 12 , cordova-android 12), it seems like work fine. Can you post the specific screenshots of the errors and the plugin list?

@dariov1988
Copy link
Author

Hi @FWiner, thanks for answering, here are the steps to reproduce the problem:
Create an empty app:
cordova create hello com.example.hello HelloWorld
Add the Android platform:
cordova platform add android
Check requirements (optional):

cordova requirements

Requirements check results for android:
Java JDK: installed 17.0.10
Android SDK: installed true
Android target: installed android-34,android-33
Gradle: installed /usr/share/java/gradle/bin/gradle

Add the background plugin:
cordova plugin add https://github.com/FWiner/cordova-plugin-android-background-mode
Check the plugin list (optional):

cordova plugin list
cordova-plugin-background-mode 0.7.3 "BackgroundMode"
cordova-plugin-device 2.1.0 "Device"

Try to build the project for Android:

cordova build android
Checking Java JDK and Android SDK versions
ANDROID_HOME=~/Android/Sdk (recommended setting)
ANDROID_SDK_ROOT=undefined (DEPRECATED)
Using Android SDK: ~/Android/Sdk
Subproject Path: CordovaLib
Subproject Path: app

> Task :app:compileDebugJavaWithJavac FAILED
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:36: error: cannot find symbol
import android.support.v4.app.NotificationCompat;
                             ^
  symbol:   class NotificationCompat
  location: package android.support.v4.app
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:38: error: cannot find symbol
  import android.support.v4.app.NotificationManagerCompat;
                               ^
  symbol:   class NotificationManagerCompat
  location: package android.support.v4.app
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:346: error: package NotificationCompat does not exist
    private void setColor(NotificationCompat.Builder notification,
                                            ^
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:204: error: package NotificationCompat does not exist
        NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                          ^
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:204: error: package NotificationCompat does not exist
        NotificationCompat.Builder notification = new NotificationCompat.Builder(context, CHANNEL_ID)
                                                                        ^
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:220: error: package NotificationCompat.Action does not exist
            NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
                                     ^
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:220: error: package NotificationCompat.Action does not exist
            NotificationCompat.Action.Builder closeAction = new NotificationCompat.Action.Builder(getIconResId(closeIconName), settings.optString("closeTitle", "Close"), closeIntent);
                                                                                         ^
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/ForegroundService.java:230: error: package NotificationCompat does not exist
                    new NotificationCompat.BigTextStyle().bigText(text));
                                          ^
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:341: error: cannot find symbol
    NotificationManagerCompat notification = NotificationManagerCompat.from(activity);
    ^
  symbol:   class NotificationManagerCompat
  location: class BackgroundModeExt
~/hello/platforms/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java:341: error: cannot find symbol
    NotificationManagerCompat notification = NotificationManagerCompat.from(activity);
                                             ^
  symbol:   variable NotificationManagerCompat
  location: class BackgroundModeExt
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
10 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app: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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 737ms
27 actionable tasks: 1 executed, 26 up-to-date
Command failed with exit code 1: ~/hello/platforms/android/gradlew -b ~/hello/platforms/android/build.gradle cdvBuildDebug

If I remove the plugin:

cordova plugin remove cordova-plugin-background-mode
Uninstalling 1 dependent plugins.
Uninstalling cordova-plugin-device from android
Uninstalling cordova-plugin-background-mode from android
Subproject Path: CordovaLib
Subproject Path: app
Removing "cordova-plugin-background-mode"
Removing cordova-plugin-background-mode from package.json

And then try to build, it build correctly:

cordova build android
Checking Java JDK and Android SDK versions
ANDROID_HOME=~/Android/Sdk (recommended setting)
ANDROID_SDK_ROOT=undefined (DEPRECATED)
Using Android SDK: ~/Android/Sdk
Subproject Path: CordovaLib
Subproject Path: app

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.6/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1s
50 actionable tasks: 13 executed, 37 up-to-date
Built the following apk(s): 
        ~/hello/platforms/android/app/build/outputs/apk/debug/app-debug.apk

Thanks for your time and effort, have a nice day/night...

@FWiner
Copy link
Owner

FWiner commented Feb 23, 2024

Hi @dariov1988 , i double checked my local project and this issue was found in cordova version > 10, i think this link can help you, please try to build after modifying in Android Studio, if the error disappears, I will update the question in the next days.

@krychu90
Copy link

krychu90 commented Jul 14, 2024

I had this error too and changing:

import android.support.v4.app

to

import androidx.core.app

helped me.

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