1

I did everything according to the instruction OpenCv with Android studio 1.3+ using new gradle - undefined reference. But I have error "could not load library "libgnustl_shared.so"". Who knows how can I solve this problem?

My build.gradle file:

apply plugin: '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")
            }
Community
  • 1
  • 1
imported_lis
  • 325
  • 3
  • 17

2 Answers2

1

I downloaded a set of libraries libstdc++ for Linux and put libgnustl_shared.so in the jniLibs folder. And called System.loadLibrary("gnustl_shared") before loading other libraries. It works!

imported_lis
  • 325
  • 3
  • 17
0

If you don't mind moving up in version with gradle experimental, I posted an example of my build script that links in opencv and uses gnustl_shared here: Migrating project to new experimental gradle plugin 0.6.0-alpha3 -> 0.6.0-alpha5

Community
  • 1
  • 1