Haven’t written a blog for a long time, people really have inertia! When you start being lazy, you get lazier! Continue to start my blogging career and hope I don’t give up this time!! Okay, what’s today’s quiz question?

Have you ever encountered this problem in a project? Every time to go online, will be in the development of their own branch test, and then hit a test environment package, to test hands to test! Then the test says there is no problem, and then the corresponding test is carried out on the production! This cycle, often need to switch the corresponding network address, a variety of corresponding configuration, sometimes forget what is a catastrophic blow! There are all kinds of problems online. Recently, I read meituan’s open source Wall multi-channel packaging scheme and was greatly inspired, so I have today’s blog!

Knowledge of this article

  • Configuration and packaging of multiple versions
  • Walle configuration and packaging
  • About some of the problems I’m having

Configuration and packaging of multiple versions

Every time I write blog, will first from the small white point of view to think how to use this thing, and then will go to in-depth understanding of how to achieve! All right, ready to go…

Add attributes to the Build. gradle Android TAB of your main module!

ProductFlavors {// Develop {buildConfigField"String"."ENV_TYPE"."\" 1 \ ""
            applicationId 'xxx'
            manifestPlaceholders = [
                    app_name     : "Development",]} // Test environment check {buildConfigField"String"."ENV_TYPE"."\ \" "2"
            applicationId 'xxx'
            manifestPlaceholders = [
                    app_name     : "Test",]} // Production environment product {buildConfigField"String"."ENV_TYPE".3 \ \ "" ""
            applicationId 'xxx'
            manifestPlaceholders = [
                    app_name     : "xxx",]}}Copy the code

Here are some related issues and points to note:

  • BuildConfigField is a related property. If it is a String, it must be followed by a translation character, because if you do not set the translation character, it will generate an int, so pay attention to it!

  • ApplicationId there are a lot of people according to the set corresponding package name, so that the APP can install multiple, make test can install multiple APP test together at the same time, but I found that there is a problem, if such changes, like what laser push, will be affected by the corresponding, so here just test one installed laborious! Malicious smile πŸ˜…!! If any officer has a better plan, you can tell the younger brother, the younger brother would be very grateful!!

  • So, how does the manifestplaceholder project project,

  • App_name Specifies the name displayed in the app

  • Icon Configureapp logo (I didn’t write it here, but this attribute can be used)

  • Configure the corresponding Androidmanifest.xml

App_name will not take effect if you do not configure the corresponding XML.

android:label="${app_name}"
Copy the code

You need to set this in the label so that the name of the app can be changed, and if you set icon, you need to change it as above! I won’t talk any more!

At this point, all you need to do is Sync Now, and you’ll see the corresponding Java file in the file path

You’ll notice that apt is written to your project in the same way you set build.gradle in the main module.

At this time, all the configuration has been configured, this time, you have to set up the corresponding type of processing logic!

  • Corresponding processing logic
String evnType = buildconfig. ENV_TYPE;Copy the code

Here I suggest a single class, the main purpose of this class is to distinguish between the above types!

Public class EnvType {/** * public static final String DEVELOP ="1"; /** * Public static final String CHECK ="2"; /** * public static final String PRODUCT ="3";
}
Copy the code

So get the corresponding type, switch a judgment, done!

  • Details of packing

If you pack normally, you will see the corresponding channel package, but I am after all a lazy person can not be lazy, I have no time to trouble how to do, of course there is a way!

Point this, perfect hit the corresponding channel package, is really where won’t point where ah!

Then you will see the corresponding channel package in the corresponding path, don’t thank me!! Haha…

Walle configuration and packaging

At the time of writing, the latest version on Github is 1.1.6, so here’s my 5m broadsword!

  • Add and configure the corresponding plug-in in your project’s build.gradle!

    It’s already written in the notes, so I don’t have to push too hard

  • Add dependent plug-ins and references to the corresponding main module
// Add aar Apply plugin for the appropriate channel:'walle'
Copy the code
/* Multichannel library */ implementation'com. At meituan. Android. Walle: library: 1.1.6'
Copy the code

Gradle in app build.gradle. In fact, the configuration similar to “Butterknife” is just some ideas of APT.

  • Configure the corresponding output

That’s the point. Why do you say that? Because this is how you configure the output of the content!

Walle {// Specify the output path of channel package apkOutputFolder = new File("${project.buildDir}/outputs/channels"); // Custom channel package APK file name apkFileNameFormat ='${appName}-${packageName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk'; ChannelFile = new File("${project.getProjectDir()}/channel")}Copy the code

Here is a description of the configuration item:

  • ApkOutputFolder: Specifies the output path of the channel package. Default is new File(“${project.builddir}/outputs/apk”)
  • ApkFileNameFormat: The file name of the APK for the custom channel package. The default value is’{buildType}-${channel}.apk’
  • The following variables can be used: AppName – App module name packageName – applicationId (App packageName packageName) buildType – buildType (release/debug) channel-channel name (corresponding to the channel name in the channel packaging) versionname-versionname (version number used for display) versionCode – versionCode BuildTime – buildTime fileSHA1 – fileSHA1 (SHA1 hash of the final APK file) flavorName – Build productFlavors name
  • ChannelFile: indicates the file path containing channel configuration information. For details, see the channel configuration file example. You can add comments with # marks.

There are just a few things to note here:

  • Corresponding output path
  • Channel name (in fact, there is no need to be so complicated, so much is written here, because there is so much written in the official document, in fact, you can delete it)
  • Channel file this should be placed under the main module, or you will have to change the address!
anzhi # android
baidu # baidu. yybPo # application
Copy the code

The configuration is basically so much, basically can meet your needs! There is a place for adding additional information, but I don’t think it works πŸ˜‚, so I didn’t go there!

You should be able to use the command line for this packaging, but I think it’s pretty easy, so? You hit a button like this, it’s all done!

Notice this thing I circled, this is the official build, you need to take the official build to work, beta you don’t need to pack channels! What do you think? (β˜ΊοΈπŸ˜’β˜ΊοΈ clip me in the product)

Just click on it and you’ll see what you want in this path!

About some of the problems I’m having

  • Error: All flavors must now belong to a named flavor dimension. There are a number of ways around this error on the Internet, basically adding a sentence I circled in the position below

  • Plugin requires ‘APK Signature Scheme v2 Enabled’ for ProductRelease. The error about this is that you did not configure the corresponding JKS file in the project.

  • The command line could not be packaged successfully

In fact, I have struggled with this problem for a long time, why? I typed the command line as Github said, but nothing worked. Finally, I noticed that the multi-channel assemble had already been generated, so it couldn’t be packaged according to Github. With the above screenshot assembleXXXReleaseChannels can! Pay attention to the corresponding Ming Ming is ok!


Well, that’s all for today! Hope to be helpful to you! Thank you for your precious time!!