ReactiveX / RxSwift

Reactive Programming in Swift
MIT License
24.39k stars 4.17k forks source link

Problem in my framework which based RxSwift #2375

Closed Blackvision2021 closed 3 years ago

Blackvision2021 commented 3 years ago

Short description of the issue:

I'm developing a swift framework that depends on RxSwift, it works well when debug, so I package it (fastlane -> carthage) and upload to cocoapods. Then I create a new Project and try my framework by cocoapods. However it crash At

RxSwift.PublishSubject line 93:
self.lock.performLocked { self.synchronized_subscribe(observer) }    ⚠️Thread 1: signal SIGABRT

Expected outcome:

It can run well with framework

What actually happens:

It crash

Self contained code example that reproduces the issue:

I try a simple code and It also can not run well

  code goes here

import UIKit
import RxSwift
import RxCocoa

public class BVTestView: UIView {
    var roomData: PublishSubject<Int> = PublishSubject()
    var mapViewW: PublishSubject<CGFloat> = PublishSubject<CGFloat>()
    var mapViewH: PublishSubject<CGFloat> = PublishSubject<CGFloat>()
    private let disposeBag: DisposeBag = DisposeBag.init()
    public init() {
        super.init(frame: .zero)
        initView()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initView() {
        self.backgroundColor = .red
        Observable.zip(mapViewW, mapViewH, roomData)
            .subscribe { (width, height, data) in
                print("\(width) == \(height) == \(data)")
            }
            .disposed(by: disposeBag)
    }
}

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

  pod 'RxSwift', '6.2.0'
  pod 'RxCocoa', '6.2.0'
  pod 'RxRelay', '6.2.0'

Platform/Environment

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

Xcode version:

  Xcode 13.0

Installation method:

I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)

Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)

Blackvision2021 commented 3 years ago

I run

po self.lock

in terminal when it crash

just this:

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=2, address=0x11a0080000).
The process has been returned to the state before expression evaluation.
freak4pc commented 3 years ago

Hey, Don't think we'll be able to help without a fully reproducible example here.

But, generally it sounds related to something with Carthage or some configuration and it's not something we directly support unless there's a more widespread issue.

Blackvision2021 commented 3 years ago

Hey, Don't think we'll be able to help without a fully reproducible example here.

But, generally it sounds related to something with Carthage or some configuration and it's not something we directly support unless there's a more widespread issue.

@freak4pc Thanks,

you can pod my framework by

pod 'BVHttp', '0.1.6'

and try it in viewController

import BVHttp

...

let testView = BVTestView.init()
testView.frame = CGRect.init(x: 0, y: 0, width: 375, height: 375)
self.view.addSubview(testView)

and run to this viewController.

Or

there are my detailed steps : first,create a project ,choose framework, and add RxSwift by cocoapods. second, create a new file just like this:

import UIKit
import RxSwift
import RxCocoa

public class BVTestView: UIView {
    var roomData: PublishSubject<Int> = PublishSubject()
    var mapViewW: PublishSubject<CGFloat> = PublishSubject<CGFloat>()
    var mapViewH: PublishSubject<CGFloat> = PublishSubject<CGFloat>()
    private let disposeBag: DisposeBag = DisposeBag.init()
    public init() {
        super.init(frame: .zero)
        initView()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initView() {
        self.backgroundColor = .red

        Observable.zip(mapViewW, mapViewH, roomData)
            .subscribe { (width, height, data) in
                print("\(width) == \(height) == \(data)")
            }
            .disposed(by: disposeBag)
    }
    public func test() {
        roomData.onNext(1)
        mapViewW.onNext(1)
        mapViewH.onNext(1)
    }
}

third, modify configuration: Build Settings -> Excluded Architectures -> Release, add key 'Any iOS Simulator SDK' and value 'arm64', then,package by fastlane, there is my script:

lane :build do
    carthage(
      command: "build",
      no_skip_current: true,
      platform: "all",
      configuration: "Release",
      use_xcframeworks: false
      )
  end

then, zip my framework and upload to cocoapods, the podspec is :

  s.name         = "BVHttp"
  s.version      = "0.1.6"
  s.summary      = "A short description of BVHttp."
  s.description  = "BVHttp"
  s.homepage     = "http://EXAMPLE/BVHttp"
  s.license      = "MIT"
  s.author             = { "Tian" => "tianyu@blackvision.net" }
  s.source       = { :http => "https://app.heimouyun.com/sdk/ios/#{s.name}-#{s.version}.zip", :type => "zip" }

  s.swift_versions = '5.0'
  s.ios.deployment_target = '11.0'
  s.vendored_frameworks = 'lib/*.framework'
  s.pod_target_xcconfig = { 'VALID_ARCHS' => 'x86_64 armv7 arm64' }
  s.requires_arc = true

  s.dependency "Alamofire", "5.4.4"
  s.dependency 'RxSwift', '6.2.0'
  s.dependency 'RxCocoa', '6.2.0'
  s.dependency 'RxRelay', '6.2.0'
  s.dependency 'GZIP', '1.3.0'
  s.dependency 'SnapKit', '5.0.1'
  s.dependency 'SwiftyJSON', '5.0.1'

at last, create a new project and pod my framwork, then try this 'BVTestView'

That's all, thanks again, look forward to your reply

freak4pc commented 3 years ago

Hey, I'm sorry to be the bearer of bad news here - but if the project works fine when running before packaging it with fastlane, this is an archiving/configuration issue, and that's unfortunately out-of-scope to the support we provide here.

If this was an issue specific to RxSwift (not just to your specific configuration) it would've been easier to look at but otherwise it's a bit tricky, I'm not too sure I can help beyond this.

Blackvision2021 commented 3 years ago

Hey, I'm sorry to be the bearer of bad news here - but if the project works fine when running before packaging it with fastlane, this is an archiving/configuration issue, and that's unfortunately out-of-scope to the support we provide here.

If this was an issue specific to RxSwift (not just to your specific configuration) it would've been easier to look at but otherwise it's a bit tricky, I'm not too sure I can help beyond this.

@freak4pc Hi, have you tried my case? is it run well in your side? I remove all other pods, leaving only 'RxSwift', 'RxCocoa', 'RxRelay' and try again, it also crash('BVHttp', '0.1.8').

This framework is very important to me, can you teach me how to configure my project and how to archive a framework based on RxSwift? Any specific configuration?

danielt1263 commented 3 years ago

I tried including the 'BVHTTP' pod in a project through cocoapods. The project ran.

Blackvision2021 commented 3 years ago

I tried including the 'BVHTTP' pod in a project through cocoapods. The project ran.

@danielt1263 Hi, have you tried 'BVTestView' like this?

let testView = BVTestView.init()
testView.frame = CGRect.init(x: 0, y: 0, width: 375, height: 375)
self.view.addSubview(testView)

and see a red view ?

danielt1263 commented 3 years ago

No I did not. I had no idea that I should try that. I have tried it now and the code crashes. Since the pod doesn't include any code, only a framework, I am unable to help determine the problem.

Blackvision2021 commented 3 years ago

No I did not. I had no idea that I should try that. I have tried it now and the code crashes. Since the pod doesn't include any code, only a framework, I am unable to help determine the problem.

@danielt1263 Hi, sorry about that I can not show you the project, but all about the way to archive the framework is on above, include the code, you can try it by yourself, it's very simple, just one file.

danielt1263 commented 3 years ago

Sorry. I don't know enough about how to setup a CocoaPod to be of use. Nor do I know anything about Fastlane or Carthage.

freak4pc commented 3 years ago

I'm sorry @Blackvsion - this is a bit out of scope or a RxSwift GitHub issue. I suggest joining our slack and trying to find help there. http://slack.rxswift.org

Blackvision2021 commented 3 years ago

Sorry. I don't know enough about how to setup a CocoaPod to be of use. Nor do I know anything about Fastlane or Carthage.

@danielt1263 It doesn't matter. Anyway, thanks bro.