可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have an INTELIJ(v12) android project successfully imported to AndroidStudio(v0.4.0). It works perfectly if I don't change anything in manifest. When I want to change the launcher activity and run, it outputs with the following 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:
Project Sync The project 'TrackingEng' is not a Gradle-based project
Anyone has faced this problem? Any ideas?
Run settings:
回答1:
I faced a similar problem after refactoring.
This is what i did to resolve this issue:
- Cleaned the Project
- Deleted the
Build
directory - Restarted Android Studio
- Rebuild the Project
- Run
And everything worked fine!
I think the key is to restart your IDE.
Hope this helps you or anyone else!
Edit:
If above steps doesn't work for you, then deleting gradle cache
seems be a solution, as pointed out by @Yasitha.
Edit 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 device.
UPDATE for Android Studio 2.1 and up
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).
To disable this option go to Preferences
option in the Android Studio
top menu and look for Instant Run
so you can uncheck the first checkbox on that screen.

Anyway that fixed it for me. Originally pointed out by user @yusufonder. I discovered this was the issue since gradle install still worked.
回答2:
May be helpful for someone:--
Sometimes when testing on a device, the app doesn't uninstall properly. To verify and fix this:
- Go to Settings.
- Go to Apps.
- Select your app. (here, you can verify that your app is not uninstalled properly).
- Open the overflow menu on the top right and select Uninstall for all users.
- Done. Try to install then launch your app again.
回答3:
This happens when you do the following
- connect your device/emulator
- run the app from 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 thinks you still have the app in your device.
tl;dr - To resolve this, you can simply disconnect your device after uninstalling the app and reconnect it.
回答4:
I would face this problem when uninstalling the app via the device (i.e. dragging the app to the "Uninstall" option). But here is the proper way to uninstall:
Use the ./gradlew uninstallAll
command. This will prevent the Error: Activity class {HomeActivity} does not exist.
error.
Update:
If you’re lazy you can use the abbreviation for this task: ./gradlew uA
.
Or define aliases for common gradle tasks in your .bash_profile
, doing so will save time, typing, and you won’t have to remember every command nor worry about typos. I suggest doing this.
回答5:
Try changing the name of the Activity in your AndroidManifest.xml
file.
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")
回答6:
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.
In build.gradle:
android { defaultConfig { applicationId "com.example.myapp" } }
回答7:
For me, the problem was that AndroidStudio
thought that the app was still on the device.
To fix it:
restart the adb
daemon; in a terminal or command prompt, enter:
adb kill-server adb start-server
try to launch your app.
if it still doesn't work, check out this answer.
make sure the platform-tools
of the Android SDK is added to your system path variables!
回答8:
Even I had the same problem but none of the above solutions worked for me. The problem was that, I had froze the particular app which I was trying to run via Titanium Backup due to which I got the above error. I tried both in Eclipse and Android Studio.
After the realization I just unistalled the app and then ran it again.
Problem Solved :-)
回答9:
I had the same issue and I solved it refactoring my activity launcher, just change the class name and it works.
回答10:
I think another reason that issue happen is that it is not fully deleted for all users on the device.
Go to Settings -> Apps - > Your Apps -> Click to the 3 dots on the top right -> Uninstall for all users
It works for me. It happen especially you change the icons of the app or messing around with the AndroidManifest.xml file.
回答11:
for me, on android 6 when i uninstalled the app it actually went to disabled instead of being removed from device.
Settings > Apps > click on your app and uninstall
this fixed it for me
回答12:
I also faced the same problem somewhere in the past. Such problems actually occurs when we do some refactoring like - renaming, moving files within the project etc. Renaming and Moving files require changes in the gradle file so whenever you rename or move some file just clean the project:
Build -> Clean Project
Cleaning the project just removes the .class files and recompiles the project. Basically, it forces a project rebuild.
Sometimes such types of errors did not cleaned on cleaning project then try to uninstall the app from the device (either it is emulator or physical one) and run the app again. Hope this will help you, it helps me 50% times.
Note:- Whenever you got any error just don't go to google, Clean the project if this not work do what you want to google.
回答13:
For me it was a very specific problem, I've got a Lg g5 to test my application on, and to reset my apps data I uninstalled it on the phone, but the phone has a "nice" feature to don't uninstall apps immediatly so you might can reinstall them within one day. So the app was installed but not usable(disabled) after removing the app from the phone completely it worked.
回答14:
I have LG Stylus and in my test phone, application isn't remove permanently. In Settings -> Application I found debug app (which I try install and debug by AS) with adnotation turn-off. When I remove app from my phone, error disappeard.
回答15:
In my case, it was because the app I was trying to launch was installed for a different user on the device. Go to Settings -> Apps (All apps) and and select the app. Click on the overflow menu and select "Uninstall for all users". This should solve the problem.
回答16:
None of the above worked for me. I had a version of the app on the device that could not be uninstalled as it was corrupt somehow. I had to factory reset the device. Not too bothered cause it was a just a dev device
回答17:
I'd like to share the trick that helped in my case. I uninstalled the application from the device and nothing of clean/rebuild/Android Studio restart
operations didn't help.
Since Android Studio thinks that the application is still installed on the device and doesn't deploy it, you can force the installation using the ADB:
adb install -r <your_application_from.apk>
where -r
means reinstall the app, keeping its data.
回答18:
As others have noted, this problem can be caused by an attached device/emulator while uninstalling the app and AS connection still exists. On my end, I just delete all the build folders (under app and project dirs) in the project, and relaunch the application on the device/emulator.
回答19:
I took reference from @jayeffkay's comment.
It works for me after I deleted the gradle cache files located in
/your_proj_directory/.gradle/2.10
2.10 is the gradle version used in my case.
回答20:
I had same issue. My problem fixed when I disabled instant run for Android Studio 2.1.1
回答21:
I had Error type 3. I managed to fix it by adding the following code below in AndroidMainfest.xml.
<activity android:name=".GameActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
回答22:
I face the similar Problem please follow the below steps.
it will help you:
1- Clean your Project
2- Delete your build directory
3- Restart your Android Studio
4- Rebuild the project
5- it will run successfully.
Thanks
回答23:
I faced this problem lately, and tried all suggestions above, and problem was not saved. Finally I changed a NDK, and problem was solved...
回答24:
If your app has only two word package name like[com.example] then all your class must be mentioned with full path in menifest like [com.example.SplashActivity] instead of relative path like[.SplashActivity] change this and delete all your build folder and re-run app . Hope it will help. Thanks
回答25:
Just in case anyone runs into my issue and has no luck with the other solutions... I was trying to start an activity through adb for FireTV while debugging Amazon launcher integration. However, my project had 60 different build variants (multi-platform, multi-app project) and the ApplicationId didn't match any classpath since the runtime package (and classpaths) were different from the applicationId.
I was trying to run adb shell am start -n com.myappid.example.packageone.packagetwo/com.myappid.example.packageone.packagetwo.MySplashActivity
(Of course I had tried many combinations with com.runtimepath.example
since I had the added challenge of a different applicationId in my build.gradle and another at runtime)
What finally helped was this post https://stackoverflow.com/a/36255727/5970652
Which revealed a different format! com.myappid.example/com.runtimepath.example.packageone.packagetwo.MySplashActivity
So if you have a different runtime classpath try specifying with the build.gradle applicationId before the slash and the runtime classpath afterwards.
You can also get these values from BuildConfig.APPLICATION_ID
and this.getLocalClassName()
respectively if you want to log them in logcat.
回答26:
In my case there was next reason:
I have 2 users: me and Guest. and app was installed on both of them but deleted only at first.
when I switched to Guest screen and delete app from there, app installed ok.
hope this will help someone :)
回答27:
i just go to Build > Rebuild Project and my problem is solved
回答28:
If you're not careful and you're trying to disable something in your app manifest make sure you don't disable the app...
<application android:allowBackup="false" android:enabled="true" ...
I accidentally set enabled
to "false" instead of allowBackup
. Wasted 2 hours searching for a solution.
回答29:
My solution is: close the "instant run" of android studio.
"instant run" can be found with the following steps: Preferences -> Build,Execution,Deployment -> Instant Run
and then uncheck the checkbox "Enable Instant Run to hot swap...."
回答30:
Check if you are building hidden version. That’s intended behavior for hidden app.
If you want to build regular version, you need to change Build Variant in Android Studio Build > Select Build Variant, change it to regular.