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

Not compatible with cocoapods use_frameworks! #3

Closed
rokgregoric opened this issue Dec 9, 2015 · 40 comments
Closed

Not compatible with cocoapods use_frameworks! #3

rokgregoric opened this issue Dec 9, 2015 · 40 comments

Comments

@rokgregoric
Copy link
Contributor

There is a problem with the current integration when using use_frameworks!.

All the needed parameters (search paths, linker flags) are set to the main project (added to the Pods.conf.xcconfig) instead of being set in Segment-GoogleAnalytics.xcconfig

I hope this gets fixed soon .. in the meantime I am using a quick fix at the end of my Podfile:

workDir = Dir.pwd
podDir = "#{workDir}/Pods/Target Support Files"
gaPaths = ["\"${PODS_ROOT}/GoogleAnalytics/Libraries\"", "\"${PODS_ROOT}/GoogleIDFASupport/Libraries\""]
libs = ['-l"sqlite3"', '-l"sqlite3.0"', '-l"GoogleAnalytics"']

post_install do |installer|
  installer.pods_project.build_configurations.each do |conf|
    file = "#{podDir}/Pods/Pods.#{conf.name.downcase}.xcconfig"
    value = File.read(file)
    gaPaths.each do |var|
      value = value.gsub(/#{Regexp.escape(var)}/, "") # remove GA search paths
    end
    (['-l"AdIdAccessLibrary"'] + libs).each do |var| # remove AdIdAccessLibrary + other libs
      value = value.gsub(/#{var} /, "")
    end
    File.open(file, "w") { |file| file << value }
  end

  file = "#{podDir}/Segment-GoogleAnalytics/Segment-GoogleAnalytics.xcconfig"
  value = File.read(file) + "\nLIBRARY_SEARCH_PATHS ="
  gaPaths.each do |var|
    value += " #{var}" # add GA search paths
  end
  value += "\nOTHER_LDFLAGS ="
  (['-weak_framework "CoreData"', '-weak_framework "SystemConfiguration"', '-l"z"'] + libs).each do |var|
    value += " #{var}" # add frameworks + libs
  end
  File.open(file, "w") { |file| file << value }
end
@darkFunction
Copy link

+1

@f2prateek
Copy link
Contributor

Ref: segmentio/analytics-ios#493

It's impossible to use this library with SWIFT and Segment-GoogleAnalytics because the Segment-GoogleAnalytics pod fails to install with this error when you have use_frameworks! set:

[!] The 'Pods-Eyegroove' target has transitive dependencies that include static binaries: (/Users/snibbe/dev/apps/eyegroove-ios-3.0/Pods/GoogleAnalytics/Libraries/libGoogleAnalytics.a and /Users/snibbe/dev/apps/eyegroove-ios-3.0/Pods/GoogleIDFASupport/Libraries/libAdIdAccessLibrary.a)

This seems to be a known error with static dependencies and SWIFT/Podfiles:

CocoaPods/CocoaPods#3194
CocoaPods/CocoaPods#4053
https://code.google.com/p/analytics-issues/issues/detail?id=609

@rokgregoric
Copy link
Contributor Author

Not if you patch your cocoapod implementation to avoid checking for it:

#!/bin/bash

file=`gem which cocoapods/installer`

sed 's/def verify_no_static_framework_transitive_dependencies/&~      return/; y/~/\n/' $file > sed_temp_file
sudo mv sed_temp_file $file

Not saying that's a good way to solve it .. but it's definitely a workaround until it gets fixed.

@snibbe
Copy link

snibbe commented Dec 15, 2015

Hi,
I attempted to build with this patch but we still get link errors:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GAIFields", referenced from:
  objc-class-ref in SEGGoogleAnalyticsIntegration.o
  "_OBJC_CLASS_$_GAIDictionaryBuilder", referenced from:
  objc-class-ref in SEGGoogleAnalyticsIntegration.o
  "_OBJC_CLASS_$_GAI", referenced from:
  objc-class-ref in SEGGoogleAnalyticsIntegration.o
  "_kGAIScreenName", referenced from:
  -[SEGGoogleAnalyticsIntegration screen:] in SEGGoogleAnalyticsIntegration.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@rokgregoric
Copy link
Contributor Author

Did you add the post_install hook to your Podfile?

@snibbe
Copy link

snibbe commented Dec 15, 2015

Yes, there's still a compile-time error in SEGGoogleAnalyticsIntegration.h:

[...]/Pods/Segment-GoogleAnalytics/Pod/Classes/SEGGoogleAnalyticsIntegration.h:3:9: Include of non-modular header inside framework module 'Segment_GoogleAnalytics.SEGGoogleAnalyticsIntegration'

due to #import <GoogleAnalytics/GAI.h>

@rokgregoric
Copy link
Contributor Author

Are you using the latest pod Analytics v3.0.2?

@snibbe
Copy link

snibbe commented Dec 15, 2015

Yes we are using 3.0.2! Thanks for your help.

@luongc86
Copy link

Are you guys using the AnalyticsSwift from segment or just the Segment-GoogleAnalytics pod?

@snibbe
Copy link

snibbe commented Dec 22, 2015

Segment-GoogleAnalytics.

On Dec 22, 2015, at 8:44 AM, luongc86 [email protected] wrote:

Are you guys using the AnalyticsSwift from segment or just the Segment-GoogleAnalytics pod?


Reply to this email directly or view it on GitHub #3 (comment).

@luongc86
Copy link

Gotcha, thanks!

@Katafalkas
Copy link

@rokgregoric

So I am trying to solve this problem but am still missing something.

  1. I did patch the cocoapods implementation with your shellScript.
  2. added post install hook to Podfile

So now I don't get any errors installing 'Analytics', '~> 3.0.4' and 'Segment-GoogleAnalytics', '~> 1.0',
but I cant import Segment_GoogleAnalytics. (Could not build Objective-C module 'Segment_GoogleAnalytics').
I tried adding Bridging-Header but #import <Segment-GoogleAnalytics/SEGGoogleAnalyticsIntegration.h> or variations of this - do not work.

I am still quite new to this, what am I missing ? :)

@rokgregoric
Copy link
Contributor Author

@Katafalkas not sure if that's the same problem I had .. but I had to patch Segment-GoogleAnalytics .. try using:
pod 'Segment-GoogleAnalytics', :git => 'https://github.com/rokgregoric/analytics-ios-integration-google-analytics.git'

@dmorrow
Copy link

dmorrow commented Jan 11, 2016

I am having a similar issue, [!] The 'Pods-<project-name>' target has transitive dependencies that include static binaries: (.../Pods/GoogleAnalytics/Libraries/libGoogleAnalytics.a and .../Pods/GoogleIDFASupport/Libraries/libAdIdAccessLibrary.a).

@rokgregoric fix doesn't solve this issue.

The Podfile looks like this (with workspace and xcodeproj names removed)

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'
use_frameworks!

workspace '***'
xcodeproj '***'

target :*** do
    pod 'GoogleAds-IMA-iOS-SDK', '~> 3.1.0'
    pod 'Alamofire', '~>3'
    pod 'AlamofireImage', '~>2'
    pod 'Analytics'
    pod 'Segment-Branch'
    pod 'Segment-GoogleAnalytics'
    pod 'Segment-Mixpanel'
end

@rokgregoric
Copy link
Contributor Author

@dmorrow try using:
pod 'Segment-GoogleAnalytics', :git => 'https://github.com/rokgregoric/analytics-ios-integration-google-analytics.git'

@dmorrow
Copy link

dmorrow commented Jan 11, 2016

@rokgregoric Thanks for the suggestion, but I get the same error:

[!] The 'Pods-<project-name>' target has transitive dependencies that include static binaries: (.../Pods/GoogleAnalytics/Libraries/libGoogleAnalytics.a and.../Pods/GoogleIDFASupport/Libraries/libAdIdAccessLibrary.a)

@rokgregoric
Copy link
Contributor Author

You need to patch cocoapods. Follow the instructions above.

@lukecharman
Copy link

Still seeing the exact same error as @dmorrow here, with the patch above.

@rokgregoric
Copy link
Contributor Author

@lukecharman
you need to patch your cocoapods installer:

#!/bin/bash

file=`gem which cocoapods/installer`

sed 's/def verify_no_static_framework_transitive_dependencies/&~      return/; y/~/\n/' $file > sed_temp_file
sudo mv sed_temp_file $file

you can do it manually as well .. just comment out verify_no_static_framework_transitive_dependencies

@lukecharman
Copy link

Alright, thank you, I'll give that a try!

@glyuck
Copy link

glyuck commented Feb 5, 2016

Ok, to sum it up:

  1. You'll need to append script from first @rokgregoric comment to the end of your Podfile

  2. Reference patched pod in your Podfile:

    pod 'Segment-GoogleAnalytics', :git => 'https://github.com/rokgregoric/analytics-ios-integration-google-analytics.git'
    
  3. Use patched cocoapods (with disabled static transitive dependencies check):

    1. In project root create file Gemfile with the following content:

      source 'https://rubygems.org'
      gem 'cocoapods', git: 'https://github.com/glyuck/CocoaPods.git', ref: '7f3a205'
      
    2. Run in terminal sudo gem install bundler

    3. Run in terminal bundle install

    4. And from now on install pods with this command: bundle exec pod install

Thanks, @rokgregoric, you saved me hours of time.

EDIT: Instead of patched version cocoapods v0.39.0 you can use cocoapods v1.0.0 (gem install cocoapods --pre or add to Gemfile gem 'cocoapods', git: '[email protected]:CocoaPods/CocoaPods.git', tag: '1.0.0.beta.3')

EDIT2: For cocoapods v1.0.0.beta3 you can use gem 'cocoapods', git: 'https://github.com/glyuck/CocoaPods.git', ref: '3b57c53'

@rokgregoric
Copy link
Contributor Author

@glyuck you are welcome.

@dougbankspersonal
Copy link

When I try to run 'bundle install' I get the following error:

Please make sure you have the correct access rights
and the repository exists.
Retrying git clone '[email protected]:glyuck/CocoaPods.git' "/Users/douglasbanks/zeemeesrc/zeemee-ios/ZeeMeeApp/vendor/cache/bundler/git/CocoaPods-9d441d3873edb3e1c61370d0fd108712021d9169" --bare --no-hardlinks --quiet due to error (3/4): Bundler::Source::Git::GitCommandError Git error: command `git clone '[email protected]:glyuck/CocoaPods.git' "/Users/douglasbanks/zeemeesrc/zeemee-ios/ZeeMeeApp/vendor/cache/bundler/git/CocoaPods-9d441d3873edb3e1c61370d0fd108712021d9169" --bare --no-hardlinks --quiet` in directory /Users/douglasbanks/zeemeesrc/zeemee-ios/ZeeMeeApp has failed.
Permission denied (publickey).
fatal: Could not read from remote repository.

@glyuck
Copy link

glyuck commented Feb 17, 2016

@dougbankspersonal updated my comment to use HTTPS URLs instead or SSH: https://github.com/glyuck/CocoaPods.git

@NathanWalker
Copy link

Any updates here on final resolution? The workarounds work but definitely not the best situation.

@ladanazita
Copy link
Contributor

Hi Nathan,

Looking into it today - I will update you all as soon as I have more!

@f2prateek
Copy link
Contributor

There is still no resolution (other than the workarounds posted here) until either CocoaPods relaxes restriction on having a transitive dependency that is a static library (CocoaPods/CocoaPods#3194 (comment)), or GA ships a dynamic framework.

@f2prateek
Copy link
Contributor

To clarify, this only affects you if you are using use_frameworks! in your Podfile. There are a few options at this point if you are using use_frameworks!:

  1. Use GA server side.
  2. Copy the integration code into your project Not compatible with cocoapods use_frameworks! #3 (comment)
  3. Try one of the other workarounds in this thread (Not compatible with cocoapods use_frameworks! #3 (comment))

You can also try asking CocoaPods to relax their requirement, or ask Google to ship a dynamic framework. If there are any suggestions as to how we can ship a solution in our library, please send a PR or open a new issue to discuss the approach, thanks!

@f2prateek
Copy link
Contributor

f2prateek commented Apr 4, 2016

Also another solution (by the way of orta/ARAnalytics#218 (comment)) would be to copy the integration code (these files) manually into your project. Then depend on Google Analytics directly.

Instead of importing the integration from our library, then you would import the integration from your local copy.

This eliminates the transitive dependency (from App -> Segment-GoogleAnalytics -> GA to App -> GA).

@joenoon
Copy link

joenoon commented Apr 14, 2016

Just in case this helps anyone, here is what seems to work for me, and doesn't require changing anything outside of the Podfile:

Podfile:

# this noops the method at runtime
Pod::Installer.class_eval { def verify_no_static_framework_transitive_dependencies; end }

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.build_settings['PRODUCT_NAME'] == "Segment_GoogleAnalytics"
        config.build_settings['LIBRARY_SEARCH_PATHS'] = ["$(inherited)", "$(PODS_ROOT)/GoogleAnalytics/Libraries", "$(PODS_ROOT)/GoogleIDFASupport/Libraries"]
        config.build_settings['OTHER_LDFLAGS'] = %Q{-weak_framework "CoreData" -weak_framework "SystemConfiguration" -l"z" -l"sqlite3" -l"sqlite3.0" -l"GoogleAnalytics"}
      end
    end
  end
end

@hankim813
Copy link

can @segment-integrations/mobile add working solutions to the Google Analytics docs? 🙏

@jessepollak
Copy link

+1 to adding the solution @joenoon posted to the docs, would save future people hours :)

@dmorrow
Copy link

dmorrow commented May 12, 2016

Not sure if this is related, but just installed Cocoapods 1.0.0 and now getting Include of non-modular header inside framework module https://github.com/segment-integrations/analytics-ios-integration-google-analytics/issues/9

@dmorrow
Copy link

dmorrow commented May 17, 2016

@joenoon We are using your solution, but get a crash when tracking starts in the app - [GAI sharedInstance] triggers a crash with EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

@joenoon
Copy link

joenoon commented May 17, 2016

@dmorrow I'm not crashing with:

#import <GoogleAnalytics/GAI.h>
...
[GAI sharedInstance];

So I'm not sure what it could be :/

@dmorrow
Copy link

dmorrow commented May 18, 2016

@joenoon I think we exposed a multithreading bug in GAI. You are correct, I can call [GAI sharedInstance] from the main thread without a problem - in fact I already was. When removing this call, the Segment Integration went back to not crashing. Segment calls this method on a background thread.

@mobileprogrammingAnurag

@joenoon , i did this but it's give me duplicate symbol error ., even there is nothing like that

@ladanazita
Copy link
Contributor

Hi all,

I've added our supported work around to our docs:
https://segment.com/docs/integrations/google-analytics/#target-has-transitive-dependencies-that-include-static-binaries

I would suggest follow this for now as we have tested it and can confirm/support that this works. Let me know if you have any questions!

@GabrielMassana
Copy link

It looks like the workaround is going to be forever.

@f2prateek
Copy link
Contributor

f2prateek commented Nov 9, 2016

As of #14, you can use:

pod 'GoogleAnalytics'
pod 'Segment-GoogleAnalytics/StaticLibWorkaround'

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