firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.72k stars 3.97k forks source link

[storage] Cannot compile #12961

Closed InShad7 closed 4 months ago

InShad7 commented 5 months ago

Is there an existing issue for this?

Which plugins are affected?

No response

Which platforms are affected?

iOS

Description

when I run my flutter project on Xcode I get this error

  Swift Compiler Error (Xcode): Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit
/Users/admin/Desktop/munjiya_ios/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/StorageDownloadTask.swift:127
:13

 Swift Compiler Error (Xcode): Reference to property 'pageSize' in closure requires explicit use of 'self' to
 make capture semantics explicit
 /Users/admin/Desktop/munjiya_ios/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Internal/StorageListTask.swif
 t:94:13

 Swift Compiler Error (Xcode): Reference to property 'previousPageToken' in closure requires explicit use of
 'self' to make capture semantics explicit
 /Users/admin/Desktop/munjiya_ios/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Internal/StorageListTask.swif
 t:98:13

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

but in android it works perfectly

Reproducing the issue

these are the file I got errors

    ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Internal/StorageListTask.swift

   ios/Pods/FirebaseStorage/FirebaseStorage/Sources/StorageDownloadTask.swift

Firebase Core version

3.1.0

Flutter Version

3.22.2

Relevant Log Output

Launching lib/main.dart on iPhone 14 Pro in debug mode...
Running pod install...                                            167.1s
Running Xcode build...                                                  
Xcode build done.                                           400.5s
Failed to build iOS app
Swift Compiler Error (Xcode): Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit
/Users/admin/Desktop/munjiya_ios/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/StorageDownloadTask.swift:127
:13

Swift Compiler Error (Xcode): Reference to property 'pageSize' in closure requires explicit use of 'self' to
make capture semantics explicit
/Users/admin/Desktop/munjiya_ios/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Internal/StorageListTask.swif
t:94:13

Swift Compiler Error (Xcode): Reference to property 'previousPageToken' in closure requires explicit use of
'self' to make capture semantics explicit
/Users/admin/Desktop/munjiya_ios/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Internal/StorageListTask.swif
t:98:13

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

Flutter dependencies

firebase_storage: 12.0.1 firebase_core: 3.1.0 firebase_messaging: 15.0.1

Additional context and comments

No response

Lyokone commented 5 months ago

Hello, which version of XCode are you using?

InShad7 commented 5 months ago

Xcode 14.2 MacOS 12

TarekkMA commented 4 months ago

Hello @InShad7,

Can you upgrade your Xcode to version 15 as per Flutter documentation?

Movement83 commented 4 months ago

hello. did you solve this issue?

InShad7 commented 4 months ago

not by updating the version because i cant be able to update because my macOS version is 12.

but i go through the errors and fix like this

Solution 1: StorageListTask file

   if (self.pageSize != nil) {
        queryParams["maxResults"] = "\(self.pageSize)"
   }

    if (self.previousPageToken != nil) {
        queryParams["pageToken"] = self.previousPageToken
  }

StorageDownloadTask file

 if  (self.fileURL != nil) {
    // Handle file downloads
        fetcher.destinationFileURL = self.fileURL
    fetcher.downloadProgressBlock = { [weak self] (bytesWritten: Int64,
                                                   totalBytesWritten: Int64,
                                                   totalBytesExpectedToWrite: Int64) in
        guard let self = self else { return }
        self.state = .progress
        self.progress.completedUnitCount = totalBytesWritten
        self.progress.totalUnitCount = totalBytesExpectedToWrite
        self.fire(for: .progress, snapshot: self.snapshot)
        self.state = .running
    }
  }

Solution 2:

StorageListTask file

  if let pageSize = self.pageSize {
    queryParams["maxResults"] = "\(pageSize)"
  }

  if let previousPageToken = self.previousPageToken {
    queryParams["pageToken"] = previousPageToken
  }

StorageDownloadTask file

  if let fileURL = self.fileURL {
    // Handle file downloads
    fetcher.destinationFileURL = fileURL
    fetcher.downloadProgressBlock = { [weak self] (bytesWritten: Int64,
                                                   totalBytesWritten: Int64,
                                                   totalBytesExpectedToWrite: Int64) in
        guard let self = self else { return }
        self.state = .progress
        self.progress.completedUnitCount = totalBytesWritten
        self.progress.totalUnitCount = totalBytesExpectedToWrite
        self.fire(for: .progress, snapshot: self.snapshot)
        self.state = .running
    }
  }

after do like this i can build.

Movement83 commented 4 months ago

How about lowering your Firebase storage version? 11.x.x ?

TarekkMA commented 4 months ago

Hello @InShad7, Can you delete your Pods/Podlock file and try again?

cd ios
rm -rf Pods && rm Podfile.lock
pod repo update
cd ..
flutter clean && flutter pub get
InShad7 commented 4 months ago

How about lowering your Firebase storage version? 11.x.x ?

when i lowered the version to 11.6.0 then the code comes like this without changing anything in the file and can compile successfully.

StorageListTask

    if let pageSize = self.pageSize {
      queryParams["maxResults"] = "\(pageSize)"
   }

  if let previousPageToken = self.previousPageToken {
     queryParams["pageToken"] = previousPageToken
  }

StorageDownloadTask

if let fileURL = self.fileURL {
// Handle file downloads
fetcher.destinationFileURL = fileURL
fetcher.downloadProgressBlock = { [weak self] (bytesWritten: Int64,
                                               totalBytesWritten: Int64,
                                               totalBytesExpectedToWrite: Int64) in
    guard let self = self else { return }
    self.state = .progress
    self.progress.completedUnitCount = totalBytesWritten
    self.progress.totalUnitCount = totalBytesExpectedToWrite
    self.fire(for: .progress, snapshot: self.snapshot)
    self.state = .running
}

}

InShad7 commented 4 months ago

Hello @InShad7, Can you delete your Pods/Podlock file and try again?

cd ios
rm -rf Pods && rm Podfile.lock
pod repo update
cd ..
flutter clean && flutter pub get

i tried this but wont change anything. After deleted the file and clean when i run pub get then also the same error within the file.

Lyokone commented 4 months ago

You mention that you are on macOS version 12 and thus unable to update to the latest version. Unfortunately, we will not be able to fix this from our side. You can still use an older version of the firebase_storage to test locally and use a CI tool to compile the app.