ChatGPT解决这个技术问题 Extra ChatGPT

Session 'app': Error Launching activity

After the Android Studio 2.0 update while the gradle build finishes I get this :

Session 'app': Error Launching activity .

It prevents the app from starting but it's installed in my emulator. This is what comes up in the Run tab :

Unexpected error while executing: am start -n "com.example.user.ypologismosmoriwn/com.example.user.ypologismosmoriwn.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Error while Launching activity

Here is the code:

package com.example.user.ypologismosmoriwn;

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);
    }
}

It's just an empty Activity,nothing added

and the XML code is just a Relative Layout with 4 Texts and 3 Check Boxes

This is the logcat i am getting

Thanks anyone who is willing to help

have you edited your manifest file ? please check it.
Another Log
How is your manifest look like?
It's the default manifest ,take a look Manifest
I've fixed the issue (on my Anroid watch Moto 360) by uninstalling the app before installing from AS

b
bv.

I also faced this issue after I updated to AS2.0. I found that it is because of the instant run enabled. So my solution is to disable the "instant run". and it worked. To disable "instant run", you can go to Preference Dialog ( May be Setting dialog on Windows), then select Build, Execution, Deployment > Instant Run, and uncheck all the checkbox to disable Instant Run.

This is my temporary solution and it may help you. Later, I'll find a better way to this issue.

update by 2016/06/06

A better solution instead of disabling instant run. Remove the .idea folder and .gradle folder, then click button Sync Project with Gradle Files (or through the menu File -> Sync Project with Gradle Files), after this process finished, you are able to run your app as normal.

Good Luck~


Disabling instant run stopped the Session 'app': Error Launching activity error.Still though,the app wont start automatically in the emulator.
Do we need to delete .idea and gradle folder before each run?!
No, just at first time
I just did a gradle sync to solve it. Was driving me crazy until I found this thread. In my case I had renamed the applicationId earlier to cause this problem.
If you have are facing this issue after installing the app from the device, the app might still exit, try checking in the settings -> Apps -> Delete the app. Then try to run the app. It worked for me.
E
EdgeDev

If you are using Android 7.0 and above it is likely that the app was installed in two places (Guest and Admin) and you only Uninstalled it for only one user and that is causing problems.

To solve that, go to: Settings -> Apps & Notifications -> See all Apps -> find the app you are trying to install.

https://i.stack.imgur.com/YNG4m.png

Then click the menu on the top right corner and select Uninstall for all users

https://i.stack.imgur.com/8it1j.png

Run Your App from Android Studio it should work.


This issue can exist in Android 7.0 devices as well. This solution works!
This issue has bugged me a couple of times recently. And your approach is the same as the approach I used from medium.com/@kaikoenig/…. Thank god I found this approach!
k
klenium

Try reinstalling the app, this solved the error for me. The trick was that, I uninstalled my app, but Android didn't truly uninstall it. On my phone, there is a guest user (my sister uses it sometimes). If you uninstall the app from your main user, it will still be available on the phone, but only for the guest user. It looks like Android Studio can't handle this case. I guess it detects that the app is installed, so it will not be reinstalled again for the current user, hence the OS can't access and launch the activity. Nice bug, I'll report it.


This is what helped me - very interesting Android behaviour
That was my case as well, thank you for finding this !
This was my case as well, when nothing else worked. It was especially interesting that I could build the app in Android Studio, but could not run it on the device. A quick adb uninstall did the trick!
s
spek

I've had same issue, rebuilding project clears the error for me.

build -> rebuild project -> run


by far the simplest solution!
And the only correct. Disabling "Instant run" is totally wrong because actually it works ok in 99% of cases.
R
Ranjithkumar

This is issue with 2.0+ studio

Issue 206036: No local changes, not deploying APK

I found the nice workaround here just add -r flag here in edit configurations and also disabling instant

https://i.stack.imgur.com/HhCgx.png

Waiting to get Instant run Feature run smoothly soon with no type 3 error more!!


@RanjithKumar you need to add this setting for each project and what i am doing is though it is showing error but new apk gets installed and then you can debug or play the same afterwards. Also uncheck Skip installation in Misc tab
e
elliptic1

For me the problem was that the app I was trying to launch was already installed under a different user account on my phone. I saw this when I went to Settings->apps looking to uninstall it. I switched to the other user, uninstalled it, came back to the original user, and was able to install and launch the app from Android Studio with no more problems.


z
zipzit

I spent a whole lot of hours on this exact issue. The "instant run" fix was a total fail. And I wasn't missing the android.intent.category.LAUNCHER I removed all applicable Android Studio and SDK code and re-installed. Still a no go.

Ultimately I think my issue was marginal hardware. I'm running on a laptop with a AMD A6-4400M processor. There is no hardware acceleration / virtualization tools available. I was just running the standard Android Studio / Google emulator. It was painfully slow, and although I was eventually able to see the emulator and interact with it, I was never able to connect the emulator to Android Studio to upload APK's.

But I did discover an awesome fix.

Remove all Android Virtual Devices and install the GenyMotion Emulator (with VirtualBox).

I've tried GenyMotion emulators before (with a Linux) and it didn't make much difference in load up speed.

On this Windows 10 machine it works exceptionally well. Its pretty quick, easily connects to Android Studio and works well deploying my apps.

GenyMotion offers one personal use device at no cost. Kudos to the GenyMotion team!

Answer provided here in case anybody else gets stuck with this error, possibly with this root cause.


C
Community

I got the same problem and fixed it with this answer.

But this problem was created by myself, as I tried to debug my unit tests. Therefore I had to uncheck the Use in-process build option of the AS Settings in Build, Execution, Deployment > Compiler.

So in my case it works, if I disabled instant run. But it also works, as I enabled instant run and also the Use in-process build option.


k
kiran puppala

Just run adb uninstall <package name> in your terminal and reinstall the app again.

Hope it helps.


And to get the package name use adb shell pm list packages
C
CodyF

Same issue, but for me problem was that Android Studio couldn't find my Default Activity. When I specified the intent filter to catch the MAIN action intent, I didn't specify the LAUNCHER category, and that caused the 'Error Launching activity' issue.

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />  <-- forgot
    </intent-filter>

The issue was there even though I hadn't change anything ,it was a default new project.Maybe it was caused after the 2.0 Android studio update.
M
Muhammad Usman

Just Run --> clean and rerun , In my case it helps. Prompts automatically like following message

would you uninstall already installed activity with same name

if activity is already installed first uninstall it and make project ready after installing app.


S
Sanjoy Kanrar

I had this error because of my stupidity. In the manifest.xml I have wrongly declared two Activity as Launcher. Make sure you have only one activity as Launcher.

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   <activity android:name=".WelcomeActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

m
macbee

I was facing the same problem in android studio 2.1.2 but worked after selecting Build -> Clean Project or alternatively Run -> Clean and Rerun


u
user3329166

I tried all suggested answers. I found out this is a hardware issue on Android N phone with studio 2.3 version. App launches fine on phones below version 7.


H
Hoque MD Zahidul

I've fixed the issue using this solution.If you are running the application in USB device then close all the virtual device like : genymotion / virtual machine .


Z
Zoe stands with Ukraine

Just disable Instant Run.

Go To File >> Settings >> Build, Execute, Deployment >> Instant Run

Uncheck The Box that says Enable instant run to hot swap code/resource changes on deploy

Re-run the emulator.


U
UzumakiL

OK already so many possible solutions for this problem, if none of those works then try this.

I faced this problem when I first uninstalled my app then tried reinstalling from ADB. But then after trying these many solutions, I realized that uninstalling app nowadays does not really uninstall it. It just disables it for few days so that it can be enabled in case you change your mind.

Now I am not sure whether its done by LG or Native Android Nougat.

I just went in Settings-> apps-> my-app and uninstalled it completely. After that from Android studio I am able to install the app again properly without this error.


Yes, I hate this feature. If I uninstalled it then I don't want it. It took me a while to figure out what was wrong.
a
adray

Adb also throws this error if applicationId, package of launching activity or module name contains error substring


OH MY GOD I WISH I COULD KISS YOU. 2 YEARS I'VE BEEN DEALING WITH THIS ON AND OFF.
Google, why? I Demand to know who is responsible for this sloppy ass programming.
s
spiraldev

None of the existing answers helped me as I had the same app installed in my other profile. Solution -

Switch to the other profile Uninstall the app from 2nd profile Switch back


C
Community

I tried the above answer. However, none of the solutiond worked for me. I changed the emulator to USB and the code is running on the USB target device prefectly!


I also had no problems with emulator, on my Android watch 'Moto 360' only. I've fixed it by uninstalling the app from device before and after that it install it from AS successfully!
佚名

All answers did not work for me.This error raised when I was trying to rename the app package.I have ended up creating a new project with the new package name and move my files to the new one.


How sad was that .. :(
K
Kiryl Ivanou

I've fixed the issue (on my Anroid watch Moto 360) by uninstalling the app before installing from AS


M
Maggie

it occured when I changed the applicationId in app gradle file. It works for me after I sync gradle.


f
fathurzero

Uninstall App on your real device or emulator. Then Run again. It's worked for me. I used Android Studio 2.3.3


T
Tirth Patel

I tried, clean & rebuild project and Invalidate Cache & Restart also manually removed .gradle and .idea folders, but that didn't solved the issue.

I have 3 user acounts in my phone. So, I didn't select Uninstall for all users, and it only uninstall my app from first user account, but it was still there in guest and second user account.

So, I removed it from rest of the accounts and it solved my issue!!


Z
Zoe stands with Ukraine

I had same problem. I was using AVD with arm processor image and received this same message. The only way for me to make Android Studio 2.1.2 runs the app with instant run was change to an X86 processor image. The error was gone and ( until this moment) I think the emulator works faster than ARM emulated. My workstation configuration is Intel I5, 6Gb RAM. Maybe this helps until next fix.


Z
Zoe stands with Ukraine

Disable "instant run", you can go to Preference Dialog ( May be Setting dialog on Windows), then select Build, Execution, Deployment > Instant Run, and uncheck all the checkbox to disable Instant Run.

And Reboot your Device this should make the thing work....instant run has a bug in Android studio 2+ This should do the magic


H
Hatim

I got the same error. This issue was caused by uninstalling the app from the device (uninstalled from only 1 user)

Solved by logging into the other user and uninstall the app from there.

and it solved.


p
parse

I did all suggestions above, but they didn't work! I rebuilt the project, uninstalled the app from my real device, unplugged USB, then I run Android Studio and run the app on my real device and the issue was gone.

Hope this helps!


G
Gilad Levinson

I had the same error as in the headline. after I changed the version name and version code in the gradle, the sync happened and then it worked. so maybe even only sync can help sometimes.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now