bsorrentino / cordova-broadcaster

Cordova Plugin to allow message exchange between javascript and native (and viceversa)
MIT License
113 stars 53 forks source link

Cannot find symbol "LocalBroadcastManager" #71

Closed MrWeezle closed 11 months ago

MrWeezle commented 11 months ago

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?

bsorrentino commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

hi @bsorrentino

Thank you very much for the fast response.

bsorrentino commented 11 months ago

fixed in release 5.1.0