引言 {#引言}
最近项目中要使用到USB摄像头的功能,然后就找到了UVCCamera
这个开源项目,clone下来后,编译运行要报错,下面带你一步步解决错误,成功运行项目。
第一个错误: {#第一个错误:}
|-----------|---------------------------------------------------------|
| 1
| Could not resolve com.serenegiant:common:2.12.4
|
解决方法:
打开project的build.gradle,替换掉原来的maven url,如下:
|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10
| allprojects { repositories { // google() maven { url 'https://maven.google.com' } jcenter() //maven { url 'http://raw.github.com/saki4510t/libcommon/master/repository/' } //使用下面的maven url即可 maven { url 'https://gitee.com/liuchaoya/libcommon/raw/master/repository/' } } }
|
第二个错误: {#第二个错误:}
|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3
| CreateProcess error=2, 系统找不到指定的文件。 Execution failed for task ':libuvccamera:ndkBuild'. A problem occurred starting process 'command 'null/ndk-build.cmd''
|
解决方法:
打开设置,确保如图已下载NDK,没有下载的就选一个下载,然后点击如下图标,打开设置,设置好NDK的位置即可。
太新的版本可能会报错,建议适当降低NDK版本,我这边使用的是:
ndk\21.4.7075529
第三个错误: {#第三个错误:}
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2
| Execution failed for task ':libuvccamera:ndkBuild'. Process 'command 'G:\win7\developSoftware\androidSDK\ndk\21.0.6113669/ndk-build.cmd'' finished with non-zero exit value 2
|
解决方法:
- 打开
Application.mk
,修改APP_ABI
, - 修改前 APP_ABI := armeabi armeabi-v7a x86 mips
- 修改后 APP_ABI := armeabi-v7a x86
第四个错误: {#第四个错误:}
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6
| Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at com.serenegiant.usbcameratest.MainActivity.onCreate(MainActivity.java:61)
|
解决方法:
- 打开
AndroidManifest.xml
,修改application
的theme
: - 修改前 android:theme="@style/AppTheme"
- 修改后 android:theme="@style/Theme.AppCompat"
第五个错误: {#第五个错误:}
|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Caused by: android.view.InflateException: Binary XML file line #32 in com.serenegiant.usbcameratest:layout/activity_main: Binary XML file line #32 in com.serenegiant.usbcameratest:layout/activity_main: Error inflating class com.serenegiant.widget.SimpleUVCCameraTextureView Caused by: android.view.InflateException: Binary XML file line #32 in com.serenegiant.usbcameratest:layout/activity_main: Error inflating class com.serenegiant.widget.SimpleUVCCameraTextureView Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:858) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:538) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at com.serenegiant.usbcameratest.MainActivity.onCreate(MainActivity.java:61) at android.app.Activity.performCreate(Activity.java:7893) at android.app.Activity.performCreate(Activity.java:7880) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3287) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3461) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2048) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:227) at android.app.ActivityThread.main(ActivityThread.java:7573) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:953) Caused by: java.lang.UnsupportedOperationException: TextureView doesn't support displaying a background drawable com.serenegiant.usbcameratest E/AndroidRuntime: at android.view.TextureView.setBackgroundDrawable(TextureView.java:326) at android.view.View.setBackground(View.java:23033) at android.view.View.<init>(View.java:5869) at android.view.View.<init>(View.java:5265) at android.view.TextureView.<init>(TextureView.java:166) at com.serenegiant.widget.SimpleUVCCameraTextureView.<init>(SimpleUVCCameraTextureView.java:50) at com.serenegiant.widget.SimpleUVCCameraTextureView.<init>(SimpleUVCCameraTextureView.java:46)
|
解决方法:
打开activity_main.xml
,把SimpleUVCCameraTextureView
的android:background="#ff000000"
这一句删掉即可。
小结 {#小结}
解决完以上5个问题,就可以把项目运行起来了。
不过APP在运行时可能会出现闪退的情况,请看以下相关的链接:
推荐链接:解决UVC Camera拔出USB摄像头APP崩溃(闪退)的问题
推荐链接:Android UVC Camera 闪退问题解决方法
UVCCamera相关内容 {#UVCCamera相关内容}
- Android UVCCamera 简介
- Android UVCCamera基本库介绍
- Android UVCCamera调用过程介绍
- 解决Android UVCCamera项目编译和运行报错的问题
- Android UVCCamera扫描USB Device的过程和原理分析
- Android UVCCamera闪退问题解决方法
- 解决UVCCamera拔出USB摄像头APP崩溃(闪退)的问题
- Android中多USB摄像头解决方案 ------ UVCCamera
- UVCCamera源码分析(一)
- UVCCamera源码分析(二)
- UVCCamera源码分析(三)
- UVCCamera源码分析(四)
- UVCCamera源码分析(五)
参考链接:https://blog.csdn.net/hanye2020/article/details/108505636