Generate .a static library for Android/iOS

range36rus 1 Reputation point
2021-03-28T20:33:28.887+00:00

I want try Xamarin.Forms for developing static library, which include: gui (activity for Android/storyboard for iOS) and mini - business logic. I downloaded module Xamarin.Forms for Visual Studio (windows) and create simple project Xamarin.Forms. He is include library-dll, which is shared projects Android and iOS, and Android app, and iOS app. I compiled project for Android and this is successed. But, shared library for Android and iOS have expansion *.dll, but not *.so(Android) or *.dylib(iOS). I checked, at compilation dll library converting to *.so and pack to apk (Android). Probably, same is happening at compiling application for iOS. I want compiling shared library for Android and iOS to static library *.a, for Android for four arch (arm64-v8a, armebi-v7, a, x86, x86_64) and iOS(armv7, armv7s, arm64, i386, x86_64). Why do I need it? I already have apk (big project) and ipa (big project), and start development based on Xamarin.Forms will take al many time. Possible it? If compilation static library real, then how call code of static library on Android (java or c++) and iOS (obj-c or c++ or swift). Thanks!

P.S.: if compiling in static library impossible, then how compiling dynamic library (Android and iOS)?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,292 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-03-29T07:33:00.417+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    I want compiling shared library for Android and iOS to static library *.a, for Android for four arch (arm64-v8a, armebi-v7, a, x86, x86_64) and iOS(armv7, armv7s, arm64, i386, x86_64). Why do I need it?

    Different Android devices use different CPUs, which in turn support different instruction sets. Each combination of CPU and instruction set has its own Application Binary Interface (ABI). An ABI includes the following information:

    • The CPU instruction set (and extensions) that can be used.
    • The endianness of memory stores and loads at runtime. Android is always little-endian.
    • Conventions for passing data between applications and the system, including alignment constraints, and how the system uses the stack and registers when it calls functions.
    • The format of executable binaries, such as programs and shared libraries, and the types of content they support. Android always uses ELF. For more information, see ELF System V Application Binary Interface.
    • How C++ names are mangled. For more information, see Generic/Itanium C++ ABI.

    For more details, you can check: https://developer.android.com/ndk/guides/abis

    Update:

    You can create library by using visual studio. The steps are : clicke on New project ->seletc Class Library in your visual studio.

    For this, you can check the offical document :

    Walkthrough: Create and use a static library

    and

    Walkthrough: Create and use your own Dynamic Link Library (C++)

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.