iPhone: Fontconfig error: Cannot load default config file - iphone

I have the following problem:
I included a static library of FontConfig libfontconfig.a into my iPhone project.
The application is building and i can run it on the device but when I do a call to a method that needs some functions of this library the application crashes with the following error
Fontconfig error: Cannot load default config file
terminate called throwing an exception
I read that this error normally occurs when FontConfig cannot find the fonts.conf file that is normally located in /etc/fonts.
But I cannot move that file to this directory of the iPhone. Has anyone a solution? Just copying the file to the application bundle did not help, as well.
I would appreciate any help.

I finally found a way to solve this problem. I set an Environment Variable FONTCONFIG_FILE and FONTCONFIG_PATH that define the locations of the fonts.conf file and the path that was before /etc/fonts. So I can add the fonts directory to the project and define the path #runtime.
The Environment Variables have to be set in your code before you call a method that needs a functionality of FontConfig. I set it after starting my Application in the AppDelegate.
Here is the code I added:
//Get the directory of your Application
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
//Create a String with the location of your fonts.conf file
NSString *fontconfigFile= [bundlePath stringByAppendingString:
[NSString stringWithFormat:#"/fonts/fonts.conf"]];
//Create a String with the path of the FontConfig configuration path
NSString *fontconfigPath= [bundlePath stringByAppendingString:
[NSString stringWithFormat:#"/fonts"]];
//Set the Environment Variables
setenv("FONTCONFIG_FILE", [fontconfigFile UTF8String], 0);
setenv("FONTCONFIG_PATH", [fontconfigPath UTF8String], 0);
In a second step I had then to modify my fonts.conf file. I added the fonts directory to FC/fonts and the cache directory to FC/cache of my project and adjusted the fonts.conf file on two parts.
I changed the first part:
<!-- Font directory list -->
<dir>/usr/share/fonts</dir>
<dir>/usr/X11R6/lib/X11/fonts</dir>
<dir>~/.fonts</dir>
to:
<!-- Font directory list -->
<dir>FC/fonts</dir>
and the second part:
<!-- Font cache directory list -->
<cachedir>/opt/local/fc1407cd/var/cache/fontconfig</cachedir>
<cachedir>~/.fontconfig</cachedir>
to:
<!-- Font cache directory list -->
<cachedir>FC/cache</cachedir>
Then it did not crash anymore.

Related

Launch External Tools from Eclipse Plug-in View

I'm building a simple Eclipse plug-in out of preexisting Java application project that relays on 2 external files, one x-executable/application and one .sh script.
The call is implemented in application like this, (which wouldn't work in plug-in):
Process p = new ProcessBuilder("external/application_name", "-d", path).start();
I used External Tool Configuration to define how I want this external files to be launch (when user clicks button on View) and I've exported configuration (example of one):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/softwareevolution/external/application_name}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-d ${project_loc}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc}"/>
</launchConfiguration>
How can I have this application install along with Eclipse plug in,
or a as a part of it? (see #howlger answer billow) - I set plugin to install as directory /
Connected plugin to Feature project- checked unpack after
installation - and exported Feature project. Select application's
folder on Build/Binary build.
Can I then make use out of this exported .launch files, and if so
under which extension point should I include them in plugin.xml? -
No. (see #greg-449)
The application is supposed to produce 2 files on the path where it
is executed from. I am facing permission denied when trying to
launch it in terminal from plug-in's install directory but not when
launching in workspace. (see #howlger answer billow) - Upon exporting the plugin, initial
permissions of application had changed. Used instructions in p2.inf
to chmod them back.
The newly generated files (from runing .sh script) are missing write permission.
ProcessBuilder
After finally setting up plugin correctly and adding ProcessBuilder I was getting exception message : Cannot run program "rfind_20" (in
directory
"home/adminuser/.p2/pool/plugins/rFindTest3_1.0.0.201809030453/external"
error=2:, No such file or directory
File rfind_20 did exist and permission were 777. The targeted project also existed.
Although the working directory was set to applications folder, the application name was not enough, the absolute path was required as
command argument.
pb = new ProcessBuilder(url.getPath(), "-d", project.getProject().getLocation().toString());
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IProject project= sampleGetSelectedProject();
ProcessBuilder pb;
Process rfind, ajust, copy;
Bundle bundle = FrameworkUtil.getBundle(getClass());//Bundle bundle = Platform.getBundle("rFindTest3");
URL url = FileLocator.find(bundle, new Path("external/rfind_20"), null);
URL dirurl = FileLocator.find(bundle, new Path("external/"), null);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
try {
MessageDialog.openInformation(
window.getShell(),
"Test",
project.getProject().getLocation().toString());
url = FileLocator.toFileURL(url);
dirurl = FileLocator.toFileURL(dirurl);
pb = new ProcessBuilder(url.getPath(), "-d", project.getProject().getLocation().toString());
//no matter the working directory the absolute path was required!! sending "rfind_20" as command did not work as command
pb.directory(new File(dirurl.getFile()));
rfind = pb.start();
rfind.waitFor();
rfind.destroy();
}catch(Exception e) {
MessageDialog.openInformation(
window.getShell(),
"Test",
e.getMessage());
}
return null;
}
The only remaining mystery is why my sampleGetProject() method wouldn't work in Plug-in Perspective. So just keep in mind to switch to other Perspectives when testing your plug-in.
There are two ways to ship an application as part of a plugin and run it via ProcessBuilder (the *.launch file cannot be used inside a plugin for that):
Extract the executable files from the plugin JAR to a (temp) directory and change their file permissions before running them
Install the plugin as a directory:
In META-INF/MANIFEST.MF add the line Eclipse-BundleShape: dir (see "The Eclipse-BundleShape Header" in Eclipse help - Platform Plug-in Developer Guide - OSGi Bundle Manifest Headers)
Create a Feature Project and connect your plug-in in Included Plug-in, check "Unpack the plug-in archive after the installation"
Create a META-INF/p2.inf file that contains the following (see Eclipse help - Platform Plug-in Developer Guide: "Touchpoint Instruction Advice" in Customizing p2 metadata and "chmod" in Provisioning Actions and Touchpoints):
instructions.install = \
chmod(targetDir:${artifact.location},targetFile:path/to/executable1,permissions:755);\
chmod(targetDir:${artifact.location},targetFile:path/to-executale_which_generates_files/executable2,permissions:733);\
chmod(targetDir:${artifact.location},targetFile:path/to-executale_which_generates_files/,permissions:766);
instructions.install.import = org.eclipse.equinox.p2.touchpoint.eclipse.chmod
If you have a xxx.launch file in the workspace you can launch it using
IFile file = ... get IFile for workspace file
ILaunchConfiguration config = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(file);
DebugUITools.launch(config, ILaunchManager.RUN_MODE, false);
If you have an executable as part of a plug-in then you can't use a .launch file. Instead use FileLocator to get the location of the executable and run it with ProcessBuilder
Bundle bundle = FrameworkUtil.getBundle(getClass());
URL url = FileLocator.find(bundle, new Path("relative path to executable"));
url = FileLocator.toFileURL(url);

Unable to get files in Android assets directory

I am trying to find files located in assets. I have .txt, .gif, and .db files that are there in an eclipse android project but do not display when I run the following code:
AssetManager am = getAssets();
try {
String list[] = am.list("/");
I=0;
Str="";
while (list[] != null) {
Str=Str+"\r\n"+list[I];
I++;
}
}
catch(exception e){
}
I get this list:
AndroidManifest.xml
META-INF
assets
classes.dex
com
res
resources.arsc
This list does not include any of the files in assets.
Project properties is currently set to not include assets folder in the build path. When I do include the assets folder in the build path, it gives me the same list with ".." as the first file.
I have tried changing "/" in the third line to "/assets/" but get nothing returned.
Changing the Android Project Build Target between Android 2.3.1 and Android 2.1-update1 appears to have no effect.
Is there a setting in the project properties that is required for files in assets to be included in the build? Is there a different name for the assets directory using AssetManager?
list() takes a relative path within the assets. Seems in your case you need to pass an empty string, am.list("")

Resource Folder Xcode 4, how to delete files from package

I am using Xcode 4. I have copied
several images to main folder, I
have built project, next I have
deleted all images. When I list
resources path by NSLog, I can see
that there are still in this
package. I've deleted build folder,
clean etc. What should I do to
delete this files from my package
And second question. Why when I copy
an entire folder, and list files and
directories by:
NSFileManager *fm = [[NSFileManager alloc] init];
NSString *string = [[NSBundle mainBundle]resourcePath];
for(NSString *name in [fm contentsOfDirectoryAtPath:string error:nil])
{
NSLog(#"%#", name);
}
In console a can only see files from this folder.
Have you deleted the project from simulator ? You can do it in the Simulator app or deleting the project folder at ~/Library/Application\ Support/iPhone\ Simulator/

loadable bundle for plists

I have a main project and a static library project inside the main project. I want few plists in my static library project. Since there is no resource directory it is not possible to add plists directly, What is did is this.
1.Added a loadable bundle to my static library project
2.Added few plists to loadable bundle
3.This loadable bundle is made as a dependency to my static library project
4.Added this loadable bundle as a dependency to my main project as well
Am i going on the right path ? when i fired the build and used show contents to see the contents of the app i was able to see the .bundle file inside the .app file. Right now i want to know how to access this bundle . .
i used this
NSBundle *staticlink = [NSBundle mainBundle] pathForResource:#"MyBundle" ofType:#"bundle"];
[staticlink load];
NSLog(#"%#",staticlink);
console said this . .
. . . /mainproject.app/MyBundle.bundle <not yet loaded>
What is missing ? what should i do load MyBundle ?
-pathFoResource:ofType: returns a NSString object which will have the path to the bundle.
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:#"MyBundle" ofType:#"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
[bundle load];

iphone: Building error precompiling app_prefix.pch

I dont know what happened to Xcode. I was debugging my app when after a while of writing some code I tried to compile and an error message appeared:
Building error precompiling app_prefix.pch
arm-apple-darwin9-gcc-4.2.1: te: no such file or directory
I had never this error before, and I am not sure how to solve it.
Did you move your [Project Name]_prefix.pch file ? If you moved it to say, a subdirectory of the project's parent, you need to open up the target Build settings for each of your targets by double clicking on them, do a search for "pch" in the build settings, and update the path to the .pch file.
For example, if you moved your .pch file to a subdirectory "Core" which is in the project parent, then you'd change "[Project Name]_prefix.pch" in the build settings to "Core/[Project Name]_prefix.pch".
Try to change the buid setting of the target in project propertys:
Change the option Precompile prefix header to "NO"