“This is my fourth day of participating in the First Challenge 2022. For more details: First Challenge 2022.”
Build. gradle is a file that everyone who has used AS knows what it can do, but I’m sure there are a lot of beginners out there who don’t know what the build.gradle file means. Here’s a look at buildTypes and productFlavors, and a couple of other configurations. First of all, we just createdAndroidBuild. gradle creates two files, one for your project and one for your Module. Here are some configurations in the build.gradle file in the Module. The code in the build.gradle file created by default is shown below:
Of course, there are also some dependencies
Here, we see that buildTypes has been created in the file, which includes some of the release configuration, that is, we publish the APK configuration (mainly obturating the file). Meanwhile, as helps us create a debug version configuration by default, using the default signing certificate, which can be seen through Build Variant.
BuildTypes = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors = productFlavors Baidu search, there will be a lot of similar blogs
What is said here is the blogger’s own understanding and use methods.
- ProductFlavors is an option that can be used for multi-channel packaging
- You can try productFlavors if your application uses different API_URL, different version numbers, different APK files for the same code, etc
Firstly, I will not go into details. I believe that many ape friends have various methods to carry out multi-channel packaging, such as Youmeng and Meituan.
For now, the second point, believe a lot of friends and apes have been feeling like this – an application needs to have many versions of use, such as the debug version, test version, and release, and each version using the interface address is not the same, this kind of situation will need time to modify the interface address and repack test, at least I at first also is such, 0.. 0. ProductFlavors can be configured with different interface addresses, different constants, different AppNames, different logos, and different package names.
ProdcutFlavors is written in the andoID directory. You can see different interface addresses, different package names, etc. Of course, you need to create a folder named for the two versions in the SRC directory of your Module.
Create a Java folder and an RES folder in the folder. The RES folder is used to replace the application logo.
sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src/main/java'] resources.srcDirs = ['src/main/java'] aidl.srcDirs = ['src/main/java'] renderscript.srcDirs = ['src/main/java'] res.srcDirs = ['src/main/res'] assets.srcDirs = ['src/main/assets'] jniLibs.srcDirs = ['libs'] } local.java.srcDirs = ['src/local/java'] local.res.srcDirs = ['src/local/res'] us.java.srcDirs = ['src/us/java'] us.res.srcDirs = ['src/us/res'] }Copy the code
“Local” and “US” files will be used first and will be bundled together with the resources files in the main file. Users will then use Build Variants to change their versions of the app for installation, which will result in different logos and no conflicts between apps. The API_URL in the configuration can be accessed by BuildConfig. Finally, packaging generates four versions of apK files — localDebug.apk, localRelease.apk, usDebug.apk, usRelease.apk — and then uses different APK files for different environments. That’s all for this blog post, thank you!!