how to call the c static library in a cocoa app? - cocoa

I have two projects, a Cocoa application and a static c library which it uses.
Then didn't in the same folder.For example:the name of c static library is libXXX.a,it in the XXXcore folder.the cocoa application in another folder that is the same level with the XXXcore folder. When I try to compile the cocoa application,I have the link error result.It is seem to change the search path in the cocoa app info(General panel).But it is not work,why?

If you're using Xcode, you can add a link to static library by adding the library to Frameworks folder in the project.

ok. I have the answer:
add the .a library to your cocoa project
edit the path of Header Search paths and Library Search paths in the project info panel(build panel)
don't forget the copy option while adding the library to your project.
Thanks Mehrdad Afshari for your help!

Related

Xamarin Android Layout Resources in library project not included in Application

I have a Xamarin Android library project which is referenced by an Android application project.
The library project has layout files which need to be used by a library project component. The Resource.designer.cs file seems to be generated properly. The layouts are marked as Android Resources. Yet at runtime the resources are not there. Trying to access them just returns 0.
After reading all the SO questions on the topic, I am convinced this should work, but so far it doesn't. Ideas?
Create the Android Class Library.
Create a layout folder in this class library and create a layout in this folder.
Add the code in your xamarin android app.
var btn_Load = FindViewById<Button>(Resource.Id.btn_LoadLibraryLayout);
btn_Load.Click += delegate
{
SetContentView(ClassLibrary1.Resource.Layout.library_layout);
};
I create a button to open the layout in class library.
Result:
You could download from the ClassLibrary_layout folder of GitHub for reference.
https://github.com/WendyZang/Test.git
Updated:
If you want to get the resource identifier, you need the package name of this class library. First, we could not get the package name in AndroidManifest.xml file or properties, because the class library does not have it.
You could get it from the steps below.
Create a activity in class library. And get the package name with the code.
var PackageNname = Application.Context.PackageName;
You could also get the resource identifier in this activity.
var resId2 = Resources.GetIdentifier("library_layout", "layout", PackageNname);
Result:
The paskage name is same to the app1 I provided.
Package Name: com.companyname.app1
You could also use the code directly in app1 activity.
int resId2 = Resources.GetIdentifier("library_layout", "layout", "com.companyname.app1");

How to use System.Security.Cryptography in Xamarin.Forms PCL

By reference to this link https://developer.xamarin.com/api/namespace/System.Security.Cryptography/
May I know how do I include this in my Xamarim.Forms PCL project? When I include in, Visual Studio is giving error as the picture below
May I know if anybody has any idea how to solve this? Thanks.
The namespace is available both in Xamarin.iOS and Xamarin.Android. You could make platform specific implementations for both platforms and then resolve them with the DependencyService
You would have your interface for whatever you need in your PCL
public interface ICryptoService // or whatever
{
string Cipher(string stringToCipher);
string Decipher(string stringToDecipher);
}
and then implement these in your platform specific projects
using System.Security.Cryptography;
namespace MyApp.Droid
{
public class CryptoService : ICryptoService
{
// implement interface
}
}
To make the implementation visible to DependencyService you have to use the DependencyAttribute
[assembly: Xamarin.Forms.Dependency(typeof(MyApp.Droid.CryptoService)]
You can now obtain an instance in your PCL with
var cryptoService = DependencyService.Get<ICryptoService>();
and then use it. The steps for iOS are basically the same. For UWP you have to register the implementation manually, see here.
Edit:
Since it's likely that the implementation will be the same for all platforms, you could introduce a shared project and put the implementation there. All you have to do now is referencing the shared project from your iOS and Android projects.
Edit 2:
Adding a shared project to an existing Xamarin.Forms solution is quite easy. Just right-click your solution in VS, choose Add -> New Project... (I only have a german localized VS at hand at the moment, but it should be something in the lines of that). Now select Shared Project, give it a name and click OK, there will be a new shared project in your solution.
Now right-click your platform specific project and choose Add -> Reference.... The window to add a reference should open and on the left you can choose the source of the reference (Assemblys, Projects, Shared Projects, COM and Browse). Select Shared Project and then the project you just created. Any code file in your shared project will now be compiled with your platform specific project as if the code file was in the platform specific project (watch for namespaces!). Repeat for the other platform specific projects.

Installation process of Gzip framework in Swift

How to install the Gzip framework in swift 3.0.1 and also how to use it in swift 3 and iOS 10.
For This actually they given the following instructions like
1.Build Gzip framework.
2.In Build Phases, add Gzip.framework library to your project.
3.import Gzip in your Swift file.
4.Use in your code.
But among all steps How to implement the 1st step like building the Gzip framework.
Thanks in advance.
1.For the solution, Just download the project from the GitHub and then open it.
2.Now in the project navigator panel expand the folder named "product".
3.In that folder beneath you can see the Gzip.framework in red color, on that you right click in order to see it in the Finder.
4.From that Finder location, you just drag and drop into your project.
5.In General tab under linker and binaries you add the framework.
6.And finally import the header module like "import GZip"for required class and then implement the required things.

Xcode: copying static library target to new project

I am trying to use the objective-c API provided by Google for Youtube using this link.
The project provided has a target for creating a static library. The documentation asks to copy the target into my project instead of the static library it produces.
The library project includes a target for building a static library for iOS apps. The static library target should be dragged into your application project's Build Phases "Link Binary with Libraries" list.
I am not able to do this. Is this what I am supposed to drag?
Since I could not find a way to drag the target, I went to the derived data folder and copied static library into the project. It worked but only partially. Can someone tell me what I am doing wrong?
no you should drag library from left side (Project Navigator).
But in bottom of (Link Binary with Libraries) section presents + and - buttons that do the same functionality as dragging, so you also can add library with plus button
Also if you build this lib from source don't remember add it to Target Dependency section

ios iphone xcode renaming a built custom framework

Have a custom built framework using custom template, etc. Works great. But would like to copy the framework after the build something like.
/dir1/myframework.framework
to
/dir2/myframework-5.1.framework
When the renamed one is included in the xcode program, all is well (framework search path is correct, etc), but the link does not see the framework. Have tried to change the renamed info.plist items with no luck. What could be missing... I thought this was done before, but can't seem to get it working now. is this a signing thing from the framework build?
Changed the following plist items
bundle name myframework-5.1.framework
executable file (changed file name)
etc.
Turns out you have to rename the object link in the framework to the same name as the framework and all is ok.

Resources