无法在 android studio 中构建 apk,因为任务 ':app:processDebugAndroidTestManifest' 执行失败

问题描述 投票:0回答:2

这是在 Android Studio Electric Eel 上 | 2022.1.1 补丁 2,但我上次在版本 4.x.x 上构建了该应用程序。当尝试运行 build apk 命令时,它给了我这些错误:

> Task :app:processDebugAndroidTestManifest FAILED
[androidx.test.espresso:espresso-core:3.2.0] C:\Users\Jason_A\.gradle\caches\transforms-3\aaf0029a0d039603c4fc1b2830c7e911\transformed\espresso-core-3.2.0\AndroidManifest.xml Warning:
    Namespace 'androidx.test.espresso' used in: androidx.test.espresso:espresso-core:3.2.0, androidx.test.espresso:espresso-idling-resource:3.2.0.
G:\Coding\Android_Studio\YouTubeStartEndTime\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7671241862673218921.xml:27:9-33:20 Error:
    android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
G:\Coding\Android_Studio\YouTubeStartEndTime\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7671241862673218921.xml:34:9-40:20 Error:
    android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
G:\Coding\Android_Studio\YouTubeStartEndTime\app\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7671241862673218921.xml:41:9-47:20 Error:
    android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger.


Execution failed for task ':app:processDebugAndroidTestManifest'.
> Manifest merger failed with multiple errors, see logs

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugAndroidTestManifest'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:142)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:140)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTask
...

Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
    at com.android.build.gradle.tasks.ProcessTestManifest.handleMergingResult(ProcessTestManifest.kt:346)
    at com.android.build.gradle.tasks.ProcessTestManifest.mergeManifestsForTestVariant(ProcessTestManifest.kt:316)
    at com.android.build.gradle.tasks.ProcessTestManifest.doTaskAction(ProcessTestManifest.kt:116)
    at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(BaseTask.kt:66)
    at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:51)
    at com.android.build.gradle.internal.tasks.NonIncrementalTask.taskAction(NonIncrementalTask.kt:97)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

...

这是我的AndroidManifest.xml

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

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

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

</manifest>

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.example.youtubestartendtime"
        minSdkVersion 16
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    namespace 'com.example.youtubestartendtime'
    buildToolsVersion '33.0.1'
    ndkVersion '25.2.9519653'
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

这是清单合并责备调试报告

1<?xml version="1.0" encoding="utf-8"?>
2<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3    package="com.example.youtubestartendtime"
4    android:versionCode="1"
5    android:versionName="1.0" >
6
7    <uses-sdk
8        android:minSdkVersion="16"
8-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml
9        android:targetSdkVersion="33" />
9-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml
10
11    <application
11-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:4:5-20:19
12        android:allowBackup="true"
12-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:5:9-35
13        android:appComponentFactory="androidx.core.app.CoreComponentFactory"
13-->[androidx.core:core:1.3.0] C:\Users\Jason_A\.gradle\caches\transforms-3\87c712ceb280b89563e287f590257de7\transformed\core-1.3.0\AndroidManifest.xml:24:18-86
14        android:debuggable="true"
15        android:icon="@mipmap/ic_launcher"
15-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:6:9-43
16        android:label="@string/app_name"
16-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:7:9-41
17        android:roundIcon="@mipmap/ic_launcher_round"
17-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:8:9-54
18        android:supportsRtl="true"
18-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:9:9-35
19        android:theme="@style/AppTheme" >
19-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:10:9-40
20        <activity
20-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:12:9-19:20
21            android:name="com.example.youtubestartendtime.MainActivity"
21-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:12:19-47
22            android:exported="true" >
22-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:13:13-36
23            <intent-filter>
23-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:14:13-18:29
24                <action android:name="android.intent.action.MAIN" />
24-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:15:17-69
24-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:15:25-66
25
26                <category android:name="android.intent.category.LAUNCHER" />
26-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:17:17-77
26-->G:\Coding\Android_Studio\YouTubeStartEndTime\app\src\main\AndroidManifest.xml:17:27-74
27            </intent-filter>
28        </activity>
29    </application>
30
31</manifest>

程序建议我更新SDK,所以我不得不将目标SDK从28更改为33(否则它会抱怨目标至少需要30)。我还必须将所有 android sdk 工具更新为最新。必须将 android:exported="true" 添加到 AndroidManifest.xml 但这些错误似乎表明其他位置需要此代码?我认为将 AndroidManifest.xml 和 build.gradle 中的 minsdk 和 Targetsdk 更改为相同可以修复它,但仍然会出现相同的错误。不确定 android studio 是否有办法更清楚地表明问题所在,但我在这里不知所措。

android android-studio build.gradle android-manifest
2个回答
3
投票

我想通了。转到 build.gradle(app) 文件并将依赖项更新为最新。刚刚在 android studio 的问题部分找到了快速修复。

之前:

    dependencies {
        implementation fileTree(dir: "libs", include: ["*.jar"])
        implementation 'androidx.appcompat:appcompat:1.2.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test.ext:junit:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    }

之后:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

-1
投票

我在一个遗留项目中遇到这个问题已经两天了。感谢分享!

© www.soinside.com 2019 - 2024. All rights reserved.