SDK production details

Source: Internet
Author: User

SDK production details

It is easy to make a simple SDK. Complex sdks are the same as complicated applications. Here we will introduce how to make a simple sdk.

Steps:

1. Create an sdk and publish files

2. Compile and obtain sdk files

3. Import the project and configuration file

4. Solve the error. Complete.

 

1. Create an sdk and publish files

Then a name is required.

When an sdk is created, the automatically generated file can be deleted like the viewController of a common project.

Describes how to use classes in the sdk and controllers with xib.

First, use this automatically generated method to add a printing method to the class.

. H file

#import <Foundation/Foundation.h>@interface SDK : NSObject-(void)sdkLog;@end

. M file

#import "SDK.h"@implementation SDK-(void)sdkLog{    NSLog(@"sdkAction");}@end

That's how it works. Then let's talk about the controller.

Create a controller named:

Remember to check "add xib" for SDKViewController, and describe the exposed File

Add anything on the xib and wait for the next hop.

You can determine the Controller in our sdk.

Next, we will make an sdk static library to protect and hide the implementation content. However, if the content needs to be called, it must be exposed, what should we do?

You can expose the file by following the graph and expose the header file to be called. Note that if the exposed header file contains a controller and the Controller has an xib file, therefore, xib must be exposed. Otherwise, when it is called in other projects, the xib's

 

Here, the sdk has come to an end. There are three types of sdk packages: The real machine sdk package, the virtual machine sdk package, and the merger of the two packages. If you are interested in Baidu, generally, packages do not need to be merged during use. Weibo and qq sdks are used to separate the two packages, because the merged package is large, the packaged ipa package will become larger, causing user dissatisfaction and wasting user traffic.

 

 

2. Compile and obtain sdk files

Next-> compile, select the real machine or the real machine sdk compiled by the Geneic iOS Device, and select the Virtual Machine sdk compiled by the virtual machine.

Real machine sdk:

 

Select a real machine or Geneic iOS Device for compiling. The red libSDK. a turns gray, indicating that the file exists.

Right-click libSDK. A and choose show in finder to view the content,

Note the folder name. The Debug-iphoneos folder is the real-machine sdk folder. Wait and check the name of the Virtual Machine sdk folder.

The files in the include folder are exposed files. when adding a to the project, you must add the files in the project. The real machine and Virtual Machine sdk are used in the same way. Check the virtual machine first.

 

Virtual Machine sdk:

Clear the sdk package of the real machine that you just programmed to see the problems caused by the xcode7 Virtual Machine. After cleaning, libSDK. a is red and does not exist.

Then select Virtual Machine compilation. If you are using xcode7, you will find how to compile it, libSDK. a is red. This is an xcode7 bug. Some people have said that xcode7 cannot compile the Virtual Machine sdk. This is wrong. You can generate the sdk without worrying about it, if the compilation prompts success, in fact, the virtual machine sdk is still successfully generated, but it is not visible in xcode. In this case, clear is not required. The real machine sdk package is also compiled together to generate the real machine sdk, click libsdk. file a show in finder. Here we can see the above situation.

Note:

I mentioned the folder name before. The folder you see is still the folder of the real machine sdk, that is, you click the virtual machine to compile it again, and you will find that it is a real machine folder, at this time, press command + scripts to return to the upper-layer folder.

Now we can see two folders. the folder on the left is the real machine sdk folder, and the folder on the right is the virtual machine sdk folder. Click the folder on the Virtual Machine to view the same content as the real machine sdk, xcode7 can find the Virtual Machine sdk folder in this way

 

 

3. Import the project and configuration file

Demonstration with Virtual Machine

Create a new project, for example, named test

Drag the folder and. a file in include to the project. If not checked, check add to targets.

 

Then configure and search for search in the configuration. If the library search paths in the configuration is empty, double-click the empty arrow to add a search path for the library. a file path such as $ (PROJECT_DIR)/text/libSDK. a

You can also add other paths to the. a file.

Otherwise, the. a file will not be found.

Search for other linker, and add-Objc and-all_load to other linker flags.-all_load is added based on the actual situation. Do not add the following descriptions.

Other Linker Flags: Other link labels

Set to "-ObjC"

When the imported static library uses a category, you need to set it to-ObjC, even if it is not used, to prevent future use of other sdks.

Supplement: Introduction to the value set by Other Linker Flags

-ObjC: After this parameter is added, the linker loads all the Objective-C classes and classes in the static library to the final executable file.

-All_load: The linker will load all the target files to the executable files, but do not use this parameter at will! If you use more than one static library file and then use this parameter, you may encounter the ld: duplicate symbol error, because different library files may have the same target file, we recommend that you use the-force_load parameter when-ObjC is invalid.
-Force_load: the operations are the same as-all_load, but-force_load needs to specify the path of all the library files to be loaded. In this case, you just fully load a library file without affecting the On-Demand Loading of other library files

 

The configuration is complete.

Finally, check whether the sdk can be used.

This can be written in appdelegate.

Controller Used by the project in the AppDelegate. m file

# Import "ViewController. h"

Add the navigation controller in the following method, because to jump to the Controller in the sdk, you must

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];        ViewController *rootViewController = [[ViewController alloc] init];    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:rootViewController];    self.window.rootViewController = nav;    [self.window makeKeyAndVisible];    return YES;}

 

In viewController. m

Or, if you want to see more clearly, add a button and add a jump event to jump to the sdk, I will be lazy here.

 1 #import "ViewController.h" 2 #import "SDK.h" 3 #import "SDKViewController.h" 4  5 @interface ViewController () 6  7 @end 8  9 @implementation ViewController10 11 - (void)viewDidLoad {12     [super viewDidLoad];13     14     15     SDK *sdk = [[SDK alloc]init];16     [sdk sdkLog];17     18     SDKViewController *sdkCtl = [[SDKViewController alloc]init];19     [self.navigationController pushViewController:sdkCtl animated:YES];20 }21 22 @end

Compile and run

 

4. Solve the error. Complete.

Compile the project.

That's because the compilation packages of the Virtual Machine sdk are also different, such as i386, x86_64, arm, and arm64. This is the Charts of the package we need. framework is not correct. I will not elaborate on it here. I want to know the differences among Baidu i386, x86_64, arm, and arm64. The simplest and most direct solution here is what virtual machine is selected when compiling the sdk, the virtual machine used during the runtime, but if the sdk is compiled with 5s, 6, 6 plus, 6 s, and 6 s plus, these sdks can be used in these virtual machines, so there is no need to consider that much.

The static library created by framework can be the same as that created by..

To make all the general Virtual Machine sdk package can refer to the http://blog.csdn.net/lizhongfu2013/article/details/12648633

 

Finally, the task is printed.

SdkAction

The interface in the Controller in the sdk is displayed. Congratulations.

Looking at the content above, it seems very easy to know after several times of understanding it. This is also the case when frameword creates a static library, and the dynamic library is different, it is not recommended that you use your own dynamic library in the project. The app store will not pass the review, followed by the debug and release modes, when creating a real sdk, you should switch Debug to release in the Build Configuration of product-> scheme-> edit scheme and then compile and use it. This is the same as in the project, if all of them are complete, you should change them.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.