Default Activity not found in Android Studio

后端 未结 28 1141
盖世英雄少女心
盖世英雄少女心 2020-11-29 03:22

I just upgraded to Android Studio 0.2.8 and I am getting an error that says \"Default Activity not found\" when I try to edit the run configurations.

When I launch A

相关标签:
28条回答
  • 2020-11-29 03:39

    Modify "Workspace.xml" (press Ctrl + Shft + R to search it)

    1. Modify the activity name with package name

    2. Make sure to change "name="USE_COMMAND_LINE" to value="false"

    3. Reload the project

    Done!

    0 讨论(0)
  • 2020-11-29 03:41

    If you changed name of directories (class structure) for example com.dir.sample to com.dir.sample1, after that don't forget to change package com.dir.sample to com.dir.sample1.

    0 讨论(0)
  • 2020-11-29 03:43

    I just experienced the same error in Android Studio 1.5.1. and just found the source of the problem. I am not sure whether the cause was a human error or some strange glitch in the behaviour of the IDE, but none of the existing StackOverflow questions about this subject seemed to show anything about this so I figured I post it as an answer anyway.

    For me, either one of my team members or the IDE itself, had changed the launcher activities manifest entry, causing it to look like this:

            <activity
                android:name="com.rhaebus.ui.activities.ActivitySplash"
                android:launchMode="singleInstance"
                android:screenOrientation="portrait">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <id android:name="android.intent.id.LAUNCHER" />
                </intent-filter>
            </activity>
    

    While it should, in fact, look like this:

            <activity android:name="com.rhaebus.ui.activities.ActivitySplash"
                android:launchMode="singleInstance"
                android:screenOrientation="portrait">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" /> <!-- Change Here -->
                </intent-filter>
            </activity>
    

    So please double, triple, quadruple check the format of your launcher activity in the manifest and you might be able to save yourself some time.

    Hope this helps.

    EDIT: I strongly suggest people not to go with the answers that suggest to manually select a launcher activity inside the configuration options of your module, as this caused the application to no longer be shown in the list of installed apps on both the Samsung Galaxy S5 Neo and the Samsung Galaxy S6 (at least for me).

    0 讨论(0)
  • 2020-11-29 03:43

    You can get Android Studio not to complain by going to the "Edit Configurations" menu (tap "Shift" three times, type "Edit Configurations"), then change Launch Options > Launch to "Nothing".

    I'll probably add a generic activity containing instructions, just to avoid any confusion.

    0 讨论(0)
  • 2020-11-29 03:45

    In Android Studio, right click on the project and choose Open Module Settings. Then go to the Sources tab in your module, find the src folder, right click on it and mark it as Sources (blue color).

    EDIT: There is no sources tab in later versions of Android Studio, but you can edit the build.gradle file instead: https://stackoverflow.com/a/22028681/1101730 (thanks for comment Josh)

    0 讨论(0)
  • 2020-11-29 03:46

    When I clicked "Open Module Settings", there was no "Source" tab, I think because that's been removed for newer versions of Android Studio (I'm on 0.8.14). So I had to do this instead:

    Add these lines to the build.gradle file inside the android { ... } block:

    android { ... sourceSets { main.java.srcDirs += 'src/main/<YOUR DIRECTORY>' } }

    After editing the file, click Tools > Android > Sync Project with Gradle Files.

    Credit to this answer and this comment.

    0 讨论(0)
提交回复
热议问题