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 22:56

Clearing the cache and restart worked for me.

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

查看更多
Evening l夕情丶
3楼-- · 2019-01-10 22:57

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

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-10 22:58

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

查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-10 23:01

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

查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-10 23:02

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
}
查看更多
【Aperson】
7楼-- · 2019-01-10 23:07

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.
查看更多
登录 后发表回答