20

I recently downloaded Android Studio 2.0 and create a new startup app and did not add anything code by myself. After running the app, android studio installs the APK on emulator successfully but does not launch the app instead it gives the following error:

$ adb shell am start -n "com.example.muhammad.firstapp/com.example.muhammad.firstapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Unexpected error while executing: am start -n "com.example.muhammad.firstapp/com.example.muhammad.firstapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Error while Launching activity

I searched it on google and found that it was asked before but the provided solution isn't working for me either. I also did not add anything in the AndroidManifest.xml file.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.muhammad.firstapp">
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>

MainActivity.java

package com.example.muhammad.firstapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.muhammad.firstapp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
</RelativeLayout>
metior
  • 365
  • 1
  • 4
  • 16
  • Possible duplicate of [Session 'app': Error Launching activity](http://stackoverflow.com/questions/36530648/session-app-error-launching-activity) – Pavlus Apr 23 '16 at 18:36
  • 1
    I mentioned it was asked before but those solutions did not work for me. Well, I got my problem solution by struggling for hours myself and it works for me now – metior Apr 24 '16 at 06:33
  • well, in that question, source of problem was a bug in **Android Studio 2.0** _Instant Run_ feature, if you've found solution of this problem without disabling _Instant Run_ feature, share it, please (by answering your own question). – Pavlus Apr 24 '16 at 08:11
  • I answered my own question, kindly up vote if its helpful – metior Apr 24 '16 at 17:14
  • Did you find any new solution? I've tried most of answers either in 2.1 and 2.2 but no way. Really I have to downgrade to 1.5? It seems difficult to believe but this way is unusable. – Birei May 25 '16 at 11:32
  • @metior if my answer solves your issue can you please mark it as the correct one? thanks a lot! – Antonino Dec 12 '18 at 13:47
  • I have found a new potential cause of this error! If your app package name has the substring `error` present in it at all (such as my app - `terror-turret`) - it will throw this issue. What the hell, Android? – Bassinator Jul 05 '19 at 23:46
  • You can check this answer https://stackoverflow.com/a/60468450/4875245 – GS Nayma Feb 29 '20 at 18:48

20 Answers20

27

I had exactly this same problem today [Android Studio 2.3.3, Android 8.0 on the phone]

This is what I discovered. The app that I was trying to install was not shown in the android Application window [the one where you have them all]. But once I went in: Settings->Apps&Notifications->AppInfo I could see this screenshot where it was said that this app was "not installed for this user":

enter image description here

At that point I entered the app->clicked on the three points in the top right corner->Uninstall for all the users

Now when I tried to run the project through Android Studio the error message disappeared and the app was correctly installed

Hope this helps, have a good day
Antonino

Antonino
  • 3,178
  • 3
  • 24
  • 39
10

If you are using android 2.0+, take the following steps
1. Go to run
2. Select edit configurations..
3. type -r in the Install Flags text field
4. Apply and Ok then run program again

tested(23/07/2016)

Root
  • 142
  • 1
  • 3
3

I encounter the same problem in AVD, when first start app it was fine but when launch the app again it reports "Error while Launching activity".

My resolution is: in AVD, uninstall the apk, maybe the reason is the new Android studio has an issue when install apk to a AVD.

Thanks, Yu

Yu Zhang
  • 31
  • 2
3

There is issue with studio 2.0+ instant run feature

Work around provided at Android Open Source Project - Issue Tracker

Don't waste time in re installation of studio or cleaning gradle build file often .

Just add -r flag in Install flags in Run->Edit configurations->General

Rahul
  • 337
  • 3
  • 10
2

For me, I was unable to solve the problem, which is absolutely infuriating for a piece of software as important as this. I'm a diehard Android guy, and this is frankly unacceptable, that I cannot even debug an app.

However, I did find a workaround that might help some.

For me, the Session 'app': Error Launching activity error didn't prevent the app being installed, but it did prevent debugging the app since there was no way to attach a debugger. However, there is another way.

Start the app on the phone, then click attach debugger to Android process (near the regular debug button, looks just like it), this allows you to attach a debugger to an already running app.

It's annoying as hell, but at least I can debug my app again.

Bassinator
  • 1,682
  • 3
  • 23
  • 50
1

After struggling for hours I came to conclusion that the problem is with the user files stored in AVD. Whenever I choose Wipe Data of an AVD the app works like a charm and does not show the error. But its really painful for developers to Wipe Data everytime before running the app as Wipe Data will only work if your emulator is not running.

In another test phase, I wiped the data of AVD and then started the app, it ran successully; but when I tried to run the app second time it shows me that error again.

Error while Launching activity

Then I opened 'Manage Apps' and delete my app from emulator. But it did not work either.

Workaround

Another Workaround (But that does not work for me)

Final Conclusion

I think the problem is with somewhere when we tried to 'Run' the app on second time. It does not uninstall the previous version of the app so when it found the package name already there it does not install the app then; results in error launching the activity.

Community
  • 1
  • 1
metior
  • 365
  • 1
  • 4
  • 16
1

I've been working on this same exact problem for the last 8 hours...you've had no issues after rolling back from 2.0 to 1.5.1?

I've noticed that, even with the error, running the app works fine sometimes.

You're not alone, brother. I'll be sure to update when I figure out the solution.

Also, what are your specs? I'm running the following:

  • Windows 7
  • AMD FX(tm)-8120 8-Core

AVD:

  • Android 6.0
  • CPU/ABI: Google APIs ARM (armeabi-v7a)
  • Target: API lvl 23
  • No accelerometer
  • heapSize: 64

If you want more details, let me know. A sample size of 2 is always better than 1.

Matt
  • 191
  • 4
  • 14
  • Thanks @Matt. Well, after downgrading my Android to 1.5.1. Its running like a charm. Its building the app, emulators are working great, still no problem. But one thing I am facing the sidebar tabs i.e. Maven, Structure etc. Does not have an option to remove them from the sidebar. But its not my concern. My specs are the same except I am running windows 10 with C2D 3.0Ghz – metior Apr 27 '16 at 19:32
1

I have been install the new version 2.10 just now ,and the problem seems like to be solved.So you can try it.

zandong
  • 11
  • 3
1

downgrading android version is not the curect way to fix the problem..if you like that you will lose new features of testing and developing in android studio.same kinda problem i faced previously when i upgrade to android 2.1.but i resolve my problem through restarting the android studio by selecting option of "setting->invalid caches/restart". Even though your problem is not fixed then try to create another avd with suitable system image. make sure that you have downloaded a suitable system image for your emulator to run in cpu.
i solved my emulator launching problem in android 2.1 by downloading system image x86-64 with api level 23.try to download this system image if you are using 64 bit.

brahmy adigopula
  • 617
  • 3
  • 15
1

I had the same problem and solved it by following these steps:

  1. Uninstall the app, in my case, from the actual hardware that is connected over the USB.

  2. This is the key step! Uninstall the app from the "Recently uninstalled apps"

  3. Rebuild the app.

  4. Run it.

1

To fix this annoying problem I followed the three following steps:

  1. Included the -r flag in the Install Flags. This may be accomplished by clicking on Run -> Edit Configurations. Now Select the General tab and type -r in the Install Flags text area.

  2. Click on File and select Invalidate Caches / Restart.

  3. Uninstall earlier versions of the app. By this I mean to remove it by accessing General -> Apps and uninstall the app. Dragging and dropping the icon of the app to the trash in the home screen will not fix the issue.

conbask
  • 9,741
  • 16
  • 57
  • 94
TicoCR16
  • 19
  • 2
1

There's a simple solution to this problem if you're running the app on an Emulator. This happens because of Storage space constraints. Increasing the storage space of the Emulator should solve this issue.Android P Emulator with less space on the disk

You can either free up some storage space from the Emulator itself or increase the storage space from the AVD Manager.

Avijeet Dutta
  • 559
  • 1
  • 5
  • 7
1

This happened to me after changing manifest permissions and trying to restart the app using AndroidStudio 3.5.1. The fix was to uninstall the app using adb and restart.

adb uninstall <your app package name>
steven smith
  • 1,519
  • 15
  • 31
0

Though I'm not sure about the exact reason for this problem, I just found a solution when I cleaned the project. So, go to Build -> Clean project. This should help you

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
0

I had the same problem, in fact the last version of my application was disabled in the phone or emulator, to solve the problem just reactivated the application in my phone (settings-> apps-> disabled) and I recompile and the problem was solved.

kevin kemta
  • 90
  • 10
0

I had this problem on LG-K220. It turned out that I have previously deinstalled this app, but this phone model had a system app which does not deinstall the app at first, but keeps it like in a recycle bin. No wonder Android Studio had troubles installing a new one. I completely removed the app and then it worked.

Arnie Schwarzvogel
  • 955
  • 1
  • 13
  • 25
0

the solution is simple just uninstall package using adb command after you connect to your device

adb uninstall PACKAGE NAME

replace “PACKAGE NAME” with the name of the application you want to delete and press “Enter.”

Ameur Bennaoui
  • 309
  • 3
  • 5
0

In my experience this error occurs when you manually uninstall your apk when it's building or installing via android studio.

In a such case I simply create a apk and install it on the AVD or phone. After It will work as usual.

Hope this will help to someone.

-1

Maybe you just set your phone or emulator to refuse all the requests of installing apk through USB. Open your phone setting and change this to allow the installing. The problem is solved. Hope it works for you!

Arya
  • 1
-1

I tried almost every solution found in the community, but the Error Launching activity never gone. Now I found what's the reason of my case.

I use a USB connected LG K20 Plus phone to test my projects built on the Android Studio 2.3.3, the Error Launching activity will appear if I uninstall the project in the phone, it will launch normally again if the deleted project is reinstalled.

I hope this will help people having the same or similar Error in your developing projects.

Su Jin
  • 1