将opencv模块依赖项添加到我的项目并尝试运行该应用程序后,出现“无法解析符号类R”错误

时间:2019-03-23 11:06:14

标签: android android-studio opencv opencv4android

我正在用opencv做一个人脸识别android应用程序。当我尝试运行项目时,出现“错误:(3,18)错误:找不到符号类R”错误。我该如何解决?

我正在尝试做一个人脸识别应用程序,为此我正在使用opencv。我想先尝试一个样本,所以我关注了一些可用的样本。 我下载了opencv4.0.1并导入到Android Studio中的应用程序中->接下来根据我的gradle设置更改了opencv gradle-> gradle文件已成功同步,没有错误->接下来,如本教程所述,我在我的应用程序中添加了模块依赖性我选择了opencv模块作为依赖项。 同步了我的gradle文件。全部同步成功。 我尝试运行该应用程序,但在“错误:(48,78)错误:程序包R不存在”之后出现错误“错误:(3,18)错误:找不到符号类R。”

这是我遵循的教程之一,因为我是opencv的新手:https://www.learn2crack.com/2016/03/setup-opencv-sdk-android-studio.html

我已经尝试过,再次清理和构建项目,使项目无效并重新启动,检查xml错误等。

这个错误正在我下面提到的一些opencv文件中出现。

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();

1 个答案:

答案 0 :(得分:0)

只需替换:

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

与:

res.srcDirs = ['res']

您可以使用Ctrl + Shift + F在android studio中找到此行代码,或导航到OpenCV库的gradle文件