我得到这个错误,而我正在构建APK。
Cause 1: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
at org.gradle.workers.internal.DefaultWorkerExecutor$WorkerExecution.waitForCompletion(DefaultWorkerExecutor.java:285)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:115)
at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:87)
at org.gradle.workers.internal.DefaultWorkerExecutor.await(DefaultWorkerExecutor.java:150)
at com.android.build.gradle.internal.tasks.Workers$WorkerExecutorAdapter.await(Workers.kt:282)
at com.android.ide.common.resources.MergeWriter.end(MergeWriter.java:48)
at com.android.ide.common.resources.MergedResourceWriter.end(MergedResourceWriter.java:242)
at com.android.ide.common.resources.DataMerger.mergeData(DataMerger.java:292)
at com.android.ide.common.resources.ResourceMerger.mergeData(ResourceMerger.java:384)
at com.android.build.gradle.tasks.MergeResources.lambda$doFullTaskAction$1(MergeResources.java:261)
at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:58)
试图使缓存无效并重新启动android工作室。重建项目,但没有一个为我工作。
当你试图构建一个使用VectorDrawable作为自适应图标的应用程序时,你可能会遇到这样的错误。和你的XML文件包含"android:fillColor"与<梯度>块:
res - drawable icon_with_gradient xml。
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="96dp"
android:height="96dp"
android:viewportHeight="100"
android:viewportWidth="100">
<path
android:pathData="M1,1 H99 V99 H1Z"
android:strokeColor="?android:attr/colorAccent"
android:strokeWidth="2">
<aapt:attr name="android:fillColor">
<gradient
android:endColor="#156a12"
android:endX="50"
android:endY="99"
android:startColor="#1e9618"
android:startX="50"
android:startY="1"
android:type="linear" />
</aapt:attr>
</path>
</vector>
渐变填充颜色通常用于自适应图标,例如在教程中这里,这里和这里。
即使布局预览工作正常,当你构建应用程序时,你会看到这样的错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Error while processing Project/app/src/main/res/drawable/icon_with_gradient.xml : null
(More info shown when the gradle build is run with --stack-trace flag):
Caused by: java.lang.NullPointerException
at com.android.ide.common.vectordrawable.VdPath.addGradientIfExists(VdPath.java:614)
at com.android.ide.common.vectordrawable.VdTree.parseTree(VdTree.java:149)
at com.android.ide.common.vectordrawable.VdTree.parse(VdTree.java:129)
at com.android.ide.common.vectordrawable.VdParser.parse(VdParser.java:39)
at com.android.ide.common.vectordrawable.VdPreview.getPreviewFromVectorXml(VdPreview.java:197)
at com.android.builder.png.VectorDrawableRenderer.generateFile(VectorDrawableRenderer.java:224)
at com.android.build.gradle.tasks.MergeResources$MergeResourcesVectorDrawableRenderer.generateFile(MergeResources.java:413)
at com.android.ide.common.resources.MergedResourceWriter$FileGenerationWorkAction.run(MergedResourceWriter.java:409)
解决方案是将文件icon_with_gradient.xml移动到drawable-v24/icon_with_gradient.xml或drawable-v26/icon_with_gradient.xml。这是因为梯度填充只在API 24 (Android 7)及以上版本中支持。VectorDrawable:无效的可绘制标签梯度
几分钟前,当我试图在我的C/(.something. /.something. /.something. /.something....)目录中运行一个flutter项目时,我也遇到了同样的问题,
所以我在我的E目录中创建了一个新文件夹,并在那里启动了一个新项目,当我运行它.....令人惊讶的是,它竟然起作用了。我不知道为什么?
这是我在运行E: directory后得到的消息
Launching lib\main.dart on Lenovo K33a42 in debug mode...
Running Gradle task 'assembleDebug'...
Checking the license for package Android SDK Platform 28 in
C:\Users\Shankar\AppData\Local\Android\sdk\licenses
License for package Android SDK Platform 28 accepted.
Preparing "Install Android SDK Platform 28 (revision: 6)".
"Install Android SDK Platform 28 (revision: 6)" ready.
Installing Android SDK Platform 28 in
C:\Users\Shankar\AppData\Local\Android\sdk\platforms\android-28
"Install Android SDK Platform 28 (revision: 6)" complete.
"Install Android SDK Platform 28 (revision: 6)" finished.
Parameter format not correct -
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
Debug service listening on ws://127.0.0.1:51105/5xCsT5vV62M=/ws
Syncing files to device Lenovo K33a42...
解决方案:
Caused by 4: com.android.builder.internal.aapt.AaptException: Dependent features configured but no package ID was set.
所有特性模块都必须应用库插件,而不是应用程序插件。
构建。gradle (androidApp: feature_A)
apply plugin: 'com.android.library'
这完全取决于每个组件的堆栈跟踪。原因1 WorkExecutionException可能是其他原因导致的。因此,我建议从最后一个原因到第一个原因读取完整的堆栈跟踪。因此,如果我们解决了最后一个原因,很可能我们就已经固定了从最后一个原因到第一个原因的链条。
我附上我的堆栈跟踪的一个例子,原始或具体的问题是在最后的原因:
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
Caused by: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-4.2.0-alpha16-6840111-linux Daemon #0: Unexpected error during link, attempting to stop daemon.
Caused by: java.io.IOException: Unable to make AAPT link command.
Caused by 4: com.android.builder.internal.aapt.AaptException: Dependent features configured but no package ID was set.
GL
特性包ID未设置
gradle.proprites
org.gradle.jvmargs=-Xmx1536M
build.gradle
defaultConfig {
multiDexEnabled true
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
然而这些东西并没有解决我的问题,直到我增加编译esdkversion从27到28,它为我工作。
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
crunchPngs false
}
}
}
在android文件夹根的本地属性中设置最小sdk版本为21:
flutter.minSdkVersion=21
在app->build.gradle中
defaultConfig {
[...]
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
根据文件:
注意:当针对Android SDK 21或更高版本时,Multidex支持是原生的。
他们还谨慎地警告说:
但是,不建议仅仅针对API 21+来解决多重索引问题,因为这可能会无意中排除运行旧设备的用户。
但是SDK 21在10年前就发布了Android版本5,0 Lollipop,如你所见:https://en.wikipedia.org/wiki/Android_Lollipop(更不用说这些设备,如果它们仍然存在,通常有能力升级他们的Android版本)。