- 说在前面
Android Studio版本:3.2
操作系统(AS):Windows10
Android版本:5.0.2
摄像头:USB摄像头(640*480
贼辣鸡)
- 编译过程
1. 安装Android Studio
http://www.android-studio.org/
(貌似有的时候安装后不能再软件里下载SDK,不知道是为啥,而且Linux下好像没问题)
2. 下载源代码
https://github.com/saki4510t/UVCCamera
3. 打开项目
4. 打开最外面的build.gradle文件
注意这里的几个版本号:
supportLibVersion = '27.1.1' //大版本要和versionCompiler一致
commonLibVersion= '2.12.4' //暂时不管
versionBuildTool = '28.0.3' //选择SDK tools里面Android SDK build-tool 中已经安装的,如下图
versionCompiler = 27 //这两个貌似要大于26,选择如下图,没有的话安装一下(打勾->Apply)
versionTarget = 27
5. Sync Project
6. 安装NDK
这里不要使用SDK Manager进行安装,去官网下载NDK14
https://developer.android.google.cn/ndk/downloads/index.html
下载后解压到PATH/Android/Sdk目录下(可以改一下文件夹名)
7. 配置NDK
打开文件local.properties
File->Project Structure
8. build
9. Run
可能会出现以下错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.serenegiant.usbcameratest0, PID: 12421
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.serenegiant.usbcameratest0/com.serenegiant.usbcameratest0.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
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.usbcameratest0.MainActivity.onCreate(MainActivity.java:61)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
需要将
改成 android:theme="@style/Theme.AppCompat.Light.NoActionBar"
- 其他错误
E/UVCCamera: [30452*UVCCamera.cpp:172:connect]:could not open camera:err=-1
Process 'command '/root/Android/Sdk/ndk-bundle/ndk-build''
finished with non-zero exit value 2
上面这俩错误都需要将NDK版本改成14
- Test8截图
END