Error type 3 Error: Activity class {} does not exi

2019-01-03 08:01发布

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: enter image description here

30条回答
女痞
2楼-- · 2019-01-03 08:53

I had the same issue and I solved it refactoring my activity launcher, just change the class name and it works.

查看更多
对你真心纯属浪费
3楼-- · 2019-01-03 08:53

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.

查看更多
何必那么认真
4楼-- · 2019-01-03 08:54

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

查看更多
祖国的老花朵
5楼-- · 2019-01-03 08:56

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"  
  }
}
查看更多
萌系小妹纸
6楼-- · 2019-01-03 08:56

For me, the problem was that AndroidStudio thought that the app was still on the device.

To fix it:

  1. restart the adb daemon; in a terminal or command prompt, enter:

    adb kill-server
    adb start-server
    
  2. try to launch your app.

  3. 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!

查看更多
Anthone
7楼-- · 2019-01-03 08:56

Got to android/app/build.gradle and search for

 buildTypes {
     ....
 }

You might have something like

buildTypes {
    debug {
        ...
    }
    release {
        ...
    }
    customBuildType {
        ...
    }
}

Chose the buildType you want to start and then start the App the following

react-native run-android --variant=[buildType] --appIdSuffix '[buildType]'

So,

react-native run-android --variant=debug --appIdSuffix 'debug'
查看更多
登录 后发表回答