59

I changed my package name from com.mycompany.myapplication to com.mycompany.testapp.

Everything builds fine but when I try to run it on the emulator, I get:

The session was restarted Target device: NexusS [emulator-5554] Uploading file local path: /home/antony/AndroidStudioProjects/testappProject/testapp/build/apk/testapp-debug-unaligned.apk remote path: /data/local/tmp/com.mycompany.myapplication Installing com.mycompany.myapplication DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.mycompany.myapplication" pkg: /data/local/tmp/com.mycompany.myapplication Success

Launching application: com.mycompany.myapplication/com.mycompany.testapp.MainActivity. DEVICE SHELL COMMAND: am start -D -n "com.mycompany.myapplication/com.mycompany.testapp.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.mycompany.myapplication/com.mycompany.testapp.MainActivity } Error type 3 Error: Activity class {com.mycompany.myapplication/com.mycompany.testapp.MainActivity} does not exist.

Note the remote path ^^^ is wrong.

If I go to the emulator, I can start the app from the menu, it's just that I get this error when i try to run the app from Android Studio.

I also see in logcat, on the top-right, the drop-down offers me "No Filters" or "app:com.mycompany.myapplication". So I can't even debug properly.

Where are these references to com.mycompany.myapplication coming from, and how can I fix this?

antgel
  • 1,241
  • 1
  • 14
  • 29

14 Answers14

98

I tried to restart Android Studio but the problem still existed.

Then the solution works with me.

  1. Remove the directory ~/.gradle/caches/. It's OK to do this while Android Studio is opened. (Refer pm installing wrong package name)
  2. Press "Sync project with Gradle files" icon on Android Studio
  3. Run the project and the remote path will be correct.
Community
  • 1
  • 1
Jack Fan
  • 2,143
  • 3
  • 18
  • 25
  • 3
    Restarting, Sync Project, Invalidate Caches didn't work for me, but this did. Thanks! – Ben Clayton Nov 16 '15 at 11:38
  • 2
    Usually I don't let myself write chatty comments, BUT FOR GOD'S SAKE HOW IT CAN EVEN WORK? Many thanks! – aga May 18 '16 at 21:15
  • this worked for me, randomly it happened, randomly it worked. Seems like gradle is still quite buggy, been having alot of problems with it – CybeX Jun 14 '16 at 17:10
  • 3
    you should use `./gradlew cleanBuildCache` to delete the gradle cache – luckyhandler Mar 07 '19 at 10:10
  • Lifesaver sir! Thank you for sharing this, was tearing my hair out trying to resolve! – omega1 May 27 '20 at 14:56
  • this is so f*cked up! spend an hour trying to figure out why my code changes are not working! (I temporarily changed app namespace to app2). then cleaned up and uninstalled both old and new version of app and then I got this on fresh launch! thanks for sharing – Bakhshi Jun 19 '23 at 12:47
  • Restarting Android Studio after removing `~/.gradle/caches` was necessary in my case. – ofavre Jul 13 '23 at 08:57
82

Here is how I solved it. Very simple.

Click the 'Sync Project with Gradle Files' button at the top of the window.

'Sync Project with Gradle Files' button screenshot

Look for this button if you're using newer version of Android Studio:

'Sync Project with Gradle Files' button in newer AS screenshiot

'Sync Project with Gradle Files' button in latest AS screenshiot

Jonas Borggren
  • 2,591
  • 1
  • 22
  • 40
  • 2
    This works for me as well. But shouldn't this be considered as a bug in Android Studio that needs to be fixed in the future? Just curious. – jonathanzh Apr 24 '16 at 01:29
  • 1
    For me worked 3rd image(solution - Sync project with gradle files) – Vivek Thummar Jan 24 '20 at 14:21
  • remove .gradle folder, restart IDE and sync gradle files and restart IDE again and restart react native project worked for me :D idk if less IDE restarts would work, but hey, it's black magic. go for it – Lukas Liesis Jan 07 '21 at 21:01
30

I Did all mentioned things but no effect. Then I found something in build.gradle file and changed it as per my new package. It worked for me.

    defaultConfig {
    applicationId "com.*****.newPackageId"
    minSdkVersion 11
    targetSdkVersion 20
}
user2322082
  • 658
  • 1
  • 6
  • 18
For Guru
  • 1,197
  • 13
  • 23
  • This worked for me when the `versionCode` needed updating. Thanks. It seems that editing the package name and `versionCode`/`versionName` is done through `build.gradle` and not through the manifest! The "Merged Manifest" is what is used in the APK AFAICS. – darrenp Apr 27 '17 at 22:27
  • This did it for me! Thanks so much. – Jk Jensen Oct 13 '17 at 17:41
  • After all other methods didn't work, this method finally worked! Thanks. – JSong May 29 '18 at 02:38
13

I'll answer, just in case anyone else gets stuck with this. Strangely enough, restarting Android Studio solved the problem. Nothing more complicated, nothing less obvious.

antgel
  • 1,241
  • 1
  • 14
  • 29
  • 7
    I have just run into this issue after changing my package name of an app. Restarting Android Studio (even with invalidating caches) did not work. Any other ideas? – Vidia Aug 28 '14 at 21:14
  • 2
    Restarting didn't help, but re-importing the project did. – pawelo Sep 15 '14 at 09:33
  • 4
    restart android studio didn't help for me too. But 'sync project with gradle files' did help. – 正宗白布鞋 Oct 07 '14 at 16:46
  • Consider marking my answer as correct since @正宗白布鞋 confirmed it (most likely) wasn't restarting Android Studio that fixed it. I believe it worked to restart Android Studio because your gradle had to sync itself. – Jonas Borggren Jul 13 '15 at 10:54
  • Another problem I am facing when I updated my Android Studio to 2.1. Unexpected error while executing: am start -n "com.example.sition.diggintemp/com.example.sition.diggintemp.StartActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Error while Launching activity That is resolved after restart. – Smeet May 06 '16 at 17:33
4

Clearing the cache and restart worked for me.

Go to Android Studio's File menu and select Invalidate Caches / Restart... option

Mukesh
  • 283
  • 3
  • 11
2

In new version of AndroidStudio, such as 0.9.1, this solution works with me:

1) remove ~/.greadle/2.1/taskArtifacts
2) clean project
3) run the project

Will Yan
  • 43
  • 5
2

I got the same problem. None of the solutions above helped me, so I am posting another solution, which helped me.

The problem appeared after I deleted my application 'by hand' on my smartphone.

I went to settings->apps. There was my app with 'Installed not for this user' (or something similar) The solution was to delete for all users in apps' settings. (This was not done when I had deleted the app using main menu)

user
  • 139
  • 1
  • 10
1

What I finally did, is change the 'application ID' in the build.gradle, build and launch. Then remove the apps from the phone and revert the application ID back

Boy
  • 7,010
  • 4
  • 54
  • 68
  • Thanks ! this worked for me - change the applicationId in 'defaultConfig' then 'synchronize' and then 'Invalidate cache/restart' This did the trick for me – satish marathe Jun 07 '15 at 03:49
1

If your App is getting the Same name as your MainActivity and you have tried eve, try to remove

android:label="MyMainActivity"

tag from Mainactivity, then run your app. That worked for me :)

Ajji
  • 3,068
  • 2
  • 30
  • 31
1

None of this solutions above worked for me, but this did:

Refactor the package's name like:

com.name.examplename

Change to:

com.name.examplename2

Change your application ID with the new name of the package:

applicationId "com.name.examplename2"

Finally, go to:

File > Invalidate Caches / Restart

Wait for android studio to restart, run your application again and get happy!

0

My issue was that some of my .xml files (particularly AndroidManifest.xml) had their headers changed somehow.

Problematic header:

<?xml code="1.0" encoding="utf-8"?>

Change this to:

<?xml version="1.0" encoding="utf-8"?>

Notice how the problematic header shows code="1.0" instead of version="1.0".

aggregate1166877
  • 2,196
  • 23
  • 38
0

Tried deleting taskArtifacts folder, invalidating,... nothing worked.

What end up working for me as forcing a Gradle Sync solved for me. (Just added a empty new line in the build.gradle to make it ask me to Sync and after the Sync it worked).

rsc
  • 10,348
  • 5
  • 39
  • 36
0

I had the exact same problem.

  • Check the manifest first of all.
  • Then Check your gradle files
  • And finally, it might be worth checking the 'test' and 'androidTest' java files.

If you don't know what to do to these files, then look at the more complete answers above.

0
  1. Build APK.
  2. Transfer it to device.
  3. Install it.
  4. Now you can install the same application using ADB.
Somesh Bhalsing
  • 142
  • 1
  • 7