android sdk product flavors - 当我使用 intent 开始新 Activity 时找不到 Activity

标签 android android-intent android-gradle-plugin android-productflavors

我有一个可用的应用程序,我向其中添加了 2 种产品口味。这个应用程序在第一个屏幕上有一个菜单,允许用户选择下一个 Activity ,我有意加载它。

这是 AndroidManifest.xml:

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.alpha.aloedu.MainActivity"
        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="com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity"
        android:label="Guided Letter Drawing"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.buildvocabulary.BuildVocabularyActivity"
        android:label="Image Plus Word"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.findthepicture.FindThePictureActivity"
        android:label="Find the Picture"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.findtheletter.FindTheLetterActivity"
        android:label="Find the Letter"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.fillintheletter.FillInTheLetterActivity"
        android:label="Find the Letter"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.EndActivity"
        android:label="End Activity"
        android:screenOrientation="portrait" />

    <activity
        android:name="com.alpha.aloedu.AdminActivity"
        android:label="Admin Activity"
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait"
        />

</application>

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:requiresSmallestWidthDp="480"
    android:resizeable="false"
    android:smallScreens="false"
    android:xlargeScreens="true" />

这里是 gradle 文件的相关部分:

productFlavors {
    de {
        applicationIdSuffix ".de"
        versionName "1.1de"
    }
    fr {
        applicationIdSuffix ".fr"
        versionName "1.1fr"
    }
}

这是源代码树:

enter image description here

这是我加载下一个 Activity 的代码:

    Intent intent = new Intent();
    intent.setClassName("com.alpha.aloedu", newClassName);
    currentActivity.startActivity(intent);
    currentActivity.finish();

我在第二行设置了一个断点,“newClassName”有正确的值。但是,当我运行“deDebug”变体时,第三行出现错误:

android.content.ActivityNotFoundException: 无法找到明确的 Activity 类 {com.alpha.aloedu/com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity}; 您是否已在 AndroidManifest.xml 中声明此 Activity ?

GuidedLetterDrawingActivity 类确实存在于主源代码树中,也存在于 AndroidManifest.xml 中。

感谢您提供的任何帮助。

最佳答案

您必须在其 list 文件中声明每种风格的 Activity
...\src\de\AndroidManifest.xml
...\src\fr\AndroidManifest.xml

关于android sdk product flavors - 当我使用 intent 开始新 Activity 时找不到 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41562961/

相关文章:

Android:从 'recent applications' 开始应用程序以 Intent 中使用的最后一组额外内容启动它

android-studio - 无法解析 : com. google.android.gms :play-services:15. 0.1

android - 适用于安卓

java - 条码扫描仪始终读取 UPC-E

android - 离散搜索栏

java - Android 特定的 OnItemClick Intent

android - 我如何处理这个字符串来打开我的应用程序

Android Studio 和大量的模块

android - Flutter 的 Multidex 问题

java - 工具栏菜单导致我的应用程序在打开时崩溃