博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
外包采用Gradle生成多套app打包
阅读量:2389 次
发布时间:2019-05-10

本文共 3177 字,大约阅读时间需要 10 分钟。

目的:可修改app名称、icon、包名、接口地址及其它

 

一、      修改基本配置(包名、版本号等)

配置module下的build.gradle

添加productFlavors例如:

productFlavors {

  fangwei{

    applicationId "com.f"

    versionCode 1

    versionName "0.1.04.21"

    //resValue "string", "app_name", "方维"

  }

  shunguoshi{

    applicationId "com.x"

    versionCode 1

    versionName "0.1.04.21"

    //生成res资源文件值,还可以通过添加文件夹的方式替换

    //resValue "string", "app_name", "顺"

    //生成BuildConfig值

    buildConfigField 'String','DOMAIN_WWW','"s.com"'

  }

}

 

二、      修改资源文件(接口地址、app名称、launcher等)

自定义BuildConfig(接口地址)

buildConfigField 'String','DOMAIN_WWW','"s.com"'

 

自定义资源(app名称、颜色等)

两种方式

1、resValue

//resValue "string", "app_name", "顺"

resValue ‘boolean’,’isDebug’,’true’

 2、为flavor建立对应资源文件

在app->src文件夹下面建立对应flavor如

“fangwei”->res->values->strings.xml

                 drawable-hdpi->ic_launcher.png

                 drawable-xhdpi->ic_launcher.png

                 drawable-xxhdpi->ic_launcher.png

                 drawable-mdpi->ic_launcher.png

 

配置应用签名

signingConfigs {

    config {

        keyAlias 'alias'

        keyPassword 'pwd2'

        storeFile file('key.keystore')

        storePassword 'pwd1'

    }

}

 

AndroidManifest占位符(用于多渠道打包、包名等)

Manifest文件中的内容

<meta-data android:value="${UMENG_CHANNEL_VALUE}" android:name="UMENG_CHANNEL"/>

 

build.gradle的内容

android {

    defaultConfig {

        manifestPlaceholders = [UMENG_CHANNEL_VALUE: 'dev']

    }

}

 

三、运行Gradle生成apk

1、chmod 777 gradlew

 

然后再执行进行编译

./gradlew  build

 

./gradlew tasks  //查看android gradle的所有任务

./gradlew assembleFangweiRelease   //生成apk,在build/outputs/apk文件夹下

 

 

附整份gradle配置

apply plugin: 'android'

 

dependencies {

    compile 'com.android.support:support-v4:19.0.0+'

    compile fileTree(dir: 'libs', include: '*.jar')

    compile project(':ZYLibrary')

    compile project(':library')

}

 

//def buildTime() {

//    def date = new Date()

//    def formattedDate = date.format('yyyyMMdd')

//    return formattedDate

//}

 

android {

//    buildTypes {

//        release {

//            applicationVariants.all { variant ->

//                variant.outputs.each { output ->

//                    if (output.outputFile != null && output.outputFile.name.endsWith('.apk')

//                            &&'release'.equals(variant.buildType.name)) {

//                        def apkFile = new File(

//                                output.outputFile.getParent(),

//                                "yizan_${variant.flavorName}_v${variant.versionName}_${buildTime()}.apk")

//                        output.outputFile = apkFile

//                    }

//                }

//            }

//        }

//    }

    signingConfigs {

        config {

            keyAlias 'o'

            keyPassword 'y

            storeFile file('o2o.keystore')

            storePassword 'y'

        }

    }

    compileSdkVersion 22

    buildToolsVersion "22.0.1"

    defaultConfig {

        applicationId "com.x"

        minSdkVersion 14

        targetSdkVersion 15

        versionCode 1

        versionName "0.1.04.21"

        // Enabling multidex support.

        multiDexEnabled true

//        resValue "string", "app_name", "方"

        signingConfig signingConfigs.config

        buildConfigField 'String','DOMAIN_WWW','"j.com"'

    }

    productFlavors {

        fangwei{

            applicationId "com.y"

            versionCode 1

            versionName "0.1.04.21"

//            resValue "string", "app_name", "维"

        }

        shunguoshi{

            applicationId "com.s"

            versionCode 1

            versionName "0.1.04.21"

//            resValue "string", "app_name", "顺"

            buildConfigField 'String','DOMAIN_WWW','"s.com"'

        }

 

    }

    sourceSets {

        main {

            manifest.srcFile 'AndroidManifest.xml'

            java.srcDirs = ['src']

            resources.srcDirs = ['src']

            aidl.srcDirs = ['src']

            renderscript.srcDirs = ['src']

            res.srcDirs = ['res']

            assets.srcDirs = ['assets']

            jniLibs.srcDirs = ['libs']

        }

 

        debug.setRoot('build-types/debug')

        release.setRoot('build-types/release')

    }

}

原文地址: 

转载地址:http://axaab.baihongyu.com/

你可能感兴趣的文章
C# 数据类型基础,堆栈,装箱与拆箱
查看>>
HTML 中的<div>
查看>>
Mysql Fabric实现学习笔记
查看>>
Spring JTA multiple resource transactions in Tomcat with Atomikos example
查看>>
How to setup multiple data sources with Spring and JPA
查看>>
MySQL 5.7 Fabric: any good?
查看>>
Accessing Fabric HA Groups from Java
查看>>
Q&A: Putting MySQL Fabric to use
查看>>
Fabric FAQ
查看>>
boost 1.39编译安装手记
查看>>
树莓派安装中文输入法
查看>>
树莓派(raspberry pi)播发flash 远程登录 视频播放
查看>>
Linux 安装与配置服务器版jre7
查看>>
Perform Two Phase Commits in MongoDB
查看>>
java.rmi.ConnectException: Connection refused to host: 127.0.0.1
查看>>
数据库服务器 Cloudscape
查看>>
JAVA中使用Schema校验XML
查看>>
使用Jakarta-ORO库的几个例子
查看>>
使用BlazeDS实现Java和Flex通信
查看>>
使用 Apache MINA 开发高性能网络应用程序
查看>>