【问题标题】:Android Studio Manifest - intent filter problemAndroid Studio Manifest - 意图过滤器问题
【发布时间】:2021-09-06 02:34:06
【问题描述】:

因为我想用一些动画来启动我的应用程序。我需要先开始动画活动。 SplashActivity 是动画活动。

在清单中我试过这个:

   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.numberguessingapp"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="31" />

    <application
        android:allowBackup="true"
        android:appComponentFactory="androidx.core.app.CoreComponentFactory"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:testOnly="true"
        android:theme="@style/Theme.NumberGuessingApp" >
        <activity
            android:name="com.company.numberguessingapp.SplashActivity"
            android:exported="true" /> 
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name="com.company.numberguessingapp.MainActivity"
            android:exported="true" >
        </activity>
    </application>
</manifest>

但是我收到了这个错误:

执行时发生故障 com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction Android资源链接失败 错误:/Users/kalilux/AndroidStudioProjects/NumberGuessingApp/app/build/intermediates/packaged_manifests/debug/AndroidManifest.xml:25: AAPT:错误:在 中发现意外元素。

第 25 行是在哪里。

【问题讨论】:

    标签: android android-studio android-manifest


    【解决方案1】:

    感谢您发布所有清单代码。用intent-filter关闭活动标签实际上是一个错误

    你应该输入

    <activity
        android:name="com.company.numberguessingapp.SplashActivity"
        android:exported="true"> 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    </activity>
    

    而不是

    <activity
        android:name="com.company.numberguessingapp.SplashActivity"
        android:exported="true" /> 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
    

    【讨论】:

    • 如果我这样做并构建代码,则 会删除。然后 android:exported = "true" /> 回来了。
    • 然后尝试从MainActivity 中删除exported 标签。
    • 当我重建项目时它也会回来。我将不得不做一个新项目。 :(
    • 你有cleaned这个项目吗?如果是,那么您尝试过invalidate cache &amp; restart
    • 是的。我用的是m1 macbook air,可能有问题。
    猜你喜欢
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多