无法从 Android Studio 启动应用程序,既没有启动选项 "Default" 也没有 "Specific" Activity

Can't start App from Android Studio with neither Launch Option "Default" nor "Specific" Activity

问题发生在一夜之间。有一天,一切正常。我关闭了我的电脑并在另一天重新启动它。但是,在不做任何更改的情况下,我尝试在我以前使用的同一台虚拟设备上启动我的应用程序,但不知何故它无法启动,因为:

"Error running 'app'. Default Activity not found."

我的清单看起来像这样。我更改了包名称和下面的两个活动(见下面的评论)。其余完全一样。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MyPackageName">

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".LoginActivity"
        android:label="@string/title_activity_login"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:screenOrientation="portrait">
    </activity>
    <activity android:name=".AnotherActivity" />
    <activity android:name=".OneMoreActivity">
    </activity>

    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="364e8b3f6acfddf9ad32bed8c1503bb762b19cd5" />


</application>

</manifest>

通常我的应用程序会以登录 Activity 开头。然而,现在没有了。我试着 "Invalidate Caches / Restart"。没有改变。我多次重启AS。还是什么都没有。

然后我尝试更改启动选项。当前选项设置为 "Default Activity"。所以我试图将其更改为特定的。即,登录Activity。但它告诉我:

"Error running 'app'. The Activity 'LoginActivity' is not declared in AndroidManifest.xml."

它告诉我它没有声明,它显然是。否则我一开始就无法从下拉列表中选择它。我还尝试从另一个 Activity 开始。 "MainActivity"。仍然没有。

我到底做错了什么?是否有一种解决方法可以让我在我的虚拟设备上手动获取 APK,这样我至少可以继续工作?

编辑

我已经尝试删除 .gradle 文件夹。可悲的是,这没有用。我尝试将其推送到 git 并在另一个文件夹中再次克隆它。那也没用。

解决方法

到目前为止,我只能找到一个解决方法:

显然,这有点麻烦,可能会使调试应用程序的启动变得更加困难。所以我仍在寻找实际的解决方案。

当我试图寻找解决另一个随机出现的问题的方法时,我找到了答案。

Androidstudio 不会加载任何预览并在我的布局中放置警告,因为

One or more layouts are missing the layout_width or layout_height attributes.

建议的一个解决方案 the answer I found for that problem 是删除

中的所有文件

C:\Users\UserName.AndroidStudio3.2\system\caches

这就是我所做的,它解决了这两个问题。我猜开发人员有一些修复工作要做。