React Native:(assembleRelease)错误:文件名无效。无法添加

时间:2017-03-08 20:17:20

标签: android react-native android-gradle react-native-android gradlew

我在尝试使用assembleRelease

构建版本apk时遇到此错误
  

捆绑:完成复制资产:app:processReleaseManifest UP-TO-DATE   :应用: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:processReleaseResources FAILED

     

失败:构建因异常而失败。

并抛出--stacktrace

  

异常是:org.gradle.api.tasks.TaskExecutionException:执行   任务失败':app:processReleaseResources'。在   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.Abs​​tractTaskPlanExecutor $ TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)   在   org.gradle.execution.taskgraph.Abs​​tractTaskPlanExecutor $ 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)   在org.gradle.internal.Factories $ 1.create(Factories.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。创建(DefaultGradleLauncher.java:98)   在   org.gradle.initialization.DefaultGradleLauncher $ 1。创建(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.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:81)   在   org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:46)   在   org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)   在   org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)   在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)   在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)   在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:无法执行   哎呀   com.android.build.gradle.tasks.ProcessAndroidResources.doFullTask​​Action(ProcessAndroidResources.java:185)   在   com.android.build.gradle.internal.tasks.IncrementalTask​​.taskAction(IncrementalTask​​.java:82)   在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)   在   org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ IncrementalTask​​Action.doExecute(AnnotationProcessingTaskFactory.java:245)   在   org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)   在   org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ IncrementalTask​​Action.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:无法执行   哎呀   com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:873)   在   com.android.build.gradle.tasks.ProcessAndroidResources.doFullTask​​Action(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_   --custom-package com.demoturismocity -0 apk --output-text-symbols / var / www / react-native-tc-demo / android / app / build / intermediates / symbols / release   com.google.common.util.concurrent.AbstractFuture $ Sync.getValue(AbstractFuture.java:299)中的--no-version-vectors}   在   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_   --custom-package com.demoturismocity -0 apk --output-text-symbols / var / www / react-native-tc-demo / android / app / build / intermediates / symbols / release   com.android.build.gradle.internal.process.GradleProcessResult.buildProcessException(GradleProcessResult.java:75)中的--no-version-vectors}   在   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)   在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:进程'命令   ' /home/alejandro/Android/Sdk/build-tools/23.0.1/aapt''完成了   非零退出值1 at   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 assembleRelease

其他信息

我需要一个组件 该文件(MAirlines.png)位于/ src / screens / Vuelos / screens / Busqueda / component / Trayecto /航空公司

  • React Native version:0.40.0
  • 平台:Android
  • 操作系统:Ubuntu 16.04
  • Gradle版本2.2.3

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

我遇到过类似的问题。如果您之前运行过cd android &&./gradlew assembleDebug,为了在真实设备上进行测试并使用react-native bundle ...进行捆绑,它会复制app/src/main/res/drawable-*下的一些资产文件。在使用assembleRelease之前,您最好删除这些文件夹。

答案 1 :(得分:1)

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个字符。