Today’s record is to use RN in the work of debugging encountered some problems (Android)
Write debug without saying too much
My development environment
// System Ubuntu 19.04
// RN version React-native 0.61
// develop tool Vscode
Copy the code
1. The SDK is configured successfully, but the initial project of create is not running
// Add a new file named.local.properties in the Android directory
Sometimes it is not possible to find your SDK location
/ / such as:
sdk.dir=/home/wangfpp/Android/sdk
Copy the code
2. The real computer or emulator cannot connect to the local server and cannot be debugged
1.Whether the simulator is enabled/whether the real machine is connected// Enter ADB Devices on the terminal to view the connected devices
// If the device exists then look for another reason
2.Check whether the machine is configured with a debug port// The emulator directly Ctrl + M to shake the phone or ADB shell input keyevent 82 call Devtools
// Dev Settings -> Debug server host for Device Select the penultimate setting
// Enter the IP address of the development machine :8081
/ / reload again
3.If still can't debug// Check whether the mobile phone and the development machine are in the same network segment
4.You may also need to reset the debug port adb Reverse TCP:8081 tcp:8081
Copy the code
The above are the problems I encountered in the debugging can be debugging can find the problem, in the way to solve the problem
How to customize packaging
./gradlew assembleRelease // This command needs to be modified before running on Linux./gradlew chmod sudo chmod +xCopy the code
The react-native packaged APK is app-release.apk/, but the actual online APK is usually named app-release.apk${ProjectName}_${VERSION}-${DATE}.apk
How do I generate/read the values of the three (project name, version, package date) variables?
How do I read the version number
1.Location of the version number// The version number is in package.json
// In js/ JSX we can directly
import packageJson form 'path/package.json'
const { version } = packageJson
// There is no way to import this file in the package script but we can find it
Copy the code
The location of the package script is android/app/build.gradle
## is approximately at line 129 android{.... defaultConfig { applicationId "com.record" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion 1 versionName rootProject. Ext targetSdkVersion versionCode appVersion / / modify the version number} here... } ### def getAppVersion() {## File packageJsonFile this needs to reference the package import in the File header groovy.json.JsonSlurper File packageJsonFile = new File('.. /package.json') ## def jsonslurper = new jsonslurper () ## def packageJson = new jsonslurper ( Jsonslurper.parsetext (packagejsonfile.text) ## return packageJson["version"]} ## define a variable to receive the return value def appVersion = getAppVersion()Copy the code
How can I Change the name of a package file
If (buildName == 'release') {if (buildName == 'release') {if (buildName == 'release') {if (buildName == 'release') createTime = new Date().format("YYYY-MM-dd", Timezone. getTimeZone("GMT+08:00")) def outputFileName = "M2600-${varie.versionName}_${createTime} Println output. GetPackageApplicationProvider () # # packaged output for the new APK name output. OutputFileName = outputFileName}Copy the code
repack
1.Gradlew assembleRelease Is an APK named M26000.01._2020- 03- 07.apk
2.The location of the apk in android/app/build/output/apk/release /...Copy the code
Write a package script
1.Gradlew assembleRelease is too long to remember2.The new release. Sh3. sudo chmod +x ./release.sh
4.Write a package scriptCopy the code
Create a release.sh file in your Android directory
#! /bin/bash
### Android package scriptAPP_HOME="`pwd -P`" ./gradlew assembleRelease if [ $? != 0 ]; Then echo 'exit 1' else: ## build success do somthing
#Cp m2600-0.1_2020-03-07. APK /home/ APK /
## Or do something else
fi
Copy the code
This is just a record of my work
My official account and QQ group