Android Studio gets package name wrong when runnin

2019-01-10 22:29发布

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?

11条回答
Explosion°爆炸
2楼-- · 2019-01-10 23:07

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 :)

查看更多
我只想做你的唯一
3楼-- · 2019-01-10 23:08

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

The button looks like this in the latest versions of AS:

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

查看更多
相关推荐>>
4楼-- · 2019-01-10 23:08

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.

查看更多
我只想做你的唯一
5楼-- · 2019-01-10 23:19

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.

查看更多
老娘就宠你
6楼-- · 2019-01-10 23:20

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".

查看更多
登录 后发表回答