我把IntelliJ IDEA从12.0.4升级到12.10。

现在我的Android项目中的所有模块都给出了错误:

错误:没有找到默认活动

我恢复到12.0.4,一切都恢复正常了。

什么好主意吗?我认为这可能是一个丢失插件的问题。由于插件没有安装,它无法找到默认活动。另一个东西可能是本地配置,但我对此表示怀疑。我删除了配置文件夹来验证,这没有改变任何东西。


当前回答

编辑文件androidmanifest.xml

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

    <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=".MainActivityName">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

其他回答

如果您在升级IntelliJ IDEA或Android Studio版本后,或者在生成新的APK文件后,看到该错误发生,您可能需要刷新IDE的缓存。

菜单文件→无效缓存和重启…

去建造。Gradle(项目:xyz)

buildscript {
    repositories {
        jcenter() 
        google()
    }
allprojects {
    repositories {
        jcenter()
        google()
    }

// Just place 'google()' to the top of 'jcenter()'

buildscript {
    repositories {
        google()
        jcenter()
    }
allprojects {
    repositories {
        google()
        jcenter()
    // enter code here
    }
}

它非常适合我。

有时会出现这种错误,因为Android Studio的错误行为,因为内部缓存和项目构建系统。即使我们已经为默认活动完美地设置了一切。

对于这样的问题,我找到了一个解决方案,它是为我工作。

步骤1。Android Studio→菜单文件→无效缓存,关闭Android Studio。

步骤2。进入路径C:\Users\USER.AndroidStudio3.2\system

步骤3。更改名称扩展为下面文件夹的.back

  Example: compiler should be *compiler.back*

编译器 compiler-server 转换 external-build_system 框架 gradle resource_folder_cache

步骤4:启动Android Studio并打开项目。

之前的答案都没帮到我。

试着去除

<?xml version="1.0" encoding="utf-8"?>

在你的AndroidManifest中。

然后菜单文件→同步项目与Gradle文件。

没有一个答案对我有用。错误信息说:

无法从../path/读取清单到/the/apk 没有发现默认活动

这个错误告诉我,Android Studio正在读取以前构建的APK文件。因此,我做了。/gradlew清洁来摆脱文件夹,这为我解决了问题。