I have a project that has been using Camera2VideoJava. I am upgrading to API 29 (AndroidX) but now the Camera2VideoFragment.java file get the following errors:
Cannot resolve symbol 'v13'
for this line:
import android.support.v13.app.FragmentCompat;
Cannot resolve symbol 'FragmentCompat'
for this line:
implements View.OnClickListener, FragmentCompat.OnRequestPermissionsResultCallback, MediaRecorder.OnInfoListener {
The issue is that android.support.v13
does not get imported into my project anymore since AndroidX handles it. With updating to API 29 & AndroidX, typically the import is automatically suggested by Android Studio when it changes.
Initially expected solution:
The import (import android.support.v13.app.FragmentCompat;
) would typically change to something like import androidx.core.app.FragmentCompat;
or androidx.legacy.app.FragmentCompat
(as suggested here), which would resolve both errors above. However, neither import exists.
Potential Solution?
I believe the import is not suggested/does not exist because FragmentCompact was deprecated and now Fragment is recommended, so my only idea then would be to use Fragment instead of FragmentCompact, but that would create other issues with :
if (FragmentCompat.shouldShowRequestPermissionRationale(this, permission)) {
FragmentCompat.requestPermissions(this, VIDEO_PERMISSIONS, REQUEST_VIDEO_PERMISSIONS);
FragmentCompat.requestPermissions(parent, VIDEO_PERMISSIONS,REQUEST_VIDEO_PERMISSIONS);
since Fragment
does not have those methods. So then I would have to replace/rewrite the functionality for those, which.. may work? but I'm not questioning if I'm taking a long route for no good reason here.
Additional:
Is there a better solution to resolve the FragmentCompat
issue for Camera2VideoJava when updating to API 29?
The easiest and fastest way that worked for me: Changing all the references in the build.gradle to:
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
in the Camera2VideoFragment add:
import androidx.legacy.app.FragmentCompat;
&
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Changing the package name to mine in line 20 of the fragment_camera2_video.
<com.yyyy.xxxx.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
That is it - works like magic
By the way - in case that you are looking for a camera app template, I found out the following much better. It demonstrate camera2API, permissions & video capturing. but also allows you to make image capturing while recording. link Camera2Video+image capture
(You will need to change ContextCompat to ActivityCompat)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With