无法在安卓工作室中构建apk,因为任务':app:processDebugAndroidTestManifest'的执行失败



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

> Task :app:processDebugAndroidTestManifest FAILED
[androidx.test.espresso:espresso-core:3.2.0] C:UsersJason_A.gradlecachestransforms-3aaf0029a0d039603c4fc1b2830c7e911transformedespresso-core-3.2.0AndroidManifest.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:CodingAndroid_StudioYouTubeStartEndTimeappbuildintermediatestmpmanifestandroidTestdebugtempFile1ProcessTestManifest7671241862673218921.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:CodingAndroid_StudioYouTubeStartEndTimeappbuildintermediatestmpmanifestandroidTestdebugtempFile1ProcessTestManifest7671241862673218921.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:CodingAndroid_StudioYouTubeStartEndTimeappbuildintermediatestmpmanifestandroidTestdebugtempFile1ProcessTestManifest7671241862673218921.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'
}

这是manifest-merge - fault -debug-report

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:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml
9        android:targetSdkVersion="33" />
9-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml
10
11    <application
11-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:4:5-20:19
12        android:allowBackup="true"
12-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:5:9-35
13        android:appComponentFactory="androidx.core.app.CoreComponentFactory"
13-->[androidx.core:core:1.3.0] C:UsersJason_A.gradlecachestransforms-387c712ceb280b89563e287f590257de7transformedcore-1.3.0AndroidManifest.xml:24:18-86
14        android:debuggable="true"
15        android:icon="@mipmap/ic_launcher"
15-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:6:9-43
16        android:label="@string/app_name"
16-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:7:9-41
17        android:roundIcon="@mipmap/ic_launcher_round"
17-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:8:9-54
18        android:supportsRtl="true"
18-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:9:9-35
19        android:theme="@style/AppTheme" >
19-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:10:9-40
20        <activity
20-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:12:9-19:20
21            android:name="com.example.youtubestartendtime.MainActivity"
21-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:12:19-47
22            android:exported="true" >
22-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:13:13-36
23            <intent-filter>
23-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:14:13-18:29
24                <action android:name="android.intent.action.MAIN" />
24-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:15:17-69
24-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:15:25-66
25
26                <category android:name="android.intent.category.LAUNCHER" />
26-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.xml:17:17-77
26-->G:CodingAndroid_StudioYouTubeStartEndTimeappsrcmainAndroidManifest.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中改变minsdk和targetsdk。Gradle是相同的会修复它,但仍然得到相同的错误。不确定是否有一种方法可以让android studio更清楚地指出问题所在,但我在这里不知所措。

我明白了。转到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'
}

最新更新