zoukankan      html  css  js  c++  java
  • 世界未解之谜之----------Android Gradle

    今天运行项目,运行的debug出来的包竟然是命名过的,但是我的buildTypes里面的debug 并没有执行重命名操作。很奇怪,我的猜测是: 执行buildTypes的时候,虽然是assermdebug,但是确实走了release里面的东西

    求大神指点:

    build.gradle:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
        useLibrary 'org.apache.http.legacy'
        defaultConfig {
            applicationId "com.aaa.ccc"
            minSdkVersion 14
            targetSdkVersion 23
            multiDexEnabled true
    
            buildConfigField("String", "ChannelId", '"116118"')         //渠道号
        }
        buildTypes {
            debug {
                buildConfigField "boolean", "LOG_DEBUG", "true"          //log 日志
                buildConfigField "String", "URL_CONFIG", ""huidu""  // url 配置:official,huidu,fangzhen
                minifyEnabled false
                zipAlignEnabled false
                debuggable true
                shrinkResources false
            }
            release {
                minifyEnabled true
                proguardFiles 'proguard-project.txt'
                debuggable false
                buildConfigField "boolean", "LOG_DEBUG", "false"
                buildConfigField "String", "URL_CONFIG", ""official""
    
                def versionN = getTodayReleaseVersion()
                applicationVariants.all { variant ->
                    variant.outputs.each { output ->
                        def outputFile = output.outputFile
                        if (outputFile != null && outputFile.name.endsWith('.apk')) {
                            def fileName = "baiduapp_v${getVersionName()}_${releaseDay()}_build${versionN}.apk"
                            output.outputFile = new File(outputFile.parent,fileName)
                        }
                    }
                }
            }
        }
        productFlavors {
        }
    
        lintOptions{
            abortOnError false
        }
        sourceSets{
            main {
                jniLibs.srcDirs = ['jniLibs']
            }
            debug.setRoot('build-types/debug')
            release.setRoot('build-types/release')
        }
    }
    
    dependencies {
        compile project(':plug')
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:support-v4:23.1.1'
    }
    def releaseDay(){
        return new Date().format("yyyyMMdd",TimeZone.getTimeZone("UTC"))
    }
    
    def getTodayReleaseVersion(){
        def runTasks = gradle.startParameter.taskNames;
        def versionPropsFile = file('buildver.properties')
        def today = releaseDay()
        if(versionPropsFile.canRead()){
            def versionId = 1
            def Properties versionProps = new Properties()
            versionProps.load(new FileInputStream(versionPropsFile))
            def releaseDay = versionProps.get("RELEASE_DAY")
            if(releaseDay.equals(today)) {
                versionId = versionProps.get('VERSION_NAME').toInteger()
                println("-------------"+runTasks);
                def isRelase = false
                runTasks.each { task ->
                    if(task.contains("assembleRelease")){
                        isRelase = true
                    }
                }
                if(isRelase){
                    versionId++
                }
            }else{
                versionProps["RELEASE_DAY"] = today;
            }
    
            versionProps['VERSION_NAME'] = versionId.toString()
            versionProps.store(versionPropsFile.newWriter(),null)
            return versionId.toString();
        }else{
            versionPropsFile.createNewFile();
            def Properties versionProps = new Properties();
            versionProps["RELEASE_DAY"] = releaseDay;
            versionProps['VERSION_NAME'] = versionId.toString()
            versionProps.store(new FileOutputStream(versionPropsFile),null)
        }
        return "1";
    }
    
    def getVersionName(){
        def fileManifest = file("src/main/AndroidManifest.xml")
        def androidManifest = new XmlSlurper().parse(fileManifest)
        return androidManifest.@'android:versionName'
    }
  • 相关阅读:
    where whereis locate find 的用法
    linux小知识
    linux touch和vi建立的文件是什么文件类型的
    linux创建文件的四种方式(其实是两种,强行4种)
    Linux mount实际使用
    linux文件系统和目录树的关系
    hard link && symbolic link
    Ext2文件系统的特点
    android pm命令
    linux安装源文件(.tar.gz)
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/6647729.html
Copyright © 2011-2022 走看看