5

I'm addind openCV native lib into my (in developpement) project. I'm following this guide. I have troubles at the very last step, while building my project, in the OpenCV-android-sdk folder : CameraGLSurfaceView.java got error cannot find symbol variable styleable at R.styleable.CameraBridgeViewBase.

I have tried to add an attrs.xml file in my values folder with this content :

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <declare-styleable name = "CameraBridgeViewBase" >
        <attr name="show_fps" format="boolean"/>
        <attr name="camera_id" format="integer" >
            <enum name="any" value="-1" />
            <enum name="back" value="2" />
            <enum name="front" value="1" />
        </attr>
    </declare-styleable>
</resources>

As it said in this quite similar error. But nothing changed when I rebuild my project.

Community
  • 1
  • 1
Jérémy
  • 1,790
  • 1
  • 24
  • 40
  • Check the answer here: https://stackoverflow.com/questions/54316458/problems-at-r-styleable-while-integrating-native-opencv-to-android-studio/66456218#66456218 – Miguel Tomás Mar 03 '21 at 11:45

5 Answers5

13

In opencv 4 just change

res.srcDirs = ['/build/master_pack-android/opencv/modules/java/android_sdk/android_gradle_lib/res']

to

res.srcDirs = ['res']

in the gradle file

GrAnd
  • 10,141
  • 3
  • 31
  • 43
Oswaldo Jaime
  • 131
  • 1
  • 2
  • 1
    you did the trick man :) trying to find solution since last day :) thanks – Ashu Kumar Apr 08 '19 at 04:20
  • I've been working on this for 2 days. This is what finally fixed it... wtf –  May 19 '19 at 07:27
  • very great i was trying to import module but attrs file got error i look many times it was showing in the explorer but not in studio after adding this line help me a lot thanks so much you deserve 1000 points for this answer.. – Najaf Ali Nov 02 '20 at 07:22
6

In openCv4, you need to make some changes in gradle file of your OPENCV folder(opencv/build.gradle). Your openCv folder is present in root directory.

ApplicationName->OpenCv->res

Just copy the path and update your gradle file as:

sourceSets {
    main {
                jniLibs.srcDirs = ['../../jni']
                java.srcDirs = ['src']  
                aidl.srcDirs = ['src']
                **res.srcDirs = ['/path-to-your-application/
    ApplicationName/openCv4/res']**
                manifest.srcFile 'AndroidManifest.xml'
            }
  }

I hope this will help!

Ankur
  • 61
  • 4
1

This also happened to me with OpenCV4, Try to download OpenCV3.4

Dov
  • 316
  • 1
  • 3
  • 13
1

after importing the module to my project i was getting the error in styleable files as my res folder was not showing to me in android studio but it was showing in file explorer then i know it is something path error in the code.

my error was like this. i was getting this error

how i solved it i just go into the gradle file of open cv library and just change the res dirctory path

from res.srcDirs = ['/build/master_pack-android/opencv/modules/java/android_sdk/android_gradle_lib/res']

to

res.srcDirs = ['res']

and then sync it start working for me and res folder appear in the project file.

start appear

enter image description here

Najaf Ali
  • 1,433
  • 16
  • 26
0

In openCv4 on Android Studio 4.2 C15 (I'm on SDK 30), the Gradle file of your OPENCV folder(OpenCV/build.Gradle) needs to be like this. assuming your openCv folder is present in the root directory.

ApplicationName->OpenCv->res

Just copy the path and update your gradle file as:

sourceSets {
    main {
                jniLibs.srcDirs = ['build\\intermediates\\library_jni\\debug\\jni']
                java.srcDirs = ['java\\src']
                aidl.srcDirs = ['src']
                res.srcDirs = ['java\\res']
                manifest.srcFile 'java\\AndroidManifest.xml'
            }
  }
Miguel Tomás
  • 1,714
  • 1
  • 13
  • 23