7

I made a fully functional tweak with theos and I need to use an image file in it , the code for getting the image is correct (tested on Xcode) . but the image isn't included in the final DEB file .

and I have this makefile :

SDKVERSION=6.0
include theos/makefiles/common.mk
include theos/makefiles/tweak.mk

TWEAK_NAME = MyTweak
MyTweak_FRAMEWORKS = Foundation  CoreGraphics UIKit
MyTweak_FILES = Tweak.xm image.png

include $(THEOS_MAKE_PATH)/tweak.mk

But when I try to compile I get :

 No rule to make target `obj/image.png.o', needed by `obj/MyTweak.dylib'.  Stop. 

what can I do to include it ??

(Sorry for bad syntax , asking from iphone).

johnny peter
  • 4,634
  • 1
  • 26
  • 38
user1784069
  • 71
  • 1
  • 2
  • Only someone familiar with the Theos build system will be able to help. From a make perspective, this means that one of those included makefiles is treating the contents of the `MyTweak_FILES` variable as source files to be compiled. Either there's some other variable that's supposed to be used for image files, or else the makefiles don't know how to deal with PNG files. – MadScientist Apr 14 '13 at 15:03

2 Answers2

11

MyTweak_FILES variable should only include files that can be compiled. Make file handles resources differently.

To include resources you need to create a bundle as follows.

1) Create a folder called Resources in the tweak.xm directory.

2) Put all your resource files (all your PNG's) into that folder.

3) Add the following info to your make file

BUNDLE_NAME = your_bundle_identifier

your_bundle_identifier_INSTALL_PATH = /Library/MobileSubstrate/DynamicLibraries

include $(THEOS)/makefiles/bundle.mk

4) Define your bundle as follows on top of your tweak.xm file.

#define kBundlePath @"/Library/MobileSubstrate/DynamicLibraries/your_bundle_identifier.bundle"

5) You can now initialize the bundle and use the images within your tweak as follows:

NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];

NSString *imagePath = [bundle pathForResource:@"your_image_name" ofType:@"png"];

UIImage *myImage = [UIImage imageWithContentsOfFile:imagePath]

In the above steps replace your_bundle_identifier with your tweaks bundle identifier which would be in the control file. (ex: com.yourdomain.tweak_name)

Also replace your_image_name with the name of the image you want to use.

You can pretty much use any resources (ex: sound files) the above way.

johnny peter
  • 4,634
  • 1
  • 26
  • 38
  • This still works in 2021. The only change to make is to remove the "autorelease" call from Step 5. – BBedit Apr 10 '21 at 10:25
0

In addition to the posted answer, it's common practice to place bundles in "/Library/Application Support/" rather than "/Library/MobileSubstrate/DynamicLibraries/"

wal
  • 46
  • 1
  • 2