Multi-version, multi-environment, multi-channel packaging

Source: Internet
Author: User

About multi-version multi-environment content before writing a blog can refer to: https://blog.csdn.net/jhl122/article/details/74540740

1, multi-version needs to be noted is the configuration of signature information:

Signingconfigs {
        Release {
            storefile file (' xxx.jks ')//keystore path
            storepassword "xxxx"
            Keyalias "xx "
            Keypassword" xxxx "
        }
        Debug {
        }
    }

2, multi-environment is used to productflavors, mainly to achieve the application of different environments can be run on a mobile phone at the same time, it is necessary to have a different application name or icon.

productflavors {
        //meetyun development environment
        Meetyun {
            buildconfigfield "int", "Env_type", "1"
            ApplicationID Project.ext.applicationIdDebug
            manifestplaceholders = [
                    app_name:project.ext.appNameDebug
            ]
        }
        //demo Environment
        Demo {
            Buildconfigfield "int", "Env_type", "2"
            ApplicationID Project.ext.applicationIdCheck
            manifestplaceholders = [
                    app_name:project.ext.appNameCheck
            ]
        }//
        production environment
//        Product {
//            Buildconfigfield "int", "Env_type", "3"
//            ApplicationID project.ext.applicationId
//            manifestplaceholders = [
///                    App_name: Project.ext.appNameProduct
//            ]
//        }
    }

And you need to use the placeholder {app_name} in the manifest file

<application
        tools:replace= "label"
        android:name= "xxx"
        android:allowbackup= "true"
        Android: icon= "@mipmap/ic_launcher"
        android:label= "${app_name}"
        android:roundicon= "@mipmap/ic_launcher_round"
        android:supportsrtl= "true"
        android:theme= "@style/apptheme" >

It is important to note that the tools:replace= "label" parameter is required when compiling the name of the label when prompted to repeat it.

Different environment Gradle will generate buildconfig files dynamically according to the Productflavors information:

Public final class Buildconfig {public
  static final Boolean DEBUG = Boolean.parseboolean ("true");
  public static final String application_id = "xxx";
  public static final String build_type = "Debug";
  public static final String FLAVOR = "Demo";
  public static final int version_code = 3;
  public static final String version_name = "00.00.03";
  fields from product Flavor:demo public
  static final int env_type = 2;
}

Set the types of environments depending on your needs:

public class Envtype {public
    static final int meetyun = 1;//meetyun development Environment Public
    static final int DEMO = 2;//demo Test Environment public
    static final int PRODUCT =3;//formal Environment
}

Where Env_type is the value we set in the Gradle.build, we can judge the different environment according to this value, then set the corresponding environment address

public static final String Http_main = Setchannel ();
public static String Setchannel () { 
        int envtype = Buildconfig.env_type;
        Switch (envtype) {case
            Envtype.meetyun:
                return "http://xx";
            Case Envtype.demo:
                return "http://xxxx";
            Default:
                return "http://xxxx";
        }
    }

At this point basically all the configuration is almost complete, this time need to execute the gradle command, two methods: the first to write directly in the terminal command "Gradlew assemble" hit Enter, the second is on the right of the Gradle Projects click on the assemble task to execute. After the command is executed, you will find that the package is already in the Outputs folder.


3, multi-channel packaging is to count the different application market is the channel download information, so generally include two aspects, one is different channel information into the APK file, the second is to return this channel information to the server for statistics, so generally multi-channel packaging is the first case. I use the multi-channel packaging tool is the Walle of the United States, characterized by fast.

The specific operation will not elaborate on GitHub above said very detailed, is to pay attention to this multi-channel file channel is created by itself, not it automatically generated.

Channelfile = new File ("${project.getprojectdir ()}/channel")


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.