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

automatically set the target membership from libBROTHERSDK.a to another_brother using COCOAPODS. #10

Open
BentEngbers opened this issue Sep 17, 2021 · 20 comments

Comments

@BentEngbers
Copy link

Hi @CodeMinion, Thanks for this awesome flutter library!
I had a lot of issues with manually setting the target membership from libBROTHERSDK.a to another_brother.
So I added the following script inside the post_install part of the the podFile, to do it automatically!
(i modified it from here https://stackoverflow.com/a/61392674/15175952)

#post install used to set target membership from libBROTHERSDK.a to flutter library another_brother
  puts("Attempting to add libBROTHERSDK.a reference to another_brother.")
  installer.pods_project.targets.each do |target|
    if target.name  == "another_brother"
      puts("Found another_brother target.")
      all_filerefs = installer.pods_project.files
      all_filerefs.each do |fileref|
         if fileref.path.end_with? "libBROTHERSDK.a"
          puts("Found libBROTHERSDK.a fileref.")
          build_phase = target.frameworks_build_phase
          puts("Determining if another_brother build phase needs correction.")
          unless build_phase.files_references.include?(fileref)
            puts("Adding libBROTHERSDK.a to another_brother target")
            build_phase.add_file_reference(fileref)
          end
         end
      end
    end
  end

The whole post_install now looks like this:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
  #post install used to set target membership from libBROTHERSDK.a to flutter library another_brother
  puts("Attempting to add libBROTHERSDK.a reference to another_brother.")
  installer.pods_project.targets.each do |target|
    if target.name  == "another_brother"
      puts("Found another_brother target.")
      all_filerefs = installer.pods_project.files
      all_filerefs.each do |fileref|
         if fileref.path.end_with? "libBROTHERSDK.a"
          puts("Found libBROTHERSDK.a fileref.")
          build_phase = target.frameworks_build_phase
          puts("Determining if another_brother build phase needs correction.")
          unless build_phase.files_references.include?(fileref)
            puts("Adding libBROTHERSDK.a to another_brother target")
            build_phase.add_file_reference(fileref)
          end
         end
      end
    end
  end
end

Maybe you could add this to the documentation of this library?

@CodeMinion
Copy link
Owner

Hi @BentEngbers ,

Glad to hear you like another_brother and thank you for the update for the libBROTHERSDK install! I'll take a closer look at the changes once I have some time this weekend and will make the update.

Note: If you are planning on releasing to the Apple Store, you probably want to use the the ios-no-type-b branch instead of the official pub.dev (See here for more info: #8 (comment) ) as it turns out the libBROTHERSDK.a does not meet the restrictions.

libBROTHERSDK.a is only used for TypeB printers like RJ-2055WB (https://www.brother-usa.com/products/rj2055wb) so if you don't plan to target those printers and are planning to release to the store you can safely use the branch.

Thanks again for the update and please don't hesitate to reach out if you run into any other issues or have any questions.

@BentEngbers
Copy link
Author

Thanks for the info!
I will use the ios-no-type-b branch from now on!

@CodeMinion
Copy link
Owner

Hi @BentEngbers ,

Thanks again for the script update. I gave it a try and it does in fact mark the membership however when I try to build the project it fails with the following error:

ld: library not found for -lBROTHERSDK

Reverting back to the default version and manually selecting the membership allows it to build correctly. Seems it will required a bit more investigation but definitely on the right track.

I'll leave this issue open for now and post any findings.

Thanks again!

@BentEngbers
Copy link
Author

BentEngbers commented Jun 7, 2022

Hi @CodeMinion,

Could the ios-no-type-b branch be updated with the latest changes from main?
I tried to create the PR myself, but i lack the permissions.

@CodeMinion
Copy link
Owner

Hey @BentEngbers !

Thanks for reaching out about this. I believe the only changes that came in recently are the additional permissions in the manifest. I'll add those in the ios-no-type-b branch later this weekend.

That said if you would like to make that change and submit a PR before then it will definitely be welcomed!

Thanks again!

@BentEngbers
Copy link
Author

Hi @CodeMinion,

Could you update the ios-no-type-b branch again with the latest changes from main?

Thanks in advance!

@leijdekkers
Copy link

@BentEngbers
Hi Bent, I am trying your 'pod install' script for adding the target membership and that works. However i do get the same error as CodeMinion, saying it cannot find the library "ld: library not found for -lBROTHERSDK"

Did you ever solve that issue? I am running the code on a CI/CD server which does a fresh " pod install" each time.

Thanks Peter

@mikhael28
Copy link

I can confirm this issue is happening as well - in my CI/CD server, this is more or less breaking the iOS pipeline.

@CodeMinion is the libBROTHERSDK.a strictly necessary - what about it is indispensable for the package? If I literally only want to use QL1110NWBc, can I strip it out?

@CodeMinion
Copy link
Owner

Hi @mikhael28 ,

Thanks for the question on this. As mentioned previously in this thread (#10 (comment)) that library is for support of the Type-B printers.

If you are not looking to use a Type-B printer at all, then the recommended approach is to use the ios-no-type-b branch.

Thanks again,

@mikhael28
Copy link

I will take a look at the ios no type b branch!

@mikhael28
Copy link

@BentEngbers you can refer to this for a workaround of sorts #70

@koldoon
Copy link

koldoon commented Jan 23, 2024

Same issue, ios pipeline is broken and no workarounds seem to work for me. Any ideas how to solve this "the right way"?

@mikhael28
Copy link

@koldoon I think the issue is that the Another Brother packages don't support arm64 virtualization - otherwise, you should be able to programatically link them using something like this in the Podfile. Perhaps it's worth taking a look at newer versions of the Brother SDK, to see if that is now supported on iOS?

if target.name == 'another_brother'
      puts('Found another brother target')
      
      all_filerefs = installer.pods_project.files
      all_filerefs.each do |fileref|
        if fileref.path.include? "BROTHERSDK.h" 
          if (fileref != "libBROTHERSDK.h")
            build_phase = target.frameworks_build_phase
            unless build_phase.files_references.include?(fileref)
              puts("____________________________________")
              puts(fileref)
              build_phase.add_file_reference(fileref)
            end
          end
        end
        if fileref.path.end_with? "libBROTHERSDK.a"
          build_phase = target.frameworks_build_phase
          unless build_phase.files_references.include?(fileref)
            puts("____________________________________")
            puts(fileref)
            build_phase.add_file_reference(fileref)
          end
         end
        end
      end

@mikhael28
Copy link

@CodeMinion any word on updated drivers from Brother potentially fixing this issue?

@koldoon
Copy link

koldoon commented Jan 25, 2024

@mikhael28 Using similar scripts in podfile I indeed get that check set (another_brother membership) but still have build issues: it says that lib BROTHERSDK is not found. If I re-set that check manually in XCode - everything works fine if I build in XCode and if I build using flutter tools. BUT, that option is not being saved in xproject configuration file! i don't know actually where it is being saved, so that when I try to build project in azure CI/CD pipelines I got all same errors.

@mikhael28
Copy link

@koldoon yeah, I think you are getting close. How can we save that option in the xproject configuration file. Maybe if you unblock all the config in the .gitignore, you can see allllll the config changes that are being made? Right now, lots of stuff is being hidden I would imagine by our gitignore options.

@savs90
Copy link

savs90 commented Feb 6, 2024

Hey guys, I made some tweaks and it works for me now. Maybe you can also try to give some feedback if it works for you too:

puts("Attempting to add libBROTHERSDK.a reference to another_brother.")
  installer.pods_project.targets.each do |target|
    if target.name  == "another_brother"
      puts("Found another_brother target.")
      all_filerefs = installer.pods_project.files
      all_filerefs.each do |fileref|
        if fileref.path.end_with? "libBROTHERSDK.a"
          puts("Found libBROTHERSDK.a fileref.")
          build_phase = target.frameworks_build_phase
          puts("Determining if another_brother build phase needs correction.")
          unless build_phase.files_references.include?(fileref)
            puts("Adding libBROTHERSDK.a to another_brother target")
            build_phase.add_file_reference(fileref)
          end
        end        
        if fileref.path.end_with? "BROTHERSDK.h"
          puts("Found BROTHERSDK.h fileref.")
          build_phase = target.headers_build_phase
          puts("Determining if another_brother build phase needs correction.")
          unless build_phase.files_references.include?(fileref)
            puts("Adding BROTHERSDK.h to another_brother target")
            build_file = build_phase.add_file_reference(fileref)
          end
        end
      end
      puts("Adding paths for the library build")
      target.build_configurations.each do |config|
        config.build_settings["LIBRARY_SEARCH_PATHS"] = ["$(inherited)", "$(PROJECT_DIR)/BROTHERSDK/BROTHERSDK"]
      end
    end
  end

@leijdekkers
Copy link

Yes it works!! I added your script and forced a pod install in Android Studio and rebuild the ios project. Also unchecked the Target Membership in Xcode to be sure the script would do its job! It adds it now automatically!

Great job!

Thanks a lot!

@chensjlv
Copy link

chensjlv commented Feb 26, 2024

Hey guys, I made some tweaks and it works for me now. Maybe you can also try to give some feedback if it works for you too:

puts("Attempting to add libBROTHERSDK.a reference to another_brother.")
  installer.pods_project.targets.each do |target|
    if target.name  == "another_brother"
      puts("Found another_brother target.")
      all_filerefs = installer.pods_project.files
      all_filerefs.each do |fileref|
        if fileref.path.end_with? "libBROTHERSDK.a"
          puts("Found libBROTHERSDK.a fileref.")
          build_phase = target.frameworks_build_phase
          puts("Determining if another_brother build phase needs correction.")
          unless build_phase.files_references.include?(fileref)
            puts("Adding libBROTHERSDK.a to another_brother target")
            build_phase.add_file_reference(fileref)
          end
        end        
        if fileref.path.end_with? "BROTHERSDK.h"
          puts("Found BROTHERSDK.h fileref.")
          build_phase = target.headers_build_phase
          puts("Determining if another_brother build phase needs correction.")
          unless build_phase.files_references.include?(fileref)
            puts("Adding BROTHERSDK.h to another_brother target")
            build_file = build_phase.add_file_reference(fileref)
          end
        end
      end
      puts("Adding paths for the library build")
      target.build_configurations.each do |config|
        config.build_settings["LIBRARY_SEARCH_PATHS"] = ["$(inherited)", "$(PROJECT_DIR)/BROTHERSDK/BROTHERSDK"]
      end
    end
  end

I can verify this works for us too. Great job!

@mikhael28
Copy link

@savs90 you are a legend! @CodeMinion you can likely add this to the official documentation, and close some of these issues!

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

No branches or pull requests

7 participants