CodeMinion / another_brother

Another Brother Flutter SDK
BSD 3-Clause "New" or "Revised" License
21 stars 20 forks source link

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

Open BentEngbers opened 2 years ago

BentEngbers commented 2 years ago

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 commented 2 years ago

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: https://github.com/CodeMinion/another_brother/issues/8#issuecomment-873489374 ) 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 commented 2 years ago

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

CodeMinion commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

Hi @CodeMinion,

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

Thanks in advance!

leijdekkers commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

Hi @mikhael28 ,

Thanks for the question on this. As mentioned previously in this thread (https://github.com/CodeMinion/another_brother/issues/10#issuecomment-921837394) 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 commented 1 year ago

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

mikhael28 commented 11 months ago

@BentEngbers you can refer to this for a workaround of sorts https://github.com/CodeMinion/another_brother/issues/70

koldoon commented 7 months ago

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

mikhael28 commented 7 months ago

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

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

koldoon commented 7 months ago

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

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

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

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

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

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