使用' gradlew assembleRelease'反应原生Android构建失败

时间:2017-12-14 11:24:10

标签: android node.js react-native gradle

我的应用程序在Genymotion模拟器中完美运行。 但我正在构建app-release.apk。

React native version: 0.46.x

build.gradle文件:

...
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    ...

当我使用gradlew assembleDebug时,它会成功跟随输出,但在app\build\outputs\apk\debug中生成错误的apk(在模拟器中不是当前的工作版本,但在之前的开发步骤中仍然是旧版本。)

BUILD SUCCESSFUL in 57s
225 actionable tasks: 216 executed, 9 up-to-date

即使我尝试使用gradlew assembleRelease,也会失败并显示跟随输出。

> Task :app:processReleaseResources
Failed to execute aapt
com.android.ide.common.process.ProcessException: Failed to execute aapt
        at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:796)
        at com.android.build.gradle.tasks.ProcessAndroidResources.invokeAaptForSplit(ProcessAndroidResources.java:551)
        at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:285)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing process <Android Sdk Folder>\build-tools\27.0.1\aapt.exe with arguments {package -f --no-crunch -I <Android Sdk Folder>\platforms\android-24\android.jar -M \\?\<My Project Folder>\android\app\build\intermediates\manifests\full\release\AndroidManifest.xml -S <My Project Folder>\android\app\build\intermediates\res\merged\release -m -J \\?\<My Project Folder>\android\app\build\generated\source\r\release -F <My Project Folder>\android\app\build\intermediates\res\release\resources-release.ap_ -G \\?\<My Project Folder>\android\app\build\intermediates\proguard-rules\release\aapt_rules.txt --custom-package com.beostore -0 apk --output-text-symbols \\?\<My Project Folder>\android\app\build\intermediates\symbols\release --no-version-vectors}
        at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:503)
        at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:482)
        at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:79)
        at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:794)
        ... 41 more
Caused by: com.android.ide.common.process.ProcessException: Error while executing process <Android Sdk Folder>\build-tools\27.0.1\aapt.exe with arguments {package -f --no-crunch -I <Android Sdk Folder>\platforms\android-24\android.jar -M \\?\<My Project Folder>\android\app\build\intermediates\manifests\full\release\AndroidManifest.xml -S <My Project Folder>\android\app\build\intermediates\res\merged\release -m -J \\?\<My Project Folder>\android\app\build\generated\source\r\release -F <My Project Folder>\android\app\build\intermediates\res\release\resources-release.ap_ -G \\?\<My Project Folder>\android\app\build\intermediates\proguard-rules\release\aapt_rules.txt --custom-package com.beostore -0 apk --output-text-symbols \\?\<My Project Folder>\android\app\build\intermediates\symbols\release --no-version-vectors}
        at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:73)
        at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:48)
        at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:78)
        at com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:74)
        at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1237)
        at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
        at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:911)
        at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:822)
        at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:664)
        at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:48)
        at com.android.build.gradle.internal.process.GradleProcessExecutor$1.run(GradleProcessExecutor.java:58)
Caused by: org.gradle.process.internal.ExecException: Process 'command '<Android Sdk Folder>\build-tools\27.0.1\aapt.exe'' finished with non-zero exit value 1
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:380)
        at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:46)
        ... 9 more


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> Failed to execute aapt

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 6s
105 actionable tasks: 3 executed, 102 up-to-date

安装了Android构建工具版本:

 23.0.1
 24.0.3
 25.0.0
 25.0.3
 26.0.1
 26.0.2
 27.0.0
 27.0.1

安装平台版本:

 android-21
 android-23
 android-24
 android-25
 android-26

我google了很多,然而,无法找到解决方案。 希望你的帮助很大。

提前致谢。

2 个答案:

答案 0 :(得分:0)

我终于修好了。 我刚刚在currentBundleTask文件中的doFirst{...} react.gradle块下面添加了此块。

doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("${resourcesDir}/drawable-${resSuffix}")
        if (originalDir.exists()) {
            File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")
            ant.move(file: originalDir, tofile: destDir)
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

此答案基于Github中的AvatarQing's comment

感谢您的所有关注。

答案 1 :(得分:0)

我遇到了类似的问题。我已经了解了如何执行aapt并从命令行使用相同的参数启动相同的进程 - 在您的情况下,这将取自您发布的日志(可能您必须替换占位符&#34; Android Sdk文件夹&#34 ;等等,按实际价值计算):

<Android Sdk Folder>\build-tools\27.0.1\aapt.exe package -f --no-crunch -I <Android Sdk Folder>\platforms\android-24\android.jar -M \\?\<My Project Folder>\android\app\build\intermediates\manifests\full\release\AndroidManifest.xml -S <My Project Folder>\android\app\build\intermediates\res\merged\release -m -J \\?\<My Project Folder>\android\app\build\generated\source\r\release -F <My Project Folder>\android\app\build\intermediates\res\release\resources-release.ap_ -G \\?\<My Project Folder>\android\app\build\intermediates\proguard-rules\release\aapt_rules.txt --custom-package com.beostore -0 apk --output-text-symbols \\?\<My Project Folder>\android\app\build\intermediates\symbols\release --no-version-vectors

然后我从aapt进程获得了真正的错误消息,该进程已被抑制 - 在我的情况下,Idea运行了graddle构建并带来了类似的堆栈跟踪,就像你的一样。 我的情况我发现我的AndroidManifest.xml包含一些值,编译器无法理解它,但它可以在你的情况下有所不同,我猜......