Custom AppComponentFactory Fails to Instantiate Application - android

I am attempting to implement a custom AppComponentFactory to create my Application and Activity instances using non-zero arg constructors (Dagger based constructor dependency injection), but my app fails to launch because my custom Application subtype does not have a zero arg constructor, and the stack trace implies my custom AppComponentFactory is not being used.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.domain.app, PID: 32670
java.lang.RuntimeException: Unable to instantiate application com.domain.app.CustomApplication: java.lang.InstantiationException: java.lang.Class<com.domain.app.CustomApplication> has no zero argument constructor
at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.InstantiationException: java.lang.Class<com.domain.app.CustomApplication> has no zero argument constructor
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at android.app.Instrumentation.newApplication(Instrumentation.java:1155)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1218)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431) 
at android.app.ActivityThread.access$1300(ActivityThread.java:219) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
UPDATE: Upon further examination, there was another error in Logcat showing that the system failed to find my custom AppComponentFactory.
E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "com.domain.app.appname.CustomAppComponentFactory" on path: DexPathList[[zip file "/data/app/com.domain.app.appname-8VLkpKFTUtW8k-xEHX-oMQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.domain.app.appname-8VLkpKFTUtW8k-xEHX-oMQ==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:256)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:855)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:950)
at android.app.LoadedApk.getResources(LoadedApk.java:1188)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2462)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2454)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6343)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

In my case this was caused by not using a fully qualified class name in the manifest. It appears that when you use the shorthand .ClassName syntax for the android:appComponentFactory attribute the system prepends the applicationId instead of the package declared in the manifest element. To get the system to recognize my CustomAppComponentFactory I had to change my manifest from this:
<application
android:appComponentFactory=".CustomAppComponentFactory"
....
>
to this:
<application
android:appComponentFactory="com.domain.app.CustomAppComponentFactory"
....
>
Note that I also had to add tools:replace="appComponentFactory" to the application element in the manifest to make all this work, but there was a clear error message about a manifest merger error with androidx.core.app.CoreComponentFactory that suggested adding the replace attribute.

Related

Failed to instantiate application in jetpack compose

So i'am trying to learn Jetpack Compose, but my Dependency Injection with dagger hilt cannot work properly. But, it is works fine in the other project, so is there something i'am missing here?
FATAL EXCEPTION: main
Process: com.lelestacia.submissioncompose, PID: 6340
java.lang.RuntimeException: Unable to instantiate application com.lelestacia.submissioncompose.application.MyApp package com.lelestacia.submissioncompose: java.lang.ClassNotFoundException: Didn't find class "com.lelestacia.submissioncompose.application.MyApp" on path: DexPathList[[dex file "/data/data/com.lelestacia.submissioncompose/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~UPDLbuW7-1MIDHePtZAPuw==/com.lelestacia.submissioncompose-VtqvuByd7B1W6Uwl4SYgJA==/base.apk"],nativeLibraryDirectories=[/data/app/~~UPDLbuW7-1MIDHePtZAPuw==/com.lelestacia.submissioncompose-VtqvuByd7B1W6Uwl4SYgJA==/lib/x86_64, /system/lib64, /system_ext/lib64]]
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1466)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1395)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6746)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.lelestacia.submissioncompose.application.MyApp" on path: DexPathList[[dex file "/data/data/com.lelestacia.submissioncompose/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~UPDLbuW7-1MIDHePtZAPuw==/com.lelestacia.submissioncompose-VtqvuByd7B1W6Uwl4SYgJA==/base.apk"],nativeLibraryDirectories=[/data/app/~~UPDLbuW7-1MIDHePtZAPuw==/com.lelestacia.submissioncompose-VtqvuByd7B1W6Uwl4SYgJA==/lib/x86_64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
at android.app.Instrumentation.newApplication(Instrumentation.java:1232)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1458)
at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1395) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6746) 
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loopOnce(Looper.java:201) 
at android.os.Looper.loop(Looper.java:288) 
at android.app.ActivityThread.main(ActivityThread.java:7898) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/lelestacia/submissioncompose/application/Hilt_MyApp;
at java.lang.VMClassLoader.findLoadedClass(Native Method)
at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
... 16 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.lelestacia.submissioncompose.application.Hilt_MyApp" on path: DexPathList[[dex file "/data/data/com.lelestacia.submissioncompose/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~UPDLbuW7-1MIDHePtZAPuw==/com.lelestacia.submissioncompose-VtqvuByd7B1W6Uwl4SYgJA==/base.apk"],nativeLibraryDirectories=[/data/app/~~UPDLbuW7-1MIDHePtZAPuw==/com.lelestacia.submissioncompose-VtqvuByd7B1W6Uwl4SYgJA==/lib/x86_64, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 19 more
And java generated also didn't generate my viewmodel factory, and my app module still marked as unused function even tho it has the icon of consumed from dagger hilt.

Xamarin.Android release build crash on startup with r8

Edit:
Please note the following issue does not occur when using Proguard, or in debug. Only issue with R8 in release
Step to reproduce:
Create a new blank Xamarin.Android application
Without making any change, simply run in debug make sure the project compile and run
Enable r8 and multi-dex:
Create release APK
When running the release APK, it will crash on startup with error:
2021-06-04 11:35:01.818 20194-20194/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.companyname.app1, PID: 20194
java.lang.RuntimeException: Unable to instantiate application androidx.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.companyname.app1-S2R0G2ABxfLbmKhyk54SLg==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.app1-S2R0G2ABxfLbmKhyk54SLg==/lib/x86, /data/app/com.companyname.app1-S2R0G2ABxfLbmKhyk54SLg==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1226)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/com.companyname.app1-S2R0G2ABxfLbmKhyk54SLg==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.app1-S2R0G2ABxfLbmKhyk54SLg==/lib/x86, /data/app/com.companyname.app1-S2R0G2ABxfLbmKhyk54SLg==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at android.app.Instrumentation.newApplication(Instrumentation.java:1148)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1218)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431) 
at android.app.ActivityThread.access$1300(ActivityThread.java:219) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859) 
at android.os.Handler.dispatchMessage(Handler.java:107) 
at android.os.Looper.loop(Looper.java:214) 
at android.app.ActivityThread.main(ActivityThread.java:7356) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
I've played around with Linking options, but they all result in the same result.
A simple project can be found here:
https://drive.google.com/file/d/1oihKvJnRjxGiOaa2JS0FYKlQYI615p91/view?usp=sharing
Any help is highly appreciated!
When enabling multidex the correct multidex library (either com.android.support:multidex:1.0.3 or androidx.multidex:multidex:2.0.1) has to be used. As class androidx.multidex.MultiDexApplication is missing use androidx.multidex:multidex:2.0.1. Could be that the project template in Xamarin defailts to com.android.support:multidex:1.0.3.
See Multidex support prior to Android 5.0 for details.

Getting classNotFindException when using Firebase performance lib with slyce android sdk

I am currently stuck with integrating the new firebase perf with my current android app. Everything works fine when I disable it i.e., firebasePerformanceInstrumentationEnabled = false. But I keep getting the below error when I enable it i.e., set it's value to true`.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.testflight.app, PID: 22011
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/neovisionaries/ws/client/D;
at com.neovisionaries.ws.client.WebSocketFactory.<init>(SourceFile:2)
at it.slyce.sdk.internal.SlyceWebSocketWorkflowTask.e(SourceFile:1)
at it.slyce.sdk.internal.SlyceWebSocketWorkflowTask.onEncodingComplete(SourceFile:3)
at it.slyce.sdk.internal.BitmapEncodingTask.a(SourceFile:4)
at it.slyce.sdk.internal.BitmapEncodingTask.onPostExecute(SourceFile:1)
at android.os.AsyncTask.finish(AsyncTask.java:755)
at android.os.AsyncTask.access$900(AsyncTask.java:192)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7811)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.neovisionaries.ws.client.D" on path: DexPathList[[zip file "/data/app/com.ashleyfurniturehomestore.ecomm-X1w1G27mqcSRlwfLujt7mQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.testflight.app-X1w1G27mqcSRlwfLujt7mQ==/lib/arm64, /data/app/com.testflight.app-X1w1G27mqcSRlwfLujt7mQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.neovisionaries.ws.client.WebSocketFactory.<init>(SourceFile:2)
at it.slyce.sdk.internal.SlyceWebSocketWorkflowTask.e(SourceFile:1)
at it.slyce.sdk.internal.SlyceWebSocketWorkflowTask.onEncodingComplete(SourceFile:3)
at it.slyce.sdk.internal.BitmapEncodingTask.a(SourceFile:4)
at it.slyce.sdk.internal.BitmapEncodingTask.onPostExecute(SourceFile:1)
at android.os.AsyncTask.finish(AsyncTask.java:755)
at android.os.AsyncTask.access$900(AsyncTask.java:192)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:772)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7811)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
How can I solve this?
Try to run with proguard disabled. If it works, you need to edit your ProguardRules.pro file to exclude Firebase libraries.

What is provideLayout()?.let { setContentView(it) }?

So I would like to learn more about cameraX, the relatively new addition to the Android Jetpack library. I've been looking at an existing project on GitHub to help me understand how to set things up. However the issue is that i'm new to kotlin (project is in kotlin).
In the project: Project
there exists something called "it"
Can be seen here: Example
More specifically in the following line:
provideLayout()?.let { setContentView(it) }
"it" is repeated multiple times throughout the project as well. I just want to know what this is. Is "it" a variable? Is "it" Kotlin specific code?
Additionally, what is:
provideLayout()?.let
How does this work? What does it do?
UPDATE
Specific to CommonsWare solution (error):
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.memory.pod.debug, PID: 31521
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.memory.pod.debug/com.memory.pod.camerax.ui.home.HomeActivity}: android.view.InflateException: Binary XML file line #8 in com.memory.pod.debug:layout/activity_home: Binary XML file line #8 in com.memory.pod.debug:layout/activity_home: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #8 in com.memory.pod.debug:layout/activity_home: Binary XML file line #8 in com.memory.pod.debug:layout/activity_home: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #8 in com.memory.pod.debug:layout/activity_home: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.arindam.camerax.ui.home.permission.PermissionsFragment: make sure class name exists
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:91)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:546)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:390)
at androidx.navigation.fragment.FragmentNavigator.instantiateFragment(FragmentNavigator.java:132)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:162)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.java:58)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:71)
at androidx.navigation.NavGraphNavigator.navigate(NavGraphNavigator.java:28)
at androidx.navigation.NavController.navigate(NavController.java:935)
at androidx.navigation.NavController.onGraphCreated(NavController.java:577)
at androidx.navigation.NavController.setGraph(NavController.java:534)
at androidx.navigation.NavController.setGraph(NavController.java:499)
at androidx.navigation.NavController.setGraph(NavController.java:481)
at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:237)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1818)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:303)
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.java:166)
at androidx.fragment.app.FragmentLayoutInflaterFactory.onCreateView(FragmentLayoutInflaterFactory.java:51)
E/AndroidRuntime: at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:135)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:356)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:335)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.memory.pod.camerax.ui.base.BaseActivity.onCreate(BaseActivity.kt:11)
at android.app.Activity.performCreate(Activity.java:7825)
at android.app.Activity.performCreate(Activity.java:7814)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: com.arindam.camerax.ui.home.permission.PermissionsFragment
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at androidx.fragment.app.FragmentFactory.loadClass(FragmentFactory.java:47)
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:88)
... 53 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.arindam.camerax.ui.home.permission.PermissionsFragment" on path: DexPathList[[zip file "/data/app/com.memory.pod.debug-koXsvzgNs8unWof_uGUUgw==/base.apk"],nativeLibraryDirectories=[/data/app/com.memory.pod.debug-koXsvzgNs8unWof_uGUUgw==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
Side not the hyperlink highlighted section is
com.memory.pod.camerax.ui.base.BaseActivity.onCreate(BaseActivity.kt:11)
Is "it" a variable?
it is a parameter passed into the lambda expression.
Taking this piece by piece...
provideLayout() is a function, returning an object.
?. is a "safe call", meaning that if the object is null, we skip the call
?.let() is a particular usage of a safe call that says "execute this lambda expression if the object is not null, and pass that object in as a parameter; if the object is null, though, skip it and let's just go have lunch"
{ setContentView(it) } is a lambda expression that is called by let() if the object returned by provideLayout() is not null, and that object is referred to in the lambda expression as it (where it is the default name of the lambda parameter, since we did not provide another name)
If we knew that provideLayout() would never return null, or if setContentView() could support null, this could be simplified as:
setContentView(provideLayout())

Unable to instantiate application class

8-03 11:35:19.736 5040-5043/? E/ANDR-PERF-MPCTL: Invalid profile no. 0, total profiles 0 only
08-03 11:35:19.863 16408-16408/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app, PID: 16408
java.lang.RuntimeException: Unable to instantiate application com.app: java.lang.ClassNotFoundException: Didn't find class "com.app" on path: DexPathList[[zip file "/data/app/com.app-2/base.apk"],nativeLibraryDirectories=[/data/app/com.app-2/lib/arm, /data/app/com.app-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5376)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.app" on path: DexPathList[[zip
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newApplication(Instrumentation.java:1014)
at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5376) 
at android.app.ActivityThread.-wrap2(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6123) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) 
08-03 11:35:19.983 1490-1523/? E/BatteryStatsService: no controller energy info supplied
Solved above problem by disabling the instant Run
I have seen this problem on more than one thread and it is almost always that the Application class name is absent, misspelled, misnamed, or in the wrong package in the manifest.
Double check your manifest and notice if the Application name is set and if it is green or red? Your app will compile even if it is red--or indicating that there is an error.
BTW this happened to me with Instant Run disabled. Instant Run is often named as the culprit when clearly the classloader cannot find the Application class, because of a name related problem.

Categories

Resources