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
0.38.0 beta causing Pods compilation error with Extension only methods #3794
Comments
Unfortunately, I don't think either solution would work, because toolchain issues with having duplicated frameworks between application and extension targets were one of the reasons for doing the deduplication in the first place. So I think it is really the case that you won't be able to use any APIs beyond |
@neonichu is correct here. |
@neonichu I'm sorry but I don't understand 😕 Once 0.38.0 goes live, everybody using AFNetworking and App Extensions (a fair amount of people I would guess) is going to encounter this issue. And if they are using AFNetworking extension-forbidden methods, it's going to make matters worse. What is the solution that the CP team suggests? |
@hartbit AFAIK, this is already broken with 0.37, apps couldn't be successfully archived if app and extension both used the same framework, e.g. AFNetworking. This seems to be an Xcode limitation, so the only solution we can recommend for now is to not use any extension unsafe methods and go with the post-install hook which sets |
I just don't think this is true - I, like the original poster, was using 0.37.2 with AFNetworking and a Today widget with a similar
So the official stance is that this is now broken and there is no workaround in the 0.38.x version of CocoaPods? This is a major issue for me. |
@rwickliffe Interesting, can you share your podfile for that project? Generally, we have seen a lot of people having problems with archiving or even building apps with duplicated frameworks, so the default clearly has to be to deduplicate. You still have the option to opt out of that and get the old behaviour, see https://github.com/CocoaPods/CocoaPods/blob/master/CHANGELOG.md#highlighted-enhancement-that-needs-testing |
@neonichu You are, of course, correct regarding Here is my current podfile - I believe that
|
I should also add that the
|
@rwickliffe Thanks, I totally overlooked that bit and yes, that explains it. This is why it works for you, the archive/build problems only occur when using frameworks integration. Maybe we could not deduplicate when using static library integration? @mrackwitz what do you think? |
Thanks @rwickliffe for weighting in. Let me see if I can summarise. If I understand correctly, there are two un-related problems:
The solutions are:
What do you think? |
Re 2: disabling duplication for framework integration actually doesn't work in practice, as stated above, so I wouldn't count this as a con. Apart from that, this is a good summary of the situation. Personally, I'm leaning towards 1, because it feels like a special case to me, but we'd obviously need to reconsider if a lot of people actually need to manually opt-out. |
I think I may have a workaround by setting use_frameworks only for the extension (which is iOS8 minimum version anyway). This seems to force the deduplication off in this case. I need to do more checking later but I thought it might be useful to suggest quickly in case others want to explore too. |
@josephlord True, that's another workaround, thanks for mentioning it. |
Just adding So this doesn't disable the deduplication for the extension target and Xcode is still not able to build my project without using IMO this problem is not a rare 'special case' because it affects every project with an extension that uses AFNetworking. Edit: I think a Podfile level setting that allows to opt-out the deduplication (like suggested by @hartbit) would be a good way. |
@andi357 that sounds like a bug, though. What kind of integration does the one target you end up with use, static library or framework? |
@neonichu It's a framework then. |
@neonichu And BTW the framework's target is just named |
Considering that I cannot put |
Speaking of static library integration. How about a setting to opt-out of deduplication per pod target? I think it's okay to generally deduplicate the targets, but if there are targets that need to be separate, an option would be great. Or is this something that can't be mixed up? |
@tanis2000: If dependencies use different forms of integration, they should not be deduplicated, but built once as library and once as framework. I think you're bringing up here again a different issue than the one you originally described over in #3550, which was just the same as here originally described by @hartbit or am I missing a point? Feel free to open up a separate issue to elaborate on your new issue. |
@mrackwitz I'd rather deduplicate than open up a new can of worms trying to have both a static library and a framework when I'm sure that some of the pods I'm already using do not support being compiled into a framework. For the time being I opted to use the config.yaml solution until something better is available as I cannot stop the development of the app just because of this issue. But that's not really a solution IMHO, it's more of a workaround as it means that all of my projects will be deduplicated, even those that would rather benefit from deduplication. |
Oh, this is something I didn't realize... you have to set up |
@MuscleRumble: Yes, it's a system-wide setting. So your proposal would go beyond that. pre_install do |installer|
pod_targets = installer.pods_project.pod_targets.flat_map do |pod_target|
pod_target.name == "foo" ? pod_target.scoped : pod_target
end
pod_targets_by_target_definition = pod_targets.group_by(&:target_definition)
installer.pods_project.aggregate_targets.each do |target|
target.pod_targets = pod_targets_by_target_definition[target.target_definition]
end
end |
If that's possible, that would be great! There are some small typos in your suggestion and I'm not familiar with Ruby, but I tried to fix them and ended up with this (using this documentation): Edit: Yeah, this isn't fixed at all, see two posts below this one. pre_install do |installer|
pod_targets = installer.pod_targets.flat_map do |pod_target|
pod_target.name == "foo" ? pod_target.scoped : pod_target
end
pod_targets_by_target_definition = pod_targets.group_by(&:target_definitions)
installer.aggregate_targets.each do |target|
target.pod_targets = pod_targets_by_target_definition[target.target_definition]
end
end But I'm getting this error:
Any idea? |
where you reference |
Sorry, as I said I'm not familiar with Ruby and its documentation, haha. Didn't see it inherits from
|
Same problem on my project. I solved it the 'brutal' way by removing the de-duplicate option (deduplicate_targets: false)... I hope another solution will be found. |
Sorry, my fault! pre_install do |installer|
pod_targets = installer.pod_targets.flat_map do |pod_target|
pod_target.name == "foo" ? pod_target.scoped : pod_target
end
installer.aggregate_targets.each do |aggregate_target|
aggregate_target.pod_targets = pod_targets.select do |pod_target|
pod_target.target_definitions.include?(aggregate_target.target_definition)
end
end
end |
Thanks, it works! I think I'm quite happy with this, even if it looks like a hack. xD Should be documented somewhere. There is btw just a small error in Follow-up question, just to make sure if there is better syntax: How would you do that for multiple pods? So if you have "foo" und "bar"? Is there a more elegant way than |
@MuscleRumble:
Fixed it above.
If it's something what turns out to be really needed in general long-term, it should be rather part of the Podfile-DSL. |
This is still a problem evidently in 0.39.0. I downloaded this project: https://github.com/Ruenzuo/ios-facade-example.git I've never used cocoapods before, so I did sudo ruby gem install cocoapods. Then I cd into /usr/local/src/ios-facade-example/ and ran the pod install. First it says "project" cannot be found and another thread said to change this to "pods_project". So I did that. Then it dies on this error:
Yeah so. It's broken. You guys, I have to say real bluntly, because I've never used cocoapods before, but isn't the whole point of cocoapods, to avoid crap like this? I mean honestly, if you can't manage to make it retain backwards compatibility with older projects then what are you even doing? Why can't it auto-detect when there is an error like this using proper exception handling, and then take some alternate steps to resolve the issue internally in the code? Rather than just break everyone's projects? If it's going to be like this then people might as well not even use cocoapods, because now the dependencies must be manually installed since cocoapods is broken for the project. BTW -- Yes, I was able to fix it by going into ~/.cocoapods/config.yaml and adding "deduplicate_targets: false" but, my point is, should not have to do that. The software should be able to automatically set deduplicate_targets: false anytime it encounters this exception, the re-run the command and succeed. So people don't have to google the error and sift through 10 github comment threads to fix it. |
This worked for me for that linked project, which is 2 years old:
Note that this also required an update to AFNetworking: This will get you to the point that you can see all the additional warnings you'd expect from an example project that is 2 years old. From semver.org:
|
@mrackwitz Your pre-install hook worked until some recent 1.0.0 update (I believe 1.0.0.beta.3 still worked, but I'm not 100% certain). I'm now getting the error:
Any idea how to solve this? Maybe some variable names have changed? Edit: Quick reminder. This is the pre-install hook I'm referring to: pre_install do |installer|
pod_targets = installer.pod_targets.flat_map do |pod_target|
pod_target.name == "foo" ? pod_target.scoped : pod_target
end
installer.aggregate_targets.each do |aggregate_target|
aggregate_target.pod_targets = pod_targets.select do |pod_target|
pod_target.target_definitions.include?(aggregate_target.target_definition)
end
end
end Edit2: It's important to me that I'm able to deactivate deduplication of specific Pods, because I need to set some preprocessor macros on App Extension targets. If there's a cleaner syntax for it or if I have to deduplicate all Pods, I guess I could do so, even though it's not as elegant as before. |
@tobihagemann did you ever fix your error? I have the same error.
|
Unfortunately, I haven't. The method I've used won't be supported anymore, that's why I don't know if a fix even exists. You have to use subspecs now, as suggested here: #5373 (comment) Didn't get the chance to try subspecs out myself yet. It's kind of sad, I'm still using 1.0.0.beta.3. 😅 I didn't lie that I think using subspecs is the way to go, but I didn't mange to find the time and nerves to actually change my setup! 😉 |
I'm using 0.38.0-beta2 and found a potential bug because of target de-duplication #3550.
Problem
One of our projects has a Podfile that is based on this structure:
The
post_install
made sure that pod targets that belong to extension targets had the correct defines thatAFNetworking
requires to pre-process out methods that are not available in extensions. That was necessary because CocoaPods hadAPPLICATION_EXTENSION_API_ONLY
enabled for pod targets that belong to project extension targets.Since CocoaPods 0.38.0-beta1,
AFNetworking
pod targets in this project have been de-duplicated, and the one target hasAPPLICATION_EXTENSION_API_ONLY
enabled. This has two serious consequences:AF_APP_EXTENSIONS
define to this target.post_install
to add the define to all targets that haveAPPLICATION_EXTENSION_API_ONLY
enabled, but this is bad: it means that even in my application target, those methods will have been pre-processed out and I'll never be able to use them.Solution
In my case, the solution would be for Cocoapods to not de-duplicate
AFNetworking
. But I'm not sure how Cocoapods can know which dependencies require a define to pre-processor out pieces of code. The only solution I can come up with is if the Podfile syntax allows us to specify certains dependencies not to be de-duplicated.I know that I can opt-out completely with
deduplicate_targets: false
, but it's a pity to have to do that for a project as pervasive asAFNetworking
.The text was updated successfully, but these errors were encountered: