google/EarlGrey

EarlGrey 2 build error: Redefinition of module 'AppFramework'

adil-hussain-84 opened this issue · 7 comments

I created a new iOS application project in order to experiment with adding EarlGrey 2 to an iOS UI Testing Bundle by means of the EarlGrey 2 setup guide.

I was able to clone the earlgrey2 branch of the EarlGrey repository, download its dependencies by executing the Scripts/download_deps.sh script, and build each of the targets in the EarlGrey Xcode project.

Next, I was able to add the libTestLib.a library to my UI testing target's Link Binary With Libraries build phase, add the -ObjC linker flag to its build settings and still be able to build it successfully.

However, when I then proceed to add the EarlGrey directory (the directory containing the EarlGrey.xcodeproj file) to my UI testing target's User Header Search Paths and try again to build it, I encounter a Redefinition of module 'AppFramework' error.

Anyone have any idea what I need to do to get around this error?

I have pushed the project here if anybody wants to inspect it.

For what it's worth, I tried running the tests in the FunctionalTests target also (located in the Tests/Functional folder and encountered the same error message.

The version of Xcode that I am using is 12.3.

I have this error when I move to the latest Xcode 12.4, @adil-hussain-84 Did you fix the issue?

@samh-depop: No, I couldn't get it to work and gave up. My UI tests are still written using EarlGrey 1 and running against the iOS 13.5 simulator (because EarlGrey 1 doesn't work with later versions of iOS). I'm thinking to rewrite my UI tests using plain old XCTest constructs (i.e. XCUIElement and XCUIElementQuery) and to use a framework like Shock to mock out the app's HTTP requests when running in "test" mode. See here for an example of how to use the Shock library. See here for some extension functions which will help you write more fluent tests with XCUIElement and XCUIElementQuery. I wish the transition from EarlGrey 1 to EarlGrey 2 was more seamless but that doesn't appear to be the case.

@samh-depop There were a couple of failures in the Tests which are trivial fixes and I'll send an update tomorrow. I believe there's an issue with Swift and the EarlGrey Collection matchers which we'll work on and update this bug with. You should be able to test this out after the update.

@adil-hussain-84 I ran your pushed project and was able to build fine - I noticed there wasn't a bridging header or a Copy Files phase added in the UI Test target, without which you can't run the project at all. Can you update the project with the full steps if there were any you missed?

Thanks, @tirodkar and @adil-hussain-84 actually using the latest commit from the EarlGrey 2 branch worked for me.

I just retried this with Xcode 13.1 and the latest commit in the earlgrey2 branch (i.e. ac95e16) and I'm still encountering the same issue. As soon as I add the path to the EarlGrey folder in my UI Testing target's User Header Search Paths Build Setting and mark it as recursive, the build fails with a Redefinition of module 'AppFramework' error.

I will mark this entry in User Header Search Paths Build Setting as non-recursive and proceed with the next steps in the setup guide in the hope that I can resolve subsequent build errors with specific non-recursive paths to the EarlGrey folder.

My Build Location Xcode preference was set to Relative to workspace rather than the default value of Unique. I suspected this could be causing the Redefinition of module 'AppFramework' error. My reasoning was that the AppFramework module is being found not just in EarlGrey/AppFramework but also in EarlGrey/build. So I proceeded to change this Xcode preference back to the default value of Unique. To my joy, the error went away.

To be scientific about it all, I thought I'd change the Xcode preference back to Relative to workspace and see the error return. Strangely, the error did not return. Since changing my Build Location Xcode preference from Relative to workspace to Unique and then back to Relative to workspace again, the error has not surfaced.

If you're not so lucky to lose the error like I have, a workaround is to add the following values in the User Header Search Paths Build Setting...

../EarlGrey/Submodules/eDistantObject (recursive)
../EarlGrey/AppFramework (recursive)
../EarlGrey/CommonLib (recursive)
../EarlGrey/TestLib (recursive)

... instead of the following values suggested in the setup guide:

../EarlGrey/Submodules/eDistantObject (recursive)
../EarlGrey (recursive)

Then, import the EarlGrey headers as #import "EarlGrey.h" or #import "EarlGreyImpl/EarlGrey.h" instead of #import "TestLib/EarlGreyImpl/EarlGrey.h".