Android Studio NDK:无法加载库" libgnustl_shared.so"

时间:2016-01-25 13:03:15

标签: android c++ opencv stl android-ndk

我根据指令OpenCv with Android studio 1.3+ using new gradle - undefined reference做了一切。但我有错误"无法加载库" libgnustl_shared.so""。谁知道我该如何解决这个问题?

我的build.gradle文件:

申请插件:' com.android.model.application'

            model {
                android {
                    compileSdkVersion = 23
                    buildToolsVersion = "23.0.2"

                    defaultConfig.with {
                        applicationId = "com.atapy.wisetrend3"
                        minSdkVersion.apiLevel = 11
                        targetSdkVersion.apiLevel = 23
                        versionCode = 1
                        versionName = "1.0"

                    }
                }

                android.ndk {
                    moduleName = "rrdecoder"
                    cppFlags.add("-std=c++11")
                    cppFlags.add("-fexceptions")
                    cppFlags.add("-I${file("D:/Android/OpenCV-3.1.0-android-sdk/OpenCV-android-sdk/sdk/native/jni/include")}".toString())
                    ldLibs.addAll(["android", "EGL", "GLESv2", "dl", "log", "z"])
                    stl = "gnustl_shared"
                }

                android.buildTypes {
                    release {
                        minifyEnabled = false
                        proguardFiles.add(file("proguard-rules.txt"))
                    }
                }

                android.productFlavors {
                    create("arm") {
                        ndk.with{
                            abiFilters.add("armeabi")

                            File curDir = file('./')
                            curDir = file(curDir.absolutePath)
                            String libsDir = curDir.absolutePath + "\\src\\main\\jniLibs\\armeabi\\"

                            ldLibs.add(libsDir + "libopencv_core.a")
                            ldLibs.add(libsDir + "libopencv_highgui.a")
                            ldLibs.add(libsDir + "libopencv_imgproc.a")
                            ldLibs.add(libsDir + "libopencv_java3.so")
                            ldLibs.add(libsDir + "libopencv_ml.a")

                        }
                    }
                    create("armv7") {
                        ndk.with {
                            abiFilters.add("armeabi-v7a")

                            File curDir = file('./')
                            curDir = file(curDir.absolutePath)
                            String libsDir = curDir.absolutePath + "\\src\\main\\jniLibs\\armeabi-v7a\\"
                            ldLibs.add(libsDir + "libopencv_core.a")
                            ldLibs.add(libsDir + "libopencv_highgui.a")
                            ldLibs.add(libsDir + "libopencv_imgproc.a")
                            ldLibs.add(libsDir + "libopencv_java3.so")
                            ldLibs.add(libsDir + "libopencv_ml.a")
                            ldLibs.add(libsDir + "libopencv_ts.a")

                        }
                    }
                }
                android.sources {
                    main {
                        jni {
                            source {
                                srcDirs += ['src/main/jniMy']
                            }
                        }
                    }
                }
            }
            dependencies {
                compile fileTree(dir: "libs", include: [$/*.jar/$])
                compile "com.android.support:appcompat-v7:23.1.1"
                compile project(":openCVLibrary310")
            }

2 个答案:

答案 0 :(得分:0)

如果您不介意使用gradle实验向上移动,我发布了一个构建脚本示例,该脚本在opencv中链接并在此处使用gnustl_shared: Migrating project to new experimental gradle plugin 0.6.0-alpha3 -> 0.6.0-alpha5

答案 1 :(得分:0)

我为Linux下载了一组libstdc ++库,并将libgnustl_shared.so放在jniLibs文件夹中。并在加载其他库之前调用System.loadLibrary(" gnustl_shared")。它有效!