1

I'm doing a face recognition android application with opencv. When i try to run the project i get "Error:(3, 18) error: cannot find symbol class R" error. How can i solve this?

I'm trying to do a face recognition application and for that i'm using opencv. I wanted to try out a sample first so i followed few of the samples that were available. I downloaded opencv4.0.1 and imported to my app in android studio -> Next changed the opencv gradle according to my gradle settings -> gradle files were synced succeessfully without errors -> Next as the tutorial stated i added the module dependency to my application where i selected the opencv module as the dependency. Synced my gradle files. All was synced successfully. I tried to run the application but the comes the error " Error:(3, 18) error: cannot find symbol class R" following "Error:(48, 78) error: package R does not exist".

This is one of the tutorials i followed as i'm completely new to opencv : https://www.learn2crack.com/2016/03/setup-opencv-sdk-android-studio.html

I already tried, cleaning & building the project again, invalidating and restarting the project, checking xml errors & etc. But none worked.

And this error is coming in some opencv files which i have mentioned below.

package org.opencv.android;

import org.opencv.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;

public class CameraGLSurfaceView extends GLSurfaceView {

     private static final String LOGTAG = "CameraGLSurfaceView";

    public interface CameraTextureListener {
        /**
         * This method is invoked when camera preview has started. After this method is invoked
         * the frames will start to be delivered to client via the onCameraFrame() callback.
         * @param width -  the width of the frames that will be delivered
         * @param height - the height of the frames that will be delivered
       */
        public void onCameraViewStarted(int width, int height);

        /**
         * This method is invoked when camera preview has been stopped for some reason.
         * No frames will be delivered via onCameraFrame() callback after this method is called.
         */
         public void onCameraViewStopped();
Lucky
  • 11
  • 4
  • Possible duplicate of ["cannot resolve symbol R" in Android Studio](https://stackoverflow.com/questions/17054000/cannot-resolve-symbol-r-in-android-studio) – Zoe Mar 23 '19 at 11:18
  • unfortunately, that doesn't provide an answer to my question. When i create a normal android project without opencv it works fine. It runs fine too. But this error is coming in an opencv class. That's the problem. I'm not sure if it's something wrong with the opencv i got. – Lucky Mar 23 '19 at 14:14

1 Answers1

0

just replace :

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

with :

res.srcDirs = ['res']

you can use Ctrl+Shift+F to find this line of code in the android studio OR navigate to gradle file of the OpenCV library

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Techie Vineet
  • 131
  • 3
  • 2