Android 导入官方UvcCamera

目录

  • 前言
  • 步骤
  • 测试
  • 项目结构
  • 结语

前言

借鉴了这个大佬的导入步骤:https://blog.csdn.net/qq_33446100/article/details/88775629
因为官方UvcCamera已经不维护了,问题还是有很多的,大家可以直接使用我处理好的UvcCamera库.也是从官方demo拉下修改了错误的代码.
链接:https://github.com/sunfusong/uvcCameraTest

步骤

  1. 导入libuvccamera:File–>New–>Import Module,找到libuvccamera的路径,点击Finish,因为还没配置,所以会报错.
  2. 接着照葫芦画瓢设置Module的build.gradle,Project的build.gradle,local.properties,同步一下就可以了.

Module的build.gradle:建议先完全按照我的sdk版本先,后面在自行修改

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.firefly.myapplication"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

......

    //添加,这里版本要和sdk版本对应
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    ......
    implementation project(path: ':libuvccamera')
}

Project的build.gradle:


buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

        //添加
        maven { url 'http://raw.github.com/saki4510t/libcommon/master/repository/' }
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

//添加
ext {
    supportLibVersion = '27.1.1'  // variable that can be referenced to keep support libs consistent
    commonLibVersion= '2.12.4'
    versionBuildTool = '28.0.3'
    versionCompiler = 27
    versionTarget = 27
    versionNameString = '1.0.0'
    javaSourceCompatibility = JavaVersion.VERSION_1_8
    javaTargetCompatibility = JavaVersion.VERSION_1_8
}

local.properties: 需要ndk14版本,资源以及下载方式:https://blog.csdn.net/qq_33446100/article/details/88775629

ndk.dir=/.../.../Android/Sdk/ndk-r14/android-ndk-r14b
sdk.dir=/.../.../Android/Sdk

测试

 private USBMonitor mUSBMonitor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mUSBMonitor=new USBMonitor(this,odcl);

    }
    private USBMonitor.OnDeviceConnectListener odcl=new USBMonitor.OnDeviceConnectListener() {
        @Override
        public void onAttach(UsbDevice device) {

        }

        @Override
        public void onDettach(UsbDevice device) {

        }

        @Override
        public void onConnect(UsbDevice device, USBMonitor.UsbControlBlock ctrlBlock, boolean createNew) {

        }

        @Override
        public void onDisconnect(UsbDevice device, USBMonitor.UsbControlBlock ctrlBlock) {

        }

        @Override
        public void onCancel(UsbDevice device) {

        }
    };

项目结构

Android 导入官方UvcCamera_第1张图片

结语

sdk版本配置先完全按照我的来,导入好了能用后在根据自己情况更改,因为关于这些配置具体含义我还不太了解,那时遇到问题,直接百度自己摸索,所以以上不懂的地方直接去百度搜下吧.
想学习uvcCamera的,可以先看官方demo,了解下流程.
后面会写一遍关于 uvcCamera的多路预览文章,支持多usb Camera同时预览,支持设置分辨率,格式,预览方向,Fps,和拍照,以及热拔插.

Android 导入官方UvcCamera_第2张图片

你可能感兴趣的:(Android,uvcCamera)