Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.
Xiao CAI is engaged in Android. I once tried to package APK files and failed. Due to various reasons, I suspended the research. The official website explains clearly, side dishes on this basis to sort out the problems encountered in the packaging process.
Packing steps:
- Check the Android environment, generally new applications without special adjustment basically no problem; If you need network requests, you need to add network permissions in the AndroidManifest file; To change the app name and icon, refer to Flutter 05:
<uses-permission android:name="android.permission.INTERNET"/>
Copy the code
- Create the signature file key.jks, which is slightly different from the key file generated in direct Android packaging; You need to run the following command in terminal. And fill in the password and basic user information as instructed; Note: Passwords need to be remembered and key files can be used universally;
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Copy the code
In 3.AndroidConfiguration in the Environmentkey.jksFile information;
3.1 Create a key.properties file whose name is not absolute and fill in the following basic key information in the file;
storePassword=123456 keyPassword=123456 keyAlias=key storeFile=/Users/... /key.jksCopy the code
3.2 ingradleAdd the following message to the file with the corresponding name.
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
Copy the code
- [Terminal] Go to the directory that needs to package the application pubspec.lock, run the following command, and wait. Finally, the APK file directory is generated.
flutter build apk
Copy the code
- Run the packaged application on a terminal device.
JKS file exists but the password is forgotten.
Side dishes have been generated on previous attemptskey.jksFile, but really can’t remember the password, packaging has failed, but to generate a newkey02.jksFiles, use a new signature, but in real projects it is recommended to use a set of signature files, otherwise there will be problems in the upgrade or other situations, so keep passwords and signature files in mind;
keytool -genkey -v -keystore ~/key02.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Copy the code
Tips: Alias and signature files should correspond to those in key.properties.
Error 2: Command not found: flutter
In the past, the plugin was configured with an outside environment and an inside environment, so there was some confusion. This problem is mainlyFlutterEnvironment is not found, need to find the personal configuration of the environment can be, if there is a problem can refer to the side dishes long ago respectivelyWindows 和 MacEnvironment configuration environment under the small blog.
The packaging of Flutter is not a problem. Pay attention to the details, especially the signature files. If there are mistakes, please guide ~
Source: Little Monk A Ce