I have javacv and opencv on Android Studio. Following codes are my activity_main.xml;
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="android.javacv.MainActivity">
<org.bytedeco.javacv.android.example.CvCameraPreview
android:id="@+id/camera_view"
android:layout_width="576dp"
android:layout_height="295dp"
android:layout_gravity="center"
app:camera_type="front"
app:scale_type="full"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
tools:ignore="MissingConstraints" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@android:drawable/screen_background_light_transparent"
android:backgroundTint="@android:drawable/screen_background_dark_transparent"
android:visibility="visible"
app:srcCompat="@android:drawable/ic_menu_camera"
tools:ignore="ContentDescription,MissingConstraints"
tools:layout_editor_absoluteX="520dp"
tools:layout_editor_absoluteY="129dp" />
And following codes are attrs.xml;
<resources>
<declare-styleable name = "CameraBridgeViewBase" >
<attr name="show_fps" format="boolean"/>
<attr name="camera_id" format="integer" >
<enum name="any" value="-1" />
<enum name="back" value="99" />
<enum name="front" value="98" />
</attr>
</declare-styleable>
And Android Studio compiler outputs ;
C:\Users\Asus\Desktop\Android Project\proj\javacv\app\src\main\res\layout-v21\activity_main.xml
Error:(10) No resource identifier found for attribute 'camera_type' in package 'android.javacv'
Error:(10) No resource identifier found for attribute 'scale_type' in package 'android.javacv'
C:\Users\Asus\Desktop\Android Project\proj\javacv\app\build\intermediates\res\merged\debug\layout-v21\activity_main.xml
Error:(10) No resource identifier found for attribute 'camera_type' in package 'android.javacv'
Error:(10) No resource identifier found for attribute 'scale_type' in package 'android.javacv'
Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.process.ProcessException: Failed to execute aapt
I found a solution here https://stackoverflow.com/a/28829264/1751507
Assuming we both use bytedeco's example called CvCameraPreview.java, around line 139, I also had to change
int camType = array.getInt(R.styleable.CvCameraPreview_camera_type, CAMERA_BACK);
int scaleType = array.getInt(R.styleable.CvCameraPreview_scale_type, SCALE_FIT);;
to
int camType = 99;
int scaleType = 1;
to make it all work. Thanks for your code too, it helped me! Now I see a live cv-enabled picture and the adventure can begin :)
PS: My Environment is Android Studio 2.3.3, the project is compileSdkVersion and buildToolsVersion 25, my phone is Android 7.1.1.