尝试使用 assembleRelease 构建发布 apk 时遇到此错误
捆绑包:完成复制资产:应用程序:进程发布清单 最新 :app:processReleaseResources/var/www/react-native-tc-demo/android/app/build/intermediates/res/merged/release/drawable-mdpi/src_screens_vuelos_screens_idavueltacontainer_screens_busqueda_components_trayecto_airlines_mairlines.png: 错误:文件名无效。无法添加。
:app:processRelease资源失败
失败:生成失败,出现异常。
这抛出 --stacktrace
异常是:org.gradle.api.tasks.TaskExecutionException: Execution 任务":应用:进程发布资源"失败。在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) 在 org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) 在 org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66) 在 org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 在 org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52) 在 org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 在 org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53) 在 org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185) 在 org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66) 在 org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50) 在 org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25) 在 org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110) 在 org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37) 在 org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 在 org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23) 在 org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43) 在 org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 在 org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 在 org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30) 在 org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:153) at org.gradle.internal.Factory$1.create(Factory.java:22) at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53) 在 org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:150) 在 org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:32) 在 org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:98) 在 org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:92) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91) 在 org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63) 在 org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:92) 在 org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:83) 在 org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:99) 在 org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28) 在 org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) 在 org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:48) 在 org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:30) 在org.gradle.launcher.exec.ContinuBuildActionExecuter.execute(ContinuBuildActionExecuter.java:81) 在 org.gradle.launcher.exec.ContinuBuildActionExecuter.execute(ContinuBuildActionExecuter.java:46) 在 org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51) 在 org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28) at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43) 在 org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:173) 在 org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:239) 在 org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:212) 在 org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35) 在 org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24) 在 org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) 在 org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) 在 org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:205) 在 org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169) at org.gradle.launcher.Main.doAction(Main.java:33) at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:55) 在 org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:36) at org.gradle.launcher.GradleMain.main(GradleMain.java:23) at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30) 在 org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127) 在 org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61) 由以下原因引起:java.lang.RuntimeException: com.android.ide.common.process.ProcessException: 无法执行 AAPT 在 com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:185) 在 com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:82) at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75) 在 org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245) 在 org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221) 在 org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232) 在 org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210) 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) 在 org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) ...60 更多 原因: com.android.ide.common.process.ProcessException: 无法执行 AAPT 在 com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:873) 在 com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:178) ...68 更多 原因: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:执行时出错 '/home/alejandro/Android/Sdk/build-tools/23.0.1/aapt' 带参数 {package -f --no-crunch -I/home/alejandro/Android/Sdk/platforms/android-23/android.jar -M/var/www/react-native-tc-demo/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml -S/var/www/react-native-tc-demo/android/app/build/intermediates/res/merged/release -m -J/var/www/react-native-tc-demo/android/app/build/generated/source/r/release -F/var/www/react-native-tc-demo/android/app/build/intermediates/res/resources-release.ap_ --自定义包 com.demoturismocity -0 apk --output-text-symbol/var/www/react-native-tc-demo/android/app/build/intermediates/symbols/release --no-version-vectors} at com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:299) 在 com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:286) 在 com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116) 在 com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:871) ...69 更多 原因: com.android.ide.common.process.ProcessException:执行时出错 '/home/alejandro/Android/Sdk/build-tools/23.0.1/aapt' 带参数 {package -f --no-crunch -I/home/alejandro/Android/Sdk/platforms/android-23/android.jar -M/var/www/react-native-tc-demo/android/app/build/intermediates/manifests/full/release/AndroidManifest.xml -S/var/www/react-native-tc-demo/android/app/build/intermediates/res/merged/release -m -J/var/www/react-native-tc-demo/android/app/build/generated/source/r/release -F/var/www/react-native-tc-demo/android/app/build/intermediates/res/resources-release.ap_ --自定义包 com.demoturismocity -0 apk --output-text-symbol/var/www/react-native-tc-demo/android/app/build/intermediates/symbols/release --no-version-vectors} at com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:75) 在 com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:49) 在 com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:78) 在 com.android.builder.internal.aapt.AbstractProcessExecutionAapt$1.onSuccess(AbstractProcessExecutionAapt.java:74) at com.google.common.util.concurrent.Futures$6.run(Futures.java:1319) 在 com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457) 在 com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156) 在 com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145) 在 com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185) 在 com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53) 在 com.android.build.gradle.internal.process.GradleProcessExecutor$1.run(GradleProcessExecutor.java:60) 由以下原因引起:org.gradle.process.internal.ExecException: process 'command '/home/alejandro/Android/Sdk/build-tools/23.0.1/aapt'' 完成 非零退出值 1 在 org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:367) 在 com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:47) ...9 更多
构建失败
繁殖
CD android &&./gradlew 组装发布
附加信息
我需要来自 该文件(MAirlines.png)位于/src/screens/Vuelos/screens/Busqueda/component/Trayecto/airlines
- 反应原生版本:0.40.0
- 平台: 安卓
- 操作系统: 乌班图 16.04
- Gradle 版本 2.2.3
有什么想法吗?
我遇到了类似的问题。如果您之前运行过cd android &&./gradlew assembleDebug
,为了在真实设备上进行测试并使用react-native bundle ...
捆绑使用,它会在app/src/main/res/drawable-*
下复制一些资产文件。在使用assembleRelease
之前,您最好删除这些文件夹。
在assembleRelease
期间,React Native 使用新名称将图像复制到 android 可绘制文件夹,该文件夹由采用图像路径、小写、用下划线替换斜杠、删除非法字符并删除assets_
前缀(如果存在)组成:https://github.com/facebook/react-native/blob/b0d68c0bb971a44dfdf7722682933f1e96e1cd45/local-cli/bundle/assetPathUtils.js#L63
function getAndroidResourceIdentifier(asset: PackagerAsset) {
var folderPath = getBasePath(asset);
return (folderPath + '/' + asset.name)
.toLowerCase()
.replace(///g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
}
例如:src/components/MyComponent/components/SubComponent/images/myimage.png
变为src_components_mycomponent_components_subcomponent_images_myimage.png
当生成的文件名太长时,会出现此问题。更具体地说,当生成的文件名超过 100 个字符时,就会发生这种情况:https://issuetracker.google.com/issues/36953084
在 React Native 中还有一个未解决的问题:https://github.com/facebook/react-native/issues/16263
此问题的解决方法是将图像移动到嵌套不太深的单独文件夹中,从而导致可绘制文件名不超过 100 个字符。