无法在android studio中构建apk,因为获取任务“:app:processDebugAndroidTestManifest”的执行失败

gtlvzcf8  于 2023-04-12  发布在  Android
关注(0)|答案(1)|浏览(366)

这是在Android Studio电鳗|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>

构建分级

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中的minsdk和targetsdk与build.gradle中的minsdk和targetsdk更改为相同可以修复它,但仍然得到相同的错误。不确定Android Studio是否有方法可以更清楚地指示问题所在,但我在这里不知所措。

myzjeezk

myzjeezk1#

我想通了。去了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'
}

相关问题