johnno1962 / InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
MIT License
3.96k stars 312 forks source link

Could not locate compile command #401

Closed axelthat closed 2 years ago

axelthat commented 2 years ago

I am using injection on my new ios(13.0+) app without storyboards (not swiftui).

πŸ’‰ ⚠️ Could not locate compile command for /Users/axel/MyApp/ViewController.swift.
This could be due to one of the following:
1. Injection does not work with Whole Module Optimization.
2. There are restrictions on characters allowed in paths.
3. File paths in the simulator are case sensitive.
4. The modified source file is not in the current project.
5. The source file is an XCTest that has not been run yet.
Try a build clean then rebuild to make logs available or
consult: "/Users/axel/Library/Developer/CoreSimulator/Devices/08177A3D-A71D-422E-A306-298729AD01C1/data/Containers/Data/Application/2C01F92B-C26B-495A-82A3-8B014D060F74/tmp/command.sh".

AppDelegate.swift

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        #if DEBUG
        Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
        #endif

        return true
    }
}

AppCode: 2022.1.2 XCode: 13.2 Injection: 4.2.7

johnno1962 commented 2 years ago

Hi, Does it work under Xcode? Can you post the contents of /Users/axel/Library/Developer/CoreSimulator/Devices/08177A3D-A71D-422E-A306-298729AD01C1/data/Containers/Data/Application/2C01F92B-C26B-495A-82A3-8B014D060F74/tmp/command.sh

axelthat commented 2 years ago

I don't get any error on xcode. But the changes aren't reflected.

Edit: It suddenly started working on AppCode as well. But the changes are again not reflected.

https://user-images.githubusercontent.com/31353695/171993585-e2ee8929-17dd-44b1-b238-56750a3de7af.mov

johnno1962 commented 2 years ago

Looks like the code to find AppCode's build logs has stopped working and it is using only Xcode's build data. Is this a new release of AppCode? @yeswolf? Changes not being reflected can be many things. Is viewDidLoad() called again when you inject? Do you have a @objc func injected() method that calls it? The code needs to be actually called.

axelthat commented 2 years ago

I am using the latest version of AppCode.

I am sorry I think I missed @objc fun injected(). What should be the body of injected function. Could you guide me? Thanks!

johnno1962 commented 2 years ago

It's could call viewDidLoad() or something like configureView() which sets up the parameters you want to set.

axelthat commented 2 years ago

Works perfectly. Thank you.

axelthat commented 2 years ago

@johnno1962 The issue still exists in AppCode: πŸ’‰ ⚠️ Could not locate compile command for /Users/axel/MyApp/ViewController.swift..

johnno1962 commented 2 years ago

I thought you said it was working in AppCode after you used Xcode? Which "the issue" is not working now?

axelthat commented 2 years ago

It only works if xcode is in background running injection else it will not work stand-alone.

johnno1962 commented 2 years ago

OK, thanks for letting me know. So, injection only works for you in AppCode if you are also running the iOS program inside Xcode at the same time? I've downloaded the new AppCode and am looking at it but can't get it to not work at the moment. The error you're getting at the moment is Could not locate compile command right?

johnno1962 commented 2 years ago

OK again, I may have found one problem. AppCode may be modifying source files in your home directory other than those of your project. To work around this until I get a fix out can you set the INJECTION_DRIECTORIES environment variable in your scheme to the project root directory to filter these changes out. This only applies to the "HotReloading" version of injection.

johnno1962 commented 2 years ago

You're running the InjectionIII.app while you're trying to use Injection? What does it print when you load the iOSInjection.bundle? The AppCode support code seems to be working for me.

johnno1962 commented 2 years ago

Is your machine M1 or Intel? I'm seeing some issues where the architecture gets confused as AppCode seems to be running as Intel as does your program in the simulator. This might take a while to sort out. It may be best to stick to Xcode for using injection on M1 for now.

axelthat commented 2 years ago

OK, thanks for letting me know. So, injection only works for you in AppCode if you are also running the iOS program inside Xcode at the same time? I've downloaded the new AppCode and am looking at it but can't get it to not work at the moment. The error you're getting at the moment is Could not locate compile command right?

Yes, appcode only works when xcode is also running the app. And yes the error is "Could not locate compile command". Try changing a file inside appcode and you should be able to see the error.

You're running the InjectionIII.app while you're trying to use Injection? What does it print when you load the iOSInjection.bundle? The AppCode support code seems to be working for me.

Yes. And here's the message,

πŸ’‰ InjectionIII connected /Users/axel/axop/Basket/Basket.xcodeproj
πŸ’‰ Watching files under the directory /Users/axel/axop/Basket

Is your machine M1 or Intel? I'm seeing some issues where the architecture gets confused as AppCode seems to be running as Intel as does your program in the simulator. This might take a while to sort out. It may be best to stick to Xcode for using injection on M1 for now.

MacBook Pro (15-inch, 2018), 2.6 GHz 6-Core Intel Core i7.

axelthat commented 2 years ago

Update,

Now, appcode works without xcode in background. I have no idea what changed. However, I do see this error. The hot reload still works despite this error.

objc[2096]: Class _TtC6Basket14ViewController is implemented in both /Users/axel/Library/Developer/CoreSimulator/Devices/08177A3D-A71D-422E-A306-298729AD01C1/data/Containers/Bundle/Application/AA8C07CD-B36F-4E8A-90FF-CC0BAB69EB41/Basket.app/Basket (0x101b41cc0) and /Users/axel/Library/Developer/CoreSimulator/Devices/08177A3D-A71D-422E-A306-298729AD01C1/data/Containers/Data/Application/A6B4BA46-2994-4F7E-8671-F6B1808A930A/tmp/eval101.dylib (0x104743308). One of the two will be used. Which one is undefined.

johnno1962 commented 2 years ago

You don't need to worry about that message, it's just a warning I can't do anything about. If you're using Intel AppCode should still be working though it seems to be getting confused about which build logs to use when switching between Xcode and AppCode causing the Could not locate compile command error. The code could be simplified a bit. It should work if you build clean and exit Xcode then build clean in AppCode and then relaunch.

axelthat commented 2 years ago

Gotcha. Thank you so much. That solves my issue.