Android Application With Camera2 Library Crash On Start For Sdk19
Solution 1:
I recently stumbled into the same issue. Diving deep into the CameraX code I found that CameraX is initialized in app startup through a content provider. Here is the content provider code where CameraX is being initialized.
publicfinalclassCamera2InitializerextendsContentProvider {
privatestaticfinalStringTAG="Camera2Initializer";
@OverridepublicbooleanonCreate() {
Log.d(TAG, "CameraX initializing with Camera2 ...");
CameraX.init(getContext(), Camera2AppConfig.create(getContext()));
returnfalse;
}
}
Im not very familiar with content providers but my first taught was, this is add at the manifest level? And indeed I was right. Looking at there manifest I found this
<manifestxmlns:android="http://schemas.android.com/apk/res/android"package="androidx.camera.camera2"><application><providerandroid:name=".Camera2Initializer"android:authorities="${applicationId}.camerax-init"android:exported="false"android:initOrder="100"android:multiprocess="true" /></application></manifest>
There manifest gets merged into ours which will include this content provider which in the other hand initializes CameraX, we want to avoid this. So one possible way of doing so is creating our own empty content provider and adding it to our manifest with the same name. This will override there content provider. You can look into https://developer.android.com/studio/build/manifest-merge for more detail about manifest merging.
So now with there content provider overriden hopefully you can call CameraX.init(getContext(), Camera2AppConfig.create(getContext())); only when the feature gets called and not on app startup.
Im hoping this gets fixed in later versions and allows us to initialize cameraX when we want to.
Post a Comment for "Android Application With Camera2 Library Crash On Start For Sdk19"