Android studio 打包及优化

    1. Android studio 打包
    1. Android Studio 引用第三方库(Jar)
    1. Gradle多渠道打包
    1. 美团多渠道打包
    1. 修改release包的输出文件名
    1. 在同一设备上同时安装多个不同功能点的app

1. Android studio 打包

  • 1.打出一个签名的apk
TMj7Dc5.png
  • 2.选择签名文件
5g0oQqD.png
  • 3.创建一个新的签名文件
FKznbLt.png
  • 4.完成签名文件配置
AwcshG5.png
  • 5.选择APK的版本和存储路径
dYvKB68.png

2. Android Studio 引用第三方库(Jar)

1.PNG
2.PNG
3.PNG
4.PNG
5.PNG
6.PNG
7.PNG
8.PNG

3. Gradle多渠道打包

Paste_Image.png
Paste_Image.png
  • productFlavors 另一种简便写法
productFlavors {
 
百度{}
华为{}
应用宝{}
360{}
 
productFlavors.all { flavor ->
flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
 
}
  • 使用命令行打包

在Terminal中使用命令gradlew assembleRelease自动打出所有的渠道包
gradlew assembleDebug //所有平台的debug包
gradlew assemblewandoujiaRelease //只打wandoujia的Release包

4. 美团多渠道打包

Paste_Image.png
Paste_Image.png
Paste_Image.png

关于美团多渠道打包:http://blog.csdn.net/wlwenming/article/details/51699457
使用新版美团多渠道打包的正确姿势 :http://blog.csdn.net/wangliblog/article/details/59547685

5. 修改release包的输出文件名

buildTypes {
        release {
            minifyEnabled true          //代码瘦身
//            shrinkResources true        //资源文件瘦身
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  //代码混淆
            //添加我们的签名文件配置
            signingConfig signingConfigs.release

            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outFile = output.outputFile
                    if (outFile != null && outFile.name.endsWith(".apk")) {
//                       + '_' + variant.productFlavors[0].name    defaultConfig.applicationId
                        def fileName = 'xingchou_v' + defaultConfig.versionName + '.apk'
                        output.outputFile = new File(outFile.parent, fileName);
                    }
                }
            }
        }

        debug {
            signingConfig signingConfigs.release

            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outFile = output.outputFile
                    if (outFile != null && outFile.name.endsWith(".apk")) {
//                       + '_' + variant.productFlavors[0].name
                        def fileName = 'xingchou_v' + defaultConfig.versionName + '.apk'
                        output.outputFile = new File(outFile.parent, fileName);
                    }
                }
            }
        }
    }

6. 在同一设备上同时安装多个不同功能点的app

 //多渠道的支持
    productFlavors{
        okhttp{
            //给defaultConfig.applicationId添加后缀(不会影响程序中获取的包名)
            applicationIdSuffix"okhttp"
            resValue "string", "app_name", "okhttp_app"
        }
        jpush{
            applicationIdSuffix"jpush"
            resValue "string", "app_name", "jpush_app"
        }
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,839评论 25 709
  • 版权声明:本文为LooperJing原创文章,转载请注明出处! · 读完这篇博客,你会了解到这些内容 1、Andr...
    LooperJing阅读 11,359评论 7 49
  • 目录一、Python打包及优化(美团多渠道打包)二、Gradle打包三、其他打包方案:修改Zip文件的commen...
    守望君阅读 11,047评论 4 17
  • 1. barren land贫瘠的土地 2. a resurgence of religion再次掀起的宗教热潮 ...
    珺_7cbb阅读 2,593评论 0 0
  • 有一个去衣柜玩耍的兔子,它最喜欢吃裙子,夜里趁主人睡了去卫生间和小伙伴开派对,有天发现半开的冰箱里有只提拉米苏蛋糕...
    忆笙阅读 1,761评论 0 0