简体   繁体   English

如何使用 gradle 以编程方式将 libc++_shared.so 包含到我的 APK 中?

[英]How to include libc++_shared.so into my APK programmatically with gradle?

Updated in project:在项目中更新:

  • Gstreamer 1.14.5 -> Gstreamer 1.18.0 Gstreamer 1.14.5 -> Gstreamer 1.18.0

  • NDKr16 -> NDKr21.3.6528147 NDKr16 -> NDKr21.3.6528147

  • build:gradle:3.5.3 -> build:gradle:4.1.0 build:gradle:3.5.3 -> build:gradle:4.1.0

  • buildToolsVersion 29.0.3构建工具版本 29.0.3

     compileSdk: 29, minSdk : 26, targetSdk : 29, material : "1.2.1", constraint: "2.0.2", ktx : "1.1.0", espresso : "3.1.0", mockito : "2.9.0", junit : "4.13.1"

This updates produce an issue:此更新产生了一个问题:

java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found
    at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
    at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
    at java.lang.System.loadLibrary(System.java:1667)
    at com.kbnt.naparnik.client.MainActivity.<clinit>(MainActivity.java:103)
    at java.lang.Class.newInstance(Native Method) 
...

Project building correctly but when I run app it crash with issue项目构建正确,但当我运行应用程序时,它会因问题而崩溃

Android.mk file:安卓.mk文件:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := client
LOCAL_SRC_FILES := client.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)

ifndef GSTREAMER_ROOT_ANDROID
    $(error GSTREAMER_ROOT_ANDROID is not defined!)
endif
ifeq ($(TARGET_ARCH_ABI),armeabi)
    GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/arm
else ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/armv7
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
    GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/arm64
else ifeq ($(TARGET_ARCH_ABI),x86)
    GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/x86
else ifeq ($(TARGET_ARCH_ABI),x86_64)
    GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/x86_64
else
    #$(error Target arch ABI not supported: $(TARGET_ARCH_ABI))
    GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/armv7
endif

GSTREAMER_NDK_BUILD_PATH  := $(GSTREAMER_ROOT)/share/gst-android/ndk-build/
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk

GSTREAMER_PLUGINS         :=  $(GSTREAMER_PLUGINS_CORE)         \
                             $(GSTREAMER_PLUGINS_CODECS)        \
                             $(GSTREAMER_PLUGINS_EFFECTS)       \
                             $(GSTREAMER_PLUGINS_NET)           \
                             $(GSTREAMER_PLUGINS_CAPTURE)       \
                             $(GSTREAMER_PLUGINS_PLAYBACK)      \
                             $(GSTREAMER_PLUGINS_SYS)

GSTREAMER_EXTRA_DEPS      := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk

Application.mk file:应用程序.mk 文件:

APP_STL := c++_shared
APP_PLATFORM := android-26

I find note in documentation https://developer.android.com/ndk/guides/cpp-support#c_runtime_libraries :我在文档https://developer.android.com/ndk/guides/cpp-support#c_runtime_libraries 中找到注释:

libc++ is not a system library. libc++ 不是系统库。 If you use libc++_shared.so, it must be included in your APK.如果您使用 libc++_shared.so,它必须包含在您的 APK 中。 If you're building your application with Gradle this is handled automatically.如果您使用 Gradle 构建应用程序,则会自动处理。

I understand that it building incorrectly, because my APK don`t include library我知道它构建不正确,因为我的 APK 不包含库

How to include libc++_shared.so into my APK programmatically with gradle?如何使用 gradle 以编程方式将 libc++_shared.so 包含到我的 APK 中?

Structure of project项目结构

在此处输入图片说明

app/build.gradle:应用程序/build.gradle:

android {
compileSdkVersion versions.compileSdk
defaultConfig {
    ...
    externalNativeBuild {
        ndkBuild {
            if (System.getenv("GSTREAMER_ROOT_ANDROID") == null)
                throw new GradleException("Define GSTREAMER_ROOT_ANDROID environment variable")
            targets "client"
            abiFilters "armeabi-v7a", 'arm64-v8a'
        }
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
externalNativeBuild {
    ndkBuild {
        path 'src/main/jni/Android.mk'
    }
}
ndkVersion '21.3.6528147'
buildToolsVersion '29.0.3'
...

I refactored my Android.mk GSTREAMER_PLUGINS field and add GSTREAMER_EXTRA_LIBS .我重构了我的 Android.mk GSTREAMER_PLUGINS字段并添加GSTREAMER_EXTRA_LIBS I replaced categories with specific plugins that using in my project and it solve my problem.我用我的项目中使用的特定插件替换了类别,它解决了我的问题。

...
GSTREAMER_PLUGINS   := coreelements udp rtpmanager rtp opengl playback
GSTREAMER_EXTRA_LIBS    := -liconv
...

Looks like some plugins in categories have a bugs看起来类别中的某些插件有错误

Thank you @NikolayKhilyuk for trying to help me谢谢@NikolayKhilyuk 试图帮助我

It looks like targets "client" issue.看起来像targets "client"问题。 Try to remove it at all or specify NDK_APPLICATION_MK :尝试完全删除它或指定NDK_APPLICATION_MK

...
    externalNativeBuild {
        ndkBuild {
            ...
            targets "client"
            arguments "NDK_APPLICATION_MK:=Application.mk"
            ...
        }
    }
}

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Clang 链接 .so 库 libc++_shared.so - Clang linking .so library libc++_shared.so OpenCV Android 中的实现 - 未找到“libc++_shared.so” - OpenCV Implementation in Android - "libc++_shared.so" not found 在 OpenCV android 应用程序中启用“libc++_shared.so” - enabling "libc++_shared.so" to be enabled in the OpenCV android application 我在哪里可以下载 Android 的 libc++_shared.so? - Where can I download libc++_shared.so for Android? 是AOSP的libc ++。所以和NDK的libc ++ _ shared.so一样吗? - Is AOSP's libc++.so the same as NDK's libc++_shared.so? Android Studio CMake - 共享库缺少 libc++_shared.so? CMake 可以捆绑这个吗? - Android Studio CMake - shared library missing libc++_shared.so? Can CMake bundle this? Android NDK无法加载libc ++ _ shared.so,获取“无法定位符号&#39;rand&#39;引用 - Android NDK cannot load libc++_shared.so, gets "cannot locate symbol 'rand' reference 从输入中找到路径 'lib/arm64-v8a/libc++_shared.so' 的 2 个文件...-react native - 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs...-react native 如何包括许多共享库.so以构建android apk - How to include many shared libraries .so to build android apk 如何使用Gradle将版本* .so文件包含到APK中? - How to include versioned *.so file into apk using Gradle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM