【问题标题】:I get a "Cannot resolve symbol class R" error after adding opencv module dependency to my project and trying to run the application将 opencv 模块依赖项添加到我的项目并尝试运行应用程序后,出现“无法解析符号类 R”错误
【发布时间】:2019-03-23 11:06:13
【问题描述】:

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

我正在尝试做一个人脸识别应用程序,为此我正在使用 opencv。我想先试用一个样本,所以我跟踪了一些可用的样本。 我下载了opencv4.0.1并在android studio中导入了我的应用程序->接下来根据我的gradle设置更改了opencv gradle->gradle文件成功同步而没有错误->接下来,正如教程所述,我将模块依赖项添加到我的应用程序中我选择了 opencv 模块作为依赖项。 同步了我的 gradle 文件。全部同步成功。 我尝试运行应用程序,但出现错误“错误:(3, 18) 错误:找不到符号类 R”,紧随“错误:(48, 78) 错误:包 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();

【问题讨论】:

  • 不幸的是,这并不能回答我的问题。当我创建一个没有 opencv 的普通 android 项目时,它工作正常。它也运行良好。但是这个错误出现在 opencv 类中。那就是问题所在。我不确定我得到的opencv是否有问题。

标签: android android-studio opencv opencv4android


【解决方案1】:

只需替换:

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 文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 2021-05-01
    • 2015-02-26
    • 2012-11-01
    • 1970-01-01
    相关资源
    最近更新 更多