NervJS / taro-native-shell

Taro 原生 React Native 壳子
MIT License
200 stars 106 forks source link

打包成apk出错 #8

Closed SuperMarshtomp closed 5 years ago

SuperMarshtomp commented 5 years ago

android目录下运行

./gradlew assembleRelease --stacktrace

报下面的错误,重装依赖没解决。

> Task :app:bundleReleaseJsAndAssets
Scanning folders for symlinks in /home/chenyx/JS_Project/taro-native-shell/node_modules (9ms)
Scanning folders for symlinks in /home/chenyx/JS_Project/taro-native-shell/node_modules (9ms)
Loading dependency graph, done.

Cannot find entry file index.js in any of the roots: ["/home/chenyx/JS_Project/taro-native-shell"]

> Task :app:bundleReleaseJsAndAssets FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'node'' finished with non-zero exit value 1

* 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:bundleReleaseJsAndAssets'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
        at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
        at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
        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.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
        at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
        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: org.gradle.process.internal.ExecException: Process 'command 'node'' finished with non-zero exit value 1
        at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:395)
        at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:37)
        at org.gradle.api.tasks.AbstractExecTask.exec(AbstractExecTask.java:56)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:801)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:768)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
        ... 31 more

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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 6s
320 actionable tasks: 1 executed, 319 up-to-date
SuperMarshtomp commented 5 years ago

原来是我路径不对

dzlove66 commented 5 years ago

我也遇到一样的问题,具体怎么解决的

szc807414589 commented 5 years ago

这个解决方法是什么

penjj commented 4 years ago

原来是我路径不对

原来是我路径不对

请问下这个是怎么解决的呀

SuperMarshtomp commented 4 years ago

这么多人问,我现在具体也不是很记得这个步骤具体的原因了,应该是我rn_temp的文件夹路径放错了,但是我记录了我当时用这个搞开发的打包apk成功的步骤,下面贴出来:

先说版本

Taro v1.3.9 (1.3.8当时用哪个具体忘了,记得1.3.9修复了个依赖,最好先用1.3.9试试) react-native-cli: 2.0.1 react-native: 0.55.4

1.在 config 目录配置,如:

rn: {
  appJson: {
      "name": "Your App Name",
  }
}

2.taro build --type rn

3.将rn_temp中的文件复制到taro-native-shell根目录下

4.将原工程package.json中需要的依赖添加到taro-native-shell根目录package.json中

5.yarn

6.修改根据https://www.jianshu.com/p/8186b70eb316

1. 路径:taro-native-shell/node_modules/expo-image-picker/android/build.gradle

77:  api 'com.facebook.fresco:fresco:1.10.0' 

版本改为1.9.0
参考issues
https://github.com/NervJS/taro-native-shell/issues/4
2. 注册name保持一致
原生端MainActivity
    @Override
    protected String getMainComponentName() {
        return "taroDemo";
    }

js端路径 rn_temp/index.js
AppRegistry.registerComponent('taroDemo', () => App);
3. 修改node_module源码
路径node_modules/@unimodules/react-native-adapter/build/NativeViewManagerAdapter.js

  const reactNativeUIConfiguration = UIManager.getViewManagerConfig(reactNativeViewName) || {
    NativeProps: {},
    directEventTypes: {},
  };

换成
  const reactNativeUIConfiguration = (UIManager.getViewManagerConfig ? UIManager.getViewManagerConfig(reactNativeViewName) : UIManager[reactNativeViewName]) || {
    NativeProps: {},
    directEventTypes: {},
  };

7.在工程目录下输入命令如下:

react-native bundle --platform android --dev false --entry-file index.js  --bundle-output android/app/src/main/assets/index.android.bundle  --assets-dest android/app/src/main/res/

8.其他就按照https://reactnative.cn/docs/0.55/signed-apk-android/

项目完成时间2019/08/20

SuperMarshtomp commented 4 years ago

@dzlove66 @szc807414589 @biliGates

penjj commented 4 years ago

@dzlove66 @szc807414589 @biliGates

谢谢你的分享,这解决了我的问题。

Leavds commented 4 years ago

@SuperMarshtomp 大佬 按照你这样的方法打release包 确实没问题,谢谢了。有点bug debug包跑不起来,你那边有碰到这个问题吗

smartsimba commented 4 years ago

@SuperMarshtomp 谢谢大佬,打包成功了 但是将rn_temp中的文件复制到taro-native-shell根目录下 这一步会导致taro-native-shell项目目录很乱,官方有方法解决一下吗??

Pines-Cheng commented 4 years ago

@smartsimba

第二种方式:

  1. 在 rn_temp 目录运行 node ../node_modules/react-native/local-cli/cli.js bundle --entry-file ./${TEMP_DIR_NAME}/index.js --bundle-output ./${BUNDLE_DIR_NAME}/index.bundle --assets-dest ./${BUNDLE_DIR_NAME} --dev false 打包 jsbundle
  2. 将生成的 jsbundle 文件和 asset 文件 copy 到 taro-native-shell
  3. 按照 RN 离线包的方式配置