Android NDK中静态库和共享库之间的区别?

时间:2022-01-16 02:50:54

I'm new to Android's NDK and I don't understand the differences between static and shared libraries. What are they, and when would I choose one type over the other?

我是Android NDK的新手,我不了解静态库和共享库之间的区别。它们是什么,何时我会选择一种类型而不是另一种类型?

2 个解决方案

#1


51  

The term shared library is not a perfect fit regarding Android's NDK, because in many cases the .so libraries aren't actually shared between applications. It's better to classify the libraries that the NDK builds as static and dynamic.

术语共享库并不适合Android的NDK,因为在许多情况下,.so库实际上并不在应用程序之间共享。最好将NDK构建的库分类为静态和动态。

Every Android application is a Java application, and the only entry point for the NDK code is loading it as a dynamic library and call it trough JNI.

每个Android应用程序都是一个Java应用程序,NDK代码的唯一入口点是将其作为动态库加载并通过JNI调用它。

Static libraries are an archives of compiled object files. They get bundled in other libraries at build time. Unused portions of code from static libraries are stripped by the NDK to reduce total size.

静态库是编译的目标文件的档案。它们在构建时捆绑在其他库中。 NDK剥离来自静态库的未使用部分代码以减小总大小。

Dynamic libraries are loaded at runtime from separate files. They can contain static libraries that they are dependent on or load more dynamic libraries.

动态库在运行时从单独的文件加载。它们可以包含它们所依赖的静态库或加载更多动态库。

So what you actually need for Android development is at least one shared library, that will be called from Java code, and linked with it's dependencies as static libraries preferably.

因此,Android开发实际需要的是至少一个共享库,它将从Java代码调用,并最好与它的依赖关系作为静态库链接。

#2


1  

Native shared libraries: The NDK builds these libraries, or .so files, from your native source code. Native static libraries: The NDK can also build static libraries, or .a files, which you can link against other libraries.

本机共享库:NDK从本机源代码构建这些库或.so文件。本机静态库:NDK还可以构建静态库或.a文件,您可以将其链接到其他库。

This is according to NDK Documentation

这是根据NDK文档

#1


51  

The term shared library is not a perfect fit regarding Android's NDK, because in many cases the .so libraries aren't actually shared between applications. It's better to classify the libraries that the NDK builds as static and dynamic.

术语共享库并不适合Android的NDK,因为在许多情况下,.so库实际上并不在应用程序之间共享。最好将NDK构建的库分类为静态和动态。

Every Android application is a Java application, and the only entry point for the NDK code is loading it as a dynamic library and call it trough JNI.

每个Android应用程序都是一个Java应用程序,NDK代码的唯一入口点是将其作为动态库加载并通过JNI调用它。

Static libraries are an archives of compiled object files. They get bundled in other libraries at build time. Unused portions of code from static libraries are stripped by the NDK to reduce total size.

静态库是编译的目标文件的档案。它们在构建时捆绑在其他库中。 NDK剥离来自静态库的未使用部分代码以减小总大小。

Dynamic libraries are loaded at runtime from separate files. They can contain static libraries that they are dependent on or load more dynamic libraries.

动态库在运行时从单独的文件加载。它们可以包含它们所依赖的静态库或加载更多动态库。

So what you actually need for Android development is at least one shared library, that will be called from Java code, and linked with it's dependencies as static libraries preferably.

因此,Android开发实际需要的是至少一个共享库,它将从Java代码调用,并最好与它的依赖关系作为静态库链接。

#2


1  

Native shared libraries: The NDK builds these libraries, or .so files, from your native source code. Native static libraries: The NDK can also build static libraries, or .a files, which you can link against other libraries.

本机共享库:NDK从本机源代码构建这些库或.so文件。本机静态库:NDK还可以构建静态库或.a文件,您可以将其链接到其他库。

This is according to NDK Documentation

这是根据NDK文档