<span id="Label3"></p><p><p><span style="font-size: 18px;"><strong>1) Manual Packaging</strong></span></p></p><p><p>Once the project is finished, it is time to upload the application to the market, and the problem arises-how to turn the code into. apk (installable files for android).<br><br>1. Create a signature file<br></p></p><p><p>2. Fill in the signature parameters<br><br></p></p><p><p>3. Build APK<br>Note: signed password and key password attention to keep, do not forget, signature file Don't leak, also don't lose</p></p>Why are you packing?<p><p>I have this question at the beginning, our code is not to click the Run button to install directly to the phone, we can find the new app-debug.apk in the project catalog directory <code>build/outputs/apk</code> . just pass this on to the Market.<br><br></p></p><p><p>no, Of course not, think about the phone when installing the app how to distinguish the various APK.<br>By the <strong>package name + signature</strong> to determine the uniqueness of an application, the debug.apk is only used to debug the system for us, if uploaded to the market, how to ensure his Security.</p></p><p><p></p></p><p><p>OK, we've solved the first step-how to Pack. After uploading, the market feedback found that our app is too good to write, this time the boss let's hurry up on some platforms, mainstream platform, Non-mainstream platform to put up.<br>So the problem comes, in order to facilitate the statistics of the installation of each platform, in line with the operation of promotion, the need to count the installation of each PLATFORM.</p></p>Sub-channel Packaging<p><p>yes, we need to use a sub-channel packaging, then we need to solve two problems<br>1. <strong>How to differentiate the identity of each platform</strong><br>2. <strong>How to generate dozens of packages, hundreds of packages per version update</strong><br>The first simple, with friends of the league pack of classmates must not be unfamiliar with this code</p></p><pre><pre><meta-data android:name=<span style="color: #800000;">"</span><span style="color: #800000;">umeng_channel</span><span style="color: #800000;">"</span> android:value=<span style="color: #800000;"></span>"<span style="color: #800000;">channel_id </span> <span style="color: #800000;">"</span>></meta-data></pre></pre><p><p>Value is filled in the values of each platform, such as the completion of uc, Yyb (app bao), 360, Baidu replaced <code>Channel_ID</code> , the app is installed, you can read this value and then passed to the background, so as to differentiate the installation requirements of each PLATFORM.<br>Second Question:<br>In the Eclipse era, I was the first to manually hit, a dozen 30 packs, every time the most afraid of version updates, the basic one afternoon are doing mechanical movement, now think up hands are cramping.<br>later, learned ant automatic packaging, fast is fast, just configure too pit dad, Super Trouble.<br>Now with Android Studio, mom doesn't have to worry about me being able to pack up happily.<br>Create a new project and modify the Module:app <code>build.gradle</code> to</p></p><pre>Apply Plugin:<span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">com.android.application</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">android {signingconfigs {config {keyalias</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">maker</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">Keypassword</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">1234make</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">storefile file (</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">/users/nevermore/androidstudioprojects/blog/jks/makeapp.jks</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">) Storepassword</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">make1234</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">}} compilesdkversion</span></span><span style="color: #800080;"><span style="color: #800080;"></span> at</span><span style="color: #000000;"><span style="color: #000000;">buildtoolsversion</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">23.0.3</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">defaultconfig {applicationid</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Com.example.makeapp</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">minsdkversion</span></span><span style="color: #800080;"><span style="color: #800080;"></span> the</span><span style="color: #000000;"><span style="color: #000000;">targetsdkversion</span></span><span style="color: #800080;"><span style="color: #800080;"></span> at</span><span style="color: #000000;"><span style="color: #000000;">Versioncode</span></span><span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;">Versionname</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">1.0</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">} buildtypes {debug {minifyenabled</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">false</span></span><span style="color: #000000;"><span style="color: #000000;">debuggable</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">} release {minifyenabled</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">true</span></span><span style="color: #000000;"><span style="color: #000000;">proguardfiles Getdefaultproguardfile (</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">Proguard-android.txt</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span>),<span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">Proguard-rules.pro</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">signingconfig signingconfigs.config debuggable</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">false</span></span><span style="color: #000000;"><span style="color: #000000;"> } }</span></span></pre><pre><pre><span style="color: #000000;"> Channel Configuration</span></pre></pre><pre><pre><span> productflavors {</span></pre></pre><pre><span style="color: #000000;"><span style="color: #000000;">UC {manifestplaceholders</span></span>= [<span style="background-color: #ff0000;"><span style="background-color: #ff0000;">Umeng_channel_value</span></span>:<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">UC</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]} _360 {manifestplaceholders</span></span>= [<span style="background-color: #ff0000;"><span style="background-color: #ff0000;">Umeng_channel_value</span></span>:<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;"></span> the</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]} Baidu {manifestplaceholders</span></span>= [<span style="background-color: #ff0000;"><span style="background-color: #ff0000;">Umeng_channel_value</span></span>:<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Baidu</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]} yyb {manifestplaceholders</span></span>= [<span style="background-color: #ff0000;"><span style="background-color: #ff0000;">Umeng_channel_value</span></span>:<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Yyb</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]}}} dependencies {compile filetree (dir:</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">Libs</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span>, Include: [<span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">*.jar</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">]) Testcompile</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">junit:junit:4.12</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">Compile</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">com.android.support:appcompat-v7:23.3.0</span></span><span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #000000;"><span style="color: #000000;">}</span></span></pre><p><p></p></p><p><p>We need to configure:</p></p><p><p><code>signingConfigs</code>This is our new key information <code>buildTypes</code> package type, including the Debug and release <code>productFlavors</code> packaging channels are configured here at the same time in the Androidmanifest add, channel identification (note The red figure of the string must be on the Right)</p></p><p><p><manifest package= "example.com.makeapk" xmlns:android= "http://schemas.android.com/apk/res/android" ><br><application><br><meta-data android:name= "umeng_channel" android:value= "${<span style="background-color: #ff0000;">umeng_channel_value</span>}" > ... Ellipsis </meta-data><br></application><br></manifest></p></p><p><p></p></p><p><p>3 <strong>now There's another question--how do you generate a channel pack when the code is finished?</strong></p></p><p><p>OK, at the command line input <code>gradlew assembleRelease</code> , indicates that all release packages are generated, the generated package is in the <code>build\outputs\apk</code> directory, if you want to generate the specified package (uc|360|baidu), the specified version (release| Debug), on the right <code>Gradle Project</code> can help you<br></p></p> <p><p><br>4. <strong>Remove the <code>unaligned.apk</code> extra</strong><br>execute-- <code>gradlew assembleRelease</code> , find a problem, generate not only the package we need, the <code>unaligned.apk</code> type of APK is also lost<br><br><br><br><code>unaligned.apk</code>is not the implementation of the alignment command package, is the middle form, this need to delete, no need not to know why Gradle did not help us to delete this useless thing, the problem is we do not want to one of the manual Deletion. well, write a script command that executes in the output Folder command line as Follows:</p></p><pre><pre><span style="color: #800000;">"</span> <span style="color: #800000;">*-unaligned.apk</span> <span style="color: #800000;">"</span> | Xargs RM-RF</pre></pre><br><p><p>5 <strong>Optimizing Gradle code</strong><br>The code you just wrote</p></p><pre><pre> <span style="color: #000000;">productflavors {uc {manifestplaceholders </span> = [umeng_channel_va LUE: <span style="color: #800000;" "< span> <span style=" color: #800000; ">uc </span> <span style="color: #800000;"> "</span> <span style="color: #000000;" ]} _360 {manifestplaceholders < span> = [umeng_channel_value: <spa n style="color: #800000;"> " </spa></span> <span style=" color: #800000; ">360 </span> <span style=" color: #800000; ">" </span> <span style="color: #000000;" ]} baidu {manifestplaceholders < span> = [umeng_channel_value: <span style=" color: #800000; "> ' <!-- Span--><span style="color: #800000;">baidu </span> <span style="color: #800000;" "< span> <span style="color: #000000;" ]} yyb {manifestplaceholders < span> = [umeng_channel_value: <span style="color: #800000;"> "</span> <span style=" color: #800000; ">yyb </span> <span style=" color: #800000; ">" </span> <span style="color: #000000;" ] }}< span></span></span></span></span></span></span></pre> </pre><p><p><br>Some redundancy, modified to reduce the amount of our code</p></p><pre><pre><span style="color: #000000;">productflavors { UC {} _360 {} Baidu {} yyb </span><span style="color: #000000;"> </span>{}} =<span style="color: #000000;"> [umeng_ channel_value:name]}</span></pre></pre><p><p>Is it more beautiful?<br><br></p></p><p><p>6. <strong> <code>Gradle</code> The grammar has a learning curve for the newcomer, can it be any easier<br></strong><br>We have the tools, open the top build.<br><br><br>Select the red section, the inside of the edit box can help us get acquainted with gradle faster<br><br><br><br><br><br><br><br><br><br>Let's take a look at the specifics of the Code and edit Boxes.<br><br><br><br>7. <strong>Packing too much, need to clean up<br></strong><br></p></p><br>Fast Packaging-modify channel numbers directly<em id="__mceDel" style="font-size: 1.5em;"><em id="__mceDel" style="font-size: 1.5em;"></em></em><p><p>Think about it, There's no need to compile the entire project to generate the channel number if you're just hitting the channel Pack.<br>If you can directly modify the APK channel number, and do not need to re-sign can save a lot of packaging time. fortunately, we have found this way. Directly unzip the apk, the extracted root directory will have a meta-inf directory.<br>If you add an empty file within the Meta-inf directory, you do not have to re-sign the app. therefore, you can uniquely identify a channel by adding different empty files for different channels of Application.<br>In this way, one channel package per dozen only needs to copy an apk and add an empty file named after the channel number in META-INF.<br>This packaging is very fast, and more than 900 channels can be played in less than a Minute.<br>yes, That's The strategy of the American Mission.</p></p><p><p>How to Use: Https://github.com/GavinCT/AndroidMultiChannelBuildTool<br>Using this tool, Android programmers only need to put Channelutil.java into the project to use, later packaging things do not have to do their own.<br>Install a Python environment, run a multichannelbuildtool.py, anyone can pack!<br>After all, practice is the only criterion for testing truth:<br>Copy one that we just generated to the <code>app-uc-release.apk</code> project directory</p></p><p><p> </p></p> <center> <center></center> </center><p><p>Sure enough, 1S came out so many bags.</p></p><p><p>Anti-compilation look, The bag is playing right<br>Command line</p></p><pre><pre> Apktool D xxx.apk</pre></pre><p><p></p></p><p><p><br>Open the directory and first confirm the identifiers in the XML we generated<br><br><br><br>And then we saw that the group was finished with the fast Package.</p></p><p><p></p></p><p><p><br>however, using Gradle to generate 4 channels, we spent the <code>26.5秒</code> others only spent a visual<code>1s</code></p></p><p><p>Source Text Address</p></p><p><p>Android Studio Package All Tips</p></p></span>
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