johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 565 forks source link

😂 How to install in xcode 8? #171

Open ghost opened 7 years ago

ghost commented 7 years ago

How to install in Xcode 8. Please give a detailed tutorial. I tried many times or failed.

objczl commented 7 years ago

+1 I tried un-sign Xcode but it still can't work.

dollar2048 commented 7 years ago

Software error:

Could not connect Access denied for user 'johnhol_inject'@'localhost' (using password: YES) at ../../../injection/common.pm line 13. Compilation failed in require at sale.cgi line 4. BEGIN failed--compilation aborted at sale.cgi line 4. For help, please send mail to the webmaster (webmaster@injection.johnholdsworth.com), giving this error message and the time and date of the error.

johnno1962 commented 7 years ago

There are a number of new hurdles Xcode 8 puts up. The first thing to check is that the plugin has built without error and is loading into Xcode. Is there a Product/Injection Plugin menu item inside Xcode? If this is not present you need to unsign Xcode as described elsewhere. The second problem is that the “InjectionLoader” used in “unlatched” injection now needs to be codesigned before it can load into the simulator. Signing this is part of the injection plugin build and typical problems include invalid or duplicate codesigning identities. Check for errors when you build. If these two conditions are met injection should work. If there is a Project/Injection Plugin menu item but the Loader does not load giving an error in the console, try “patched” injection using a main.m file. If you still can’t get it to work please provide more detail of your problem than “it doesn’t work”. How doesn’t it work? What is the error? Is the plugin loading?

dollar2048 commented 7 years ago

@johnno1962 xcode is unsigned. "injection menu" is visible. I have installed in using Alcatraz. but now It gives me error:

`

\ RECORDED BUILD SUCCEEDED ** 

Renaming bundle so it reloads..
rm -rf "/Users/user/PR/Project/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle1.bundle" && cp -r "/Users/user/PR/Project/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle.bundle" "/Users/user/PR/Project/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle1.bundle"
Codesigning with identity 'iPhone Developer' for iOS device
 iPhone Developer: ambiguous (matches "iPhone Developer: User (N3YZ6Z6Z3X)" and "iPhone Developer: user123@gmail.com (43173B53US)" in /Users/user/Library/Keychains/login.keychain)



* Could not codesign as 'iPhone Developer': /Users/user/PR/Project/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle1.bundle *



at /Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/common.pm line 57.


main::error('Could not codesign as 9hone Developerø/Users/user...') called at /Users/user/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/injectSource.pl line 513
 * Bundle build failed *`

johnno1962 commented 7 years ago

You need to resolve the ambiguity in the injection bundle project. Open Project/Injection Bundle/Open Bundle Project and modify code signing identity and delete iOSInjectionProject/identity.txt so it is updated (edited)

dollar2048 commented 7 years ago

@johnno1962 sorry, where do I have to modify? in iOSInjectionProject which is in my project? there I see "Target is unsigned"

johnno1962 commented 7 years ago

Please see https://github.com/johnno1962/injectionforxcode/issues/41

dollar2048 commented 7 years ago

@johnno1962 thanks for the great help!!! finally I have to delete other "iPhone Developer" certificates in login KeyChain to leave only one certificate. this issue could be closed, I think.

ghost commented 7 years ago

@dollar2048 This is my issue ...

dollar2048 commented 7 years ago

@luoerming I have used three lines to unsign Xcode 8 and update plugins: sudo gem install update_xcode_plugins update_xcode_plugins --unsign update_xcode_plugins

from Here (unsign Xcode8)

ghost commented 7 years ago

cd InjectionLoader && xcodebuild -sdk iphonesimulator -config Debug && cd - && chmod +x "$INSTALL_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"/*.pl && cp -rf Classes/Xtrace.* InjectionLoader/build/*-iphonesimulator/InjectionLoader.bundle "$INSTALL_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH" /usr/bin/codesign --force --sign "iPhone Developer" --timestamp=none "$INSTALL_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH"/InjectionLoader.bundle

qq20160923-1 2x

@dollar2048 Thank you, This is my "Run Script" code, There is something wrong here?

I have a error code,

2
dollar2048 commented 7 years ago

@luoerming 1) so did you unsign xcode8? 2) try to install "injection" via alcatraz and not via xcodebuild.

ghost commented 7 years ago

@dollar2048 Yes, I was using alcatraz installed, But I have a new error. 😔

qq20160929-0 2x qq20160929-0 2x
ghost commented 7 years ago
qq20160929-2 2x

I try using Alcatraz to reinstall again. I still can not succeed.


qq20160929-1 2x

Then I restart the Xcode. And choose the "load Bundle " button, Now the "injection menu" is visible. But when I run the injection plug-in I have a new error code.

2016-09-29 17:12:47.437 example[50417:872947] Error loading /Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader: dlopen(/Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader, 265): no suitable image found. Did find: /Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader: required code signature missing for '/Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader'

dollar2048 commented 7 years ago

@luoerming I have received also error 65 and it installed fine for me anyway. then I have Click OK and relauch XCode. XCode asked me to "Load plugin bundle". after that I can see Injection in my "Product" menu tab.

do you see Injection as installed plugin in your package manager?

ghost commented 7 years ago

qq20160929-3 2x

qq20160929-3 2x

Yes, I'm sure it's already installed to Xcode8. And the Xcode menu is visible injection plug-in button.

dollar2048 commented 7 years ago

@luoerming so you did install it in Xcode 8! the problem is solved, isn't it? ))

ghost commented 7 years ago

@dollar2048 😪Yes, Is already installed, But it can not work. This is error code .

2016-09-29 17:12:47.437 example[50417:872947] Error loading /Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader: dlopen(/Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader, 265): no suitable image found. Did find: /Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader: required code signature missing for '/Users/carroll/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle/InjectionLoader'

dollar2048 commented 7 years ago

@luoerming You have this error in the installation window. right? but the plugin was installed. right? try to use it.

ghost commented 7 years ago

@dollar2048 Thank you. It's indeed already installed in Xcode. But when I tried to run it. The Xcode console will be display this error code.

dollar2048 commented 7 years ago

Sorry, than we have to ask @johnno1962

ghost commented 7 years ago

@dollar2048 Anyway, Thank you. Can I make a friend with you?

johnno1962 commented 7 years ago

It’s best to build the plugin from source rather than using Alcatraz now. The “InjectionLoader” error you are getting is becuase it is not codesigned whcih is done in the RunScript build phase you mention above. That is the place to look.

ghost commented 7 years ago

@johnno1962 But when I paste the RunScript. Xcode will not run.

This is RunScript code and Xcode console displayed error code

qq20160923-1 2x
2
ghost commented 7 years ago

@johnno1962 So this is because I did not give the signature of the injection plug-in?

johnno1962 commented 7 years ago

The injection plugin itself does not need to be signed. It is the InjectionLoader which loads into the simulator on demand when you inject that needs to be signed with Xcode 8. I don’t see why it can’t find the InjectionLoader directory. it should be there if you have git cloned the repo correctly. But your problem is still ambiguous codesigning. Change "iPhone developer" in the run script to something else.

dollar2048 commented 7 years ago

@johnno1962 by the way I have the same issue when try to compile "Injection" by cloning the project.

johnno1962 commented 7 years ago

which specific issue? Codesigning issues are related to the keys in your keychain.

dollar2048 commented 7 years ago

Yes. the same error in the RunScript. Related to Code signing. (that is why I could install only via Alcatraz)

johnno1962 commented 7 years ago

Alcatraz is just ignoring what is an important error. If your error is still something like: iPhone Developer: ambiguous (matches "iPhone Developer: User (N3YZ6Z6Z3X)" and "iPhone Developer: user123@gmail.com (43173B53US)" in /Users/user/Library/Keychains/login.keychain)

you need to alter the run script so it has a unique identity to sign with. Either "iPhone Developer: User (N3YZ6Z6Z3X)” or "iPhone Developer: user123@gmail.com (43173B53US)"

johnno1962 commented 7 years ago

i.e. alter this: /usr/bin/codesign --force --sign "iPhone Developer" --timestamp=none "$INSTALL_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH”/InjectionLoader.bundle

dollar2048 commented 7 years ago

@johnno1962 after deleting other "iPhone Developer" certificates in login KeyChain it builds with no error. I left only one certificate. :)

johnno1962 commented 7 years ago

Hurrah! But does it work now?

dollar2048 commented 7 years ago

@johnno1962 as for me, it started to work after installing via Alcatraz.

johnno1962 commented 7 years ago

Cool. I wish there was a solution to this amiguous signing problem other than deleteing profiles.

johnno1962 commented 7 years ago

I’ll leave this open for other users.

dollar2048 commented 7 years ago

@johnno1962 Thanks anyway! this plugin is so nice.

johnno1962 commented 7 years ago

For more information look here: https://johntmcintosh.com/blog/2016/10/03/code-injection-ios

ivnsch commented 7 years ago

I did all the steps from the blog, it's not working. The plugin seems to be installed - the additional menu items in XCode are available but the injected() function is not being called. I added it to a view controller which I use. Not sure if it's a general problem with the plugins - I also tried to install XcodeColors (via Alcatraz, installation of which worked without problems after unsigning XCode), it installed fine, it shows it's installed, I restarted XCode but the messages are not colored.

ghost commented 7 years ago

@johnno1962 Thanks anyway! this plugin is so nice. and I have solved this problem. Thank you very much.

johnno1962 commented 7 years ago

You can now avoid all this by using the new standalone Injection as an App. http://johnholdsworth.com/injection.html

ghost commented 7 years ago

@johnno1962 Wow, It's very cool new features, I can finally use this plugin Now!! But I still have an error code.

Like this: 1 warning generated. objc[76145]: Class BTBicycViewController is implemented in both /Users/xx/Library/Developer/CoreSimulator/Devices/EE0BB85E-98CF-4E4C-9B15-41CE0E6014F6/data/Containers/Bundle/Application/A8EDC737-112C-4AC7-BB43-FE169F0564BC/xx.app/xx (0x11069f7e0) and /Users/xx/Library/Developer/Xcode/DerivedData/biketo-dnylhyikwfqriaegbrpmsayzjwmh/Logs/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle6.bundle/InjectionBundle (0x1289017c0). One of the two will be used. Which one is undefined.