0

Getting error Unable to instantiate activity when using flavors and the launcher activity is having different code in both flavors.

MainActivity is launcher activity. And it contains different code in both flavors.

Project Structure

--Flavor 1

--> AndroidManifest.xml(contains activities only used in this flavor)

--> java

----> MainActivity.java(specific code for this flavor)

--Flavor 2

--> AndroidManifest.xml(contains activities only used in this flavor)

--> java

----> MainActivity.java(specific code for this flavor)

-- main

--> AndroidManifest.xml(just the manifest tags are used i.e. just empty manifest file)

When I was having common MainActivity for both flavors the code was working fine. But now when I run the code on emulator/any device it shows this error in logcat

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{some.package.flavor1/some.package.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "some.package.MainActivity" on path: DexPathList[[...]]

After doing clean project or rebuild sometimes the app works just fine but most of the times the app crashes and gives the above error.

Thank you for reading the question. I hope it is understandable...

0 Answers0