Android Studio: “Session ‘app’: Error Launching activity”

Sometimes weird things happen in Android-land. This is the (not fully solved) story of a weird launch problem I ran into in Android Studio.

3 min readJan 22, 2018

--

My usual work/test setup is that I have two physical devices (Nexus 5 on LineageOS 7.1.2 & Pixel 1 on Stock 8.1) connected to my Macbook Pro. This allows easy access to testing changes quickly on a device.

I was working through a bunch of changes on an app for client and wanted to test the result on the phones. I launched the app on the Nexus 5 via Run ‘app’ in Android Studio — everything was fine and worked as expected.

Next, I tried to launch the app on the Pixel but it didn’t install and therefore it didn’t launch either. The app didn’t show up in the app drawer.

Instead Android Studio decided to show me the proverbial middle finger and resorted to the dreaded Session 'app': Error Launching activity problem. I managed to obtain some more details from the run panel and it seemed that the source of the trouble was that the MainActivity couldn’t be found.

Error while executing: am start -n "com.something/com.something.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHERStarting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.something/.MainActivity }Error type 3Error: Activity class {com.something/com.something.MainActivity} does not exist.

Error while Launching activity

A quick investigation looking into a variety of possible problems left me puzzled. After cleaning the build and rebuilding, the generated .apk file looked ok. The app hadn’t changed that dramatically over the last couple of days anyway. The weirdest thing though: going back in time in the Mercurial repo and rebuilding from an older snapshot still didn’t fix the problem.

At this stage it was clear it would have to be an issue with the Pixel or Android Studio and the Pixel or some other weird thing coming from an update to the build or sdk tools.

One particular thing that I found in logcat when trying to install on the Pixel were messages from PackageManger that indicated a path change:

Code path for pkg : com.something changing from /data/app/com.something-56474ef754777 to /data/app/com.something-73574845ab5feResource path for pkg : com.something changing from /data/app/com.something-56474ef754777 to /data/app/com.something-73574845ab5fe

That’s weird — why would the path change in this situation? Because the app didn’t show up in the app drawer, the finding inspired me to have a look in the app list in the Settings app. And bingo, the app in question was there. However, it had a little note saying “Not installed for this user” next to it. Unfortunately I didn’t take a screenshot of it, but it would look similar to the screenshot shown in a Stackexchange discussion on how to remove apps installed for a different user.

Uninstalling it (via uninstall for all users in the three dots menu in the upper right corner) got rid of the app. Another clean build and a relaunch from Android Studio fixed the issue with the app not running on the Pixel.

Now, in hindsight the launch error makes sense. Not sure if adding -r (for replacing an existing app) to the pm install flags would have prevented the issue, it might have.

Now we’re getting to the unsolved part I mentioned above. What does not make sense to me is that my Pixel thought the app was installed for a different user.

For a start my phone doesn’t have multiple users. It has me (well, and the guest user option one can’t get rid of easily). I struggle to think that Android Studio would install apps into that guest user even by accident, so let’s rule that out.

Leaves the option of some of the internals of the device’s user management (or specifically my user) having changed through the lifecycle of my phone. Could the upgrade from Android 7.1.2 to 8 or to 8.1 have caused that? Could one of the monthly security patches have caused this?

I’d be really keen to shed some more light on this particular problem. If you have seen this before and know more about it, I’d really appreciate any comments, feedback and further explanation.

I hope you find this informative and useful. If you do, please like it and share. As usual, I’d really appreciate any comments and feedback. You can find me as AgentK on Twitter.

--

--

Building Web & Android apps in Kotlin, CFML, JS, Java… 💑 to @blauerpunto. Also: pilot ✈️ & Nintendo gamer 🎮: 4613–9999–2913 (3DS) & SW-3852–3319–8305 (Switch)