Android--------multi-channel packaging (with the help of mobile statistics analytics)

Source: Internet
Author: User

Long time no blog, the reason is to change work, today's Dragon Boat Festival holiday, so to send a blog,

Multi-channel packaging, with the help of Friends of mobile statistical analysis, I hope you will be helpful

Understanding of multi-channel packaging:

Channel package is to add channel information in the installation package, that is channel, corresponding to different channels, such as: Millet market, pea pod, application bao market, etc.

Why provide multi-channel packages?

We want to add a different identity to the installation package, the application to carry the channel information when requesting the network, to facilitate the background to do operational statistics (this is the usefulness of adding channel information).

How to implement multi-channel packaging

In general, the logo of this channel will be placed in a metadata of the Androidmanifest.xml application. The corresponding data can then be obtained from the API in Java.

Go to Theme

Register for friends and add new apps to get Appkey

Introducing Dependencies

' Com.umeng.sdk:common:latest.integration '

Androidmanifest.xml adding Appkey and funnel placeholders

<!--Friends League statistics related Meta-data -        <Meta-dataAndroid:value= "5b2497a6f29d985d850001b3"Android:name= "Umeng_appkey"/><!--Friends Union Appkey -                <Meta-dataAndroid:value= "${umeng_channel_value}"Android:name= "Umeng_channel"/><!--Channel number -

To dynamically replace the value of our placeholder in Build.gradle

defaultconfig {        "Com.zhangqie.channel                "1                 "1.0"        "Android.support.test.runner.AndroidJUnitRunner"        true // a limit          of 65535 of the breakthrough application method Manifestplaceholders = [umeng_channel_value: ' name ']    }

Signature file generation can watch my blog Android Studio apk package, Keystore.jks file generation, get SHA1 security code according to KeyStore key

Signature configuration

Signingconfigs {        Debug {}        //Release Package add signature file configuration         release{            storefile File (".. /channle.jks ")            " 123456 "            " Channle            "" 123456 "}    }    buildtypes {        release {            false            proguardfiles getdefaultproguardfile ( ' Proguard-android.txt '), ' Proguard-rules.pro '            signingconfig signingconfigs.release        }    } 

Channels specify two ways of

  productflavors{        xiaomi{            //manifestplaceholders = [Umeng_channel_value: "Xiaomi "]        }        wandoujia{            //manifestplaceholders = [Umeng_channel_value:" Wandoujia "]        }    }

  //2 productflavors.all{ -flavor.manifestplaceholders = [Umeng_channel_value:name] }

Remove the previous comment, the 2nd place below the code is the second way

Then console Terminal

Enter gradlew assembleRelease   to perform the packaging ( Note: Mac to add this . gradlew assembleRelease /)

Of coursegradlew assembleDebug  这是debug的

You can also specify gradlew assembleWandoujiaRelease the packing of pea pods.

Performing packaging

I met a pit when I got there.

Because my position is wrong.

buildtypes {        release {            false            proguardfiles getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro '            signingconfig signingconfigs.release                 }    } Signingconfigs {        Debug {}        //Release Package add signature file configuration         release{            StoreFile file (".. /channle.jks ")            " 123456 "            " Channle            "" 123456 "}    } 

So be aware that

Package complete

Build APK package.

We can change the name of the APK output

buildtypes {release {minifyenabledfalseproguardfiles Getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro 'signingconfig signingconfigs.release//Specify the output file name of our release package is our channel nameApplicationvariants.all{VariantVariant.outputs.each {Output-def OutFile=Output.outputfileif(OutFile! =NULL&& OutFile.name.endsWith (". apk")) {def fileName= "${variant.productflavors[0].name}" + ". apk"Output.outputfile=NewFile (outfile.parent,filename); }                }            }        }    }

Input gradlew assembleRelease   Execution Packaging

The name has changed, set according to your own needs,

So we can do the multi-channel packing.

Android--------multi-channel packaging (with the help of mobile statistics analytics)

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.