本文翻译自:Error type 3 Error: Activity class {} does not exist
I have an IntelliJ Android project, that I successfully imported to Android Studio 0.4.0. 我有一个IntelliJ Android项目,该项目已成功导入到Android Studio 0.4.0。 It works perfectly if I don't change anything in manifest. 如果我不更改清单中的任何内容,它将非常有效。 However, when I want to change the launcher activity and run, it fails with this error: 但是,当我想更改启动器活动并运行时,它失败并显示以下错误:
Launching application: com.trackingeng/LandingActivity.
DEVICE SHELL COMMAND: am start -D -n "com.trackingeng/LandingActivity"
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] cmp=com.trackingeng/LandingActivity }
Error type 3
Error: Activity class {com.trackingeng/LandingActivity} does not exist.
When I click Sync Project with Gradle files , it outputs: 当我单击与Gradle文件同步项目时 ,输出:
Project Sync
The project 'TrackingEng' is not a Gradle-based project
Run settings: 运行设置:
#1楼
参考:https://stackoom.com/question/1Pl10/错误类型-错误-活动类-不存在
#2楼
I faced a similar problem after refactoring. 重构后,我遇到了类似的问题。
This is what i did to resolve this issue: 这是我为解决此问题所做的事情:
- Cleaned the Project 清理项目
- Deleted the
Build
directory 删除Build
目录 - Restarted Android Studio 重新启动Android Studio
- Rebuild the Project 重建项目
- Run 跑
- Optionally (Go to the files menu on android, click on "Invalidate Caches / Restart..." uninstall the app on your phone and try again) (可选)(转到android上的文件菜单,单击“无效的缓存/重新启动...”,卸载手机上的应用程序,然后重试)
And everything worked fine! 而且一切正常!
I think the key is to restart your IDE . 我认为关键是重新启动IDE 。
Hope this helps you or anyone else! 希望这对您或其他任何人有帮助!
Edit 1: 编辑1:
If the above steps don't work for you, then deleting Gradle cache seems to be a solution, as pointed out by @Yasitha. 如果上述步骤对您不起作用,则@Yasitha指出,删除Gradle缓存似乎是一种解决方案。
Edit 2 编辑2
As suggested by a couple of users in the comments below, sometimes the issue can be resolved by completely removing and reinstalling the app from your device. 正如一些用户在以下评论中所建议的那样,有时可以通过从设备中完全删除并重新安装该应用程序来解决该问题。
Simply type adb uninstall <package>
in terminal to completely remove app from the device. 只需在终端中键入adb uninstall <package>
即可从设备中完全删除应用程序。
Edit 3 编辑3
As mentioned in Abhishek's Answer , one should also try deleting the app from your device in case multiple users are set up on your device. 如Abhishek的答案中所述 ,如果您的设备上设置了多个用户,则还应尝试从设备中删除该应用程序。
Simply go to Mobile Settings > Apps > [Your App] > More > Uninstall App for All Users
只需转到Mobile Settings > Apps > [Your App] > More > Uninstall App for All Users
UPDATE for Android Studio 2.1 and up Android Studio 2.1及更高版本的更新
When running Android Studio 2.1 and up you can also encounter this issue when you have the instant run option enabled in your preferences (is enabled by default). 在运行Android Studio 2.1及更高版本时,如果您在首选项中启用了即时运行选项(默认情况下处于启用状态),也会遇到此问题。
To disable this option go to the Preferences
option in the Android Studio
top menu and look for Instant Run
so you can uncheck the first checkbox on that screen. 要禁用此选项,请转到Android Studio
顶部菜单中的Preferences
选项Preferences
选项,然后查找“ Instant Run
以便您可以取消选中该屏幕上的第一个复选框。
Anyway that fixed it for me. 无论如何,它为我解决了。 Originally pointed out by user @yusufonder. 最初由用户@yusufonder指出。 I discovered this was the issue since gradle install still worked. 我发现这是问题,因为gradle安装仍然有效。
#3楼
Try changing the name of the Activity in your AndroidManifest.xml
file. 尝试在AndroidManifest.xml
文件中更改“活动”的名称。
Right now it says: 现在它说:
<activity android:name="LandingActivity" >
Try either adding a period to the beginning of the Activity's name: 尝试在活动名称的开头添加句点 :
<activity android:name=".LandingActivity" >
Or adding the package name to the beginning of the Activity's name: 或将包名称添加到活动名称的开头:
<activity android:name="com.trackingeng.LandingActivity" >
It also may be a problem that your package name has only two components separated by periods (your package name is "com.trackingeng"; a more standard package name would be "com.trackingeng.app") 您的软件包名称中只有两个由句点分隔的部分也可能是一个问题(您的软件包名称为“ com.trackingeng”;更标准的软件包名称为“ com.trackingeng.app”)
#4楼
I had the same error after renaming/refactoring. 重命名/重构后出现相同的错误。 What I did was add the applicationId
property attribute to my build.gradle file, and set its value to the application package. 我所做的是将applicationId
属性属性添加到我的build.gradle文件中,并将其值设置为应用程序包。
In build.gradle : 在build.gradle中 :
android {
defaultConfig {
applicationId "com.example.myapp"
}
}
#5楼
This happens when you do the following 当您执行以下操作时,会发生这种情况
- connect your device/emulator 连接您的设备/仿真器
- run the app from Android Studio (AS) 从Android Studio(AS)运行应用
- use/test the app and uninstall it from the device while it is still connected to your computer 使用/测试该应用,并在该设备仍连接到计算机时将其从设备上卸载
- try to run the app again from AS 尝试从AS重新运行该应用
AS thinks you still have the app in your device. AS认为您的设备中仍然有该应用程序。
tl;dr - To resolve this, you can simply disconnect your device after uninstalling the app and reconnect it. tl; dr-要解决此问题,只需在卸载应用程序后重新连接设备并断开连接即可。
#6楼
我遇到了同样的问题,我解决了它,可以重构活动启动器,只需更改类名即可。