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

Cannot find symbol "LocalBroadcastManager" #71

Closed
MrWeezle opened this issue Jul 18, 2023 · 6 comments
Closed

Cannot find symbol "LocalBroadcastManager" #71

MrWeezle opened this issue Jul 18, 2023 · 6 comments
Assignees

Comments

@MrWeezle
Copy link

MrWeezle commented Jul 18, 2023

I upgraded my Ionic App to Capacitor 5 and also updated all plugins to the newest compatible version.
I also updated this plugin (cordova-broadcaster) to version 5.0.0 where I saw that a fix for androidx was implemented.
Sadly, the build still fails with the following error message:

android/capacitor-cordova-android-plugins/src/main/java/org/bsc/cordova/CDVBroadcaster.java:192: error: cannot find symbol
    return LocalBroadcastManager.getInstance(super.webView.getContext()).sendBroadcast(intent);
           ^
  symbol:   variable LocalBroadcastManager
  location: class CDVBroadcaster`

Manually editing the gradle file to add
implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"
and removing
implementation "com.android.support:support-v4:26+"
because it is not compatible, results in a working Build in Android Studio and a functioning broadcaster. Leaving the support-library in results in following error messages, thus i removed it:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.10.0-runtime (androidx.core:core:1.10.0) and support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)

But building it with Jenkins always fails, because the gradle file is overridden with capacitor sync.

The import in CSVBroadcaster.java is
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
which is different from the value I saw in the PR a few days ago.

Is there any solution to get a working build with Jenkins?

@MrWeezle MrWeezle changed the title Caoont find symbol "LocalBroadcastManager" Cannot find symbol "LocalBroadcastManager" Jul 18, 2023
@bsorrentino
Copy link
Owner

Hi @MrWeezle

I merged PR without any modification and the last PR commit is:

- import androidx.LocalBroadcastManager;
+ import androidx.localbroadcastmanager.content.LocalBroadcastManager;

This is mostly a capacitor issue and you need further investigations on it. When I'll have a time-slot give I try to figure out the problem

@MrWeezle
Copy link
Author

MrWeezle commented Jul 18, 2023

Thanks for the reply. I looked at the commits in the wrong order, my bad.

But the solution is changing the implementation lines in the gradle file.

add

implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"

and remove

implementation "com.android.support:support-v4:26+"

At least that's what solved the issue for me for building with Android Studio but not with Jenkins because even though I added the gradle to git the change is overridden to the default when using npx cap sync

@MrWeezle
Copy link
Author

MrWeezle commented Jul 19, 2023

I found a solution that works for me:

In the plugin.xml file in the section for android I changed

<framework src="com.android.support:support-v4:26+" />
to
<framework src="androidx.localbroadcastmanager:localbroadcastmanager:1.0.0" />

The Build process updates the gradle file correctly and no errors are shown.
For validation with a Jenkins Build I forked this project, implemented the change, used the forked project in package.json and ran a build. No errors.

I cannot confirm that changing the used library in the framework part works for every use case, but it works for our app.

@bsorrentino bsorrentino self-assigned this Jul 19, 2023
@bsorrentino
Copy link
Owner

HI @MrWeezle

I think that your update to plugin.xml is the right way to deploy broadcaster plugin

I'll arrange a new release with your fix

@MrWeezle
Copy link
Author

hi @bsorrentino

Thank you very much for the fast response.

bsorrentino added a commit that referenced this issue Jul 19, 2023
replace com.android.support:support-v4:26+ with androidx.localbroadcastmanager:localbroadcastmanager:1.1.0

issue #71
@bsorrentino
Copy link
Owner

fixed in release 5.1.0

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

No branches or pull requests

2 participants