找不到具有两个不同维度的默认活动

问题描述

我需要在项目中使用两个不同的维度。但是使用这种方法后,无论做什么,Android Studio都会告诉我“未找到认活动”。其实src文件夹中没有任何更改,因为我不需要修改口味中的任何类。

flavorDimensions "device","backend"

productFlavors {
    dev {
        buildConfigField "String","API_VERSION","\"1.1\""
        ...extra configs
        dimension "backend"
    }
    staging {
        buildConfigField "String","\"1.1\""
        ...extra configs
        dimension "backend"
    }
    prod {
        buildConfigField "String","\"1.1\""
        ...extra configs
        dimension "backend"
    }
    android {
        buildConfigField "String","DEVICE_TYPE","\"ANDROID\""
        dimension "device"
    }
    huawei {
        buildConfigField "String","\"ANDROID_HW\""
        versionCode 10000 + defaultConfig.versionCode
        dimension "device"
    }
}

enter image description here

enter image description here

main / AndroidManifest.xml:

<application
    android:name=".XApplication"
    ...

    <activity
        android:name=".ui.SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

解决方法

AndroidManifest.xml中,将活动的android:name属性更改为活动的全限定类名,而不使用.ui.SplashActivity表示法。当您在名称前加上.时,会将其附加到package属性的<manifest>批注中,该批注可能与实际Activity类的包匹配,也可能不匹配。确保您的Activity类在文件顶部具有正确的package声明,并且位于正确的src目录中。

您的应用程序类名称也是如此。我避免不惜一切代价使用.表示法。