Android的工作室,OpenCV的罐子,抛出java.lang.ClassNotFoundException:org.opencv.R $设置样式 [英] Android Studio, OpenCV jar, java.lang.ClassNotFoundException: org.opencv.R$styleable

查看:1437
本文介绍了Android的工作室,OpenCV的罐子,抛出java.lang.ClassNotFoundException:org.opencv.R $设置样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关如何使用OpenCV的与Android工作室涉及进口OpenCV的模块项目在网络上的大多数例子。不过,我想使用的OpenCV作为一个罐子,让我避免弄乱我的源代码控制库与OpenCV的副本。

Most examples on the web regarding how to use OpenCV with Android Studio involve importing the OpenCV module into your project. However, I am trying to use OpenCV as a jar so that I avoid cluttering my source control repository with copies of OpenCV.

因此​​,这些都是我做我的应用程序被称为应用。

So these are the steps I am doing for my app called 'app'.

一个。在创建/项目/应用一个libs目录。把OpenCV的罐子在那里。也把OpenCV的本地库在那里,在子目录。

A. Create a libs directory under /Project/apps. Put the OpenCV jar there. Also put the opencv native libs there, in sub-directories.

乙。在/Project/app/build.gradle执行以下操作

B. In /Project/app/build.gradle do the following

把这些线在顶部:

repositories { flatDir { dirs 'libs'    } }

把这些线在android部分:

Put these lines in the android section:

sourceSets.main.jniLibs.srcDirs = ['libs']

将这个线的依赖性部分:

Put this line in the dependencies section:

    compile fileTree(dir: 'libs', include: ['*.jar'])

℃。添加这些行AndroidManifest.xml中,应用程序标记之后。

C. Add these lines to AndroidManifest.xml, after the application tag.

    <uses-sdk android:minSdkVersion="9"/>
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>

Ð。不知道这是否是必需的或没有,我已经试过与无 - 似乎没有什么区别:我添加以下行应用程序标签中在AndroidManifest.xml:

D. Not sure if this is required or not, I've tried with and without - seems to make no difference: I add the following line inside the application tag in AndroidManifest.xml:

        <uses-library android:name="org.opencv.android.JavaCameraView" />

电子。最后,这是我的布局XML:

E. Finally here is my layout xml:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:opencv="http://schemas.android.com/apk/lib/org.opencv.android.JavaCameraView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <org.opencv.android.JavaCameraView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone"
        android:id="@+id/main_activity_surface_view"
        opencv:show_fps="true"
        opencv:camera_id="any" />

    </LinearLayout>

这一切工作正常。我可以在我的活动中引用OpenCV的没有错误。然而,布局编辑器提供了以下错误:以下类不能被实例化:org.opencv.android.JavaCameraView。抛出java.lang.ClassNotFoundException:org.opencv.R $设置样式

This all works fine. I can reference OpenCV in my activity without errors. However the layout editor gives the following error: The following classes could not be instantiated: org.opencv.android.JavaCameraView. java.lang.ClassNotFoundException: org.opencv.R$styleable.

如果这只是一个显示问题也许我可以不理它,但是当我运行出现类似的错误。

If it was just a rendering problem perhaps I could ignore it, however a similar error occurs when I run it.

我是什么失踪?

(我知道有些类似的问题,在SO对于这个错误,但他的解决方案涉及导入整个模块,它确实工作,但为precisely我想要避免的。)

(I am aware of a somewhat similar question in SO regarding this error, but his solution involves importing the whole module which does indeed work but is precisely what I'm trying to avoid.)

推荐答案

的错误消息:

以下类不能被实例化:org.opencv.android.JavaCameraView。抛出java.lang.ClassNotFoundException:org.opencv.R $设置样式

The following classes could not be instantiated: org.opencv.android.JavaCameraView. java.lang.ClassNotFoundException: org.opencv.R$styleable

指示操作的构建当没有找到的OpenCV资源。如果你的OpenCV包括作为一个jar库,这将是问题的根源 - 罐子没有资源在他们的

indicates that it isn't finding OpenCV resources when doing the build. If you're including OpenCV as a jar library, that will be the source of the problem -- jars don't have resources in them.

的解决方案是构建的OpenCV为AAR,因为AARS做有资源。构建库模块,它编译成AAR,到处重用存档需要。

The solution is to build OpenCV as an AAR, because AARs do have resources. Construct a library module for it, compile it to AAR, and reuse that archive everywhere you need to.

这篇关于Android的工作室,OpenCV的罐子,抛出java.lang.ClassNotFoundException:org.opencv.R $设置样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆