In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how Taro packages Android apk. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
First, we use the command to create a template project, as follows.
Taro init myApp
Then, install the dependency package using yarn or npm install, and compile the Taro project using the following command.
Yarn dev:rn
After startup, a monitoring process will be started.
However, if you are careful, you may find that projects initialized with the taro init command are not supported by native modules. It turns out that Taro uses a shell project. First download the shell project taro-native-shell using the following command, as shown below.
Git clone git@github.com:NervJS/taro-native-shell.git
Install the dependency using yarn or npm install in the taro-native-shell directory and start the shell project using the following command.
React-native run-android
However, the following error was reported after startup:
Error: bundling failed: NotFoundError: Cannot find entry file index.js in any of the roots: ["/ Users/mac/Taro/work/taro-yanxuan"] at DependencyGraph.getAbsolutePath (/ Users/mac/Taro/work/taro-yanxuan/node_modules/metro/src/node-haste/DependencyGraph.js:317:11) at / Users/mac/Taro/work/taro-yanxuan/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:280:416 at Generator.next () at The error reported on step (/ Users/mac/Taro/work/taro-yanxuan/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:11:445) at / Users/mac/Taro/work/taro-yanxuan/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:11:605 at processTicksAndRejections (internal/process/task_queues.js:97:5) means that the entry file index.js for RN cannot be found. For this problem, you only need to change the getJSMainModuleName in MainApplication.java to:
Rn_temp/index
That's fine, because the package Taro packed is in the rn_temp directory, and the latest react-native-shell has been fixed.
After modification, re-execute the react-native run-android command.
However, since the project is below version 0.60.0, I reported the following error at run time.
React Native version mismatchjavascript version 0.55.4Native version 0.64.0
This is because the react-native-shell is 0.64.0 and my RN project is 0.55.4, so I can only upgrade or downgrade the RN project.
React-native-shell . If there are no errors, you can then make an offline apk package.
First of all, you need to generate the key file of Android. About how to generate the key file, you can find the relevant information yourself and copy the generated key file to the android/app folder in the project. Then, add the following constant code to / android/gradle.properties.
MYAPP_RELEASE_STORE_FILE=my-release-key.keystoreMYAPP_RELEASE_KEY_ALIAS=my-key-aliasMYAPP_RELEASE_STORE_PASSWORD=*MYAPP_RELEASE_KEY_PASSWORD=*
Then, add the following code to the app/build.gradle file.
Release {if (project.hasProperty ('MYAPP_UPLOAD_STORE_FILE')) {storeFile file (MYAPP_UPLOAD_STORE_FILE) storePassword MYAPP_UPLOAD_STORE_PASSWORD keyAlias MYAPP_UPLOAD_KEY_ALIAS keyPassword MYAPP_UPLOAD_KEY_PASSWORD}}
Next, copy the previously generated rn_temp file to the android folder of the taro-native-shell shell project, and modify the code in MainApplication, as shown below.
@ Override protected String getBundleAssetName () {return ". / android/rn_temp/index";}}
Then, modify and add the following code in android/app/build.gradle.
Project.ext.react = [entryFile: "android/rn_temp/index.js", cliPath: "node_modules/react-native/cli.js"]
Then, execute the following command to generate the index.bundle file, as shown below.
Node. / node_modules/react-native/local-cli/cli.js bundle--entry-file. / android/rn_temp/index.js-- bundle-output. / android/rn_temp/index.bundle-- assets-dest. / rn_bundle-- dev false
Finally, execute the packaging command in the root directory of Android.
. / gradlew assembleRelease
When the package is complete, you can see the signed package in android/app/build/outputs.
These are all the contents of the article "how to package Android apk by Taro". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.