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

[Compile]: Swift Compiler Error (Xcode): Instance member 'connectivityProvider' cannot be used on type 'ConnectivityPlusPlugin' #3355

Open
8 tasks done
Selectus2 opened this issue Nov 14, 2024 · 8 comments
Labels
compile Compilation error triage

Comments

@Selectus2
Copy link

Operating System

macOS Sonoma version 14.6.1

Plugin

connectivity_plus

Version

6.1.0

Flutter SDK

3.24.3

Compilation command

fvm flutter run

Dart Dependencies

No response

Native dependencies

No response

Compilation Error

Swift Compiler Error (Xcode): Instance member 'connectivityProvider' cannot be used on type 'ConnectivityPlusPlugin'
/Users/vishwa/.pub-cache/hosted/pub.dev/connectivity_plus-6.1.0/darwin/connectivity_plus/Sources/connectivity_plus/ConnectivityPlusPlugin.swift:41:64


Could not build the application for the simulator.
Error launching application on iPhone 16.

Flutter Doctor

[✓] Flutter (Channel stable, 3.24.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-IN)
    • Flutter version 3.24.3 on channel stable at /Users/vishwa/fvm/versions/3.24.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (9 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/vishwa/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.94.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.100.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 130.0.6723.119

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Checklist before submitting a bug

  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@Selectus2 Selectus2 added compile Compilation error triage labels Nov 14, 2024
@Selectus2
Copy link
Author

FYI, When tried building with connectivity_plus-6.0.5 its building properly with no issues.

@miquelbeltran
Copy link
Member

miquelbeltran commented Nov 14, 2024

Is per chance your app project still in obj-c and not swift?

https://github.com/fluttercommunity/plus_plugins/pull/3173/files#r1713480016

@miquelbeltran
Copy link
Member

miquelbeltran commented Nov 14, 2024

Mmmhh I cannot reproduce it either with an ios objc project, I did the following:

flutter create -i objc --empty test_ios
flutter pub add connectivity_plus
open ios/Runner.xcworkspace (to fix provisioning profile)
flutter build ios

Compilation worked:

Building com.example.testIos.xyz for device (ios-release)...
Automatically signing iOS for device deployment using specified development team in Xcode project: _______
Running pod install...                                             805ms
Running Xcode build...
 └─Compiling, linking and signing...                         3.6s
Xcode build done.                                           34.1s
✓ Built build/ios/iphoneos/Runner.app (25.1MB)

Same result when creating a swift project.

Can you do the same and see if it builds for you?

@FullstackWEB-developer
Copy link

I got similar issue with connectivity_plus-6.1.0

Error (Xcode): 'ConnectivityPlusPlugin' has different definitions in different modules; first difference is definition in module 'connectivity_plus.Swift'
found 2 referenced protocols
/Users/Documents/test-project/app/build/ios/Production-Release-iphoneos/connectivity_plus/connectivity_plus.framework/Headers
/connectivity_plus-Swift.h:310:11


Modules Issue (Xcode): Definition of 'ConnectivityPlusPlugin' must be imported from module 'connectivity_plus.Swift' before it is required
/Users/Documents/test-project/ios/Runner/GeneratedPluginRegistrant.m:167:3


Encountered error while building for device.

However, this problem does not occur in connectivity_plus-6.0.5.

This is AppDelegate.swift

import UIKit
import Flutter
import GoogleMaps
import flutter_local_notifications

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    // This is required to make any communication available in the action isolate.
    FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
      GeneratedPluginRegistrant.register(with: registry)
    }
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    //Google Maps API Key
    GMSServices.provideAPIKey("")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
  // for the OneSignal package
  override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
      super.userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler)
  }
  override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
      super.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
  }
}

And the project also has a swift code section like this: NotificationService.swift

import UserNotifications

import OneSignalExtension

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var receivedRequest: UNNotificationRequest!
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.receivedRequest = request
        self.contentHandler = contentHandler
        self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            /* DEBUGGING: Uncomment the 2 lines below to check this extension is executing
                          Note, this extension only runs when mutable-content is set
                          Setting an attachment or action buttons automatically adds this */
            // print("Running NotificationServiceExtension")
            // bestAttemptContent.body = "[Modified] " + bestAttemptContent.body

            OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
        }
    }

    override func serviceExtensionTimeWillExpire() {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
            contentHandler(bestAttemptContent)
        }
    }
}

@miquelbeltran
Copy link
Member

Do you see this error in debug builds or only release builds?

The only change in 6.1.0 is that it deleted the objc plugin definition, which is not clear for me if it was still necessary: https://github.com/fluttercommunity/plus_plugins/pull/3173/files

Is your project somehow an old codebase?

@FullstackWEB-developer
Copy link

FullstackWEB-developer commented Nov 22, 2024

@miquelbeltran Thank you for your quick reply.
Sure, this is a project I've been managing for 3 years, but I'm using the latest stable flutter version, and all 28 other packages except connectivity_plus are the latest versions.
Could it be that removing the objc plugin definition is causing conflicts with other packages? Or is it that I have objc in my code base?
image
However, the Object-C part of my project is only the automatically generated this part

@miquelbeltran
Copy link
Member

Could it be that removing the objc plugin definition is causing conflicts with other packages? Or is it that I have objc in my code base?

I think the issue is a combination of old(ish) Flutter native codebase and removing the objc definition, indeed.

A newly created Flutter project with objc doesn't have this issue.

A possible solution can be to revert part of the changes in #3173 but keeping the Swift package support. The problem is that I cannot reproduce the issue on my side, so I'd love if someone who has the problem can try this somehow and submit a PR.

@FullstackWEB-developer
Copy link

Thank you for your reply.
Let me try again with new codebase

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

No branches or pull requests

3 participants