android - android中的不同口味

标签 android gradle build

我想在我的项目中创建这样的东西,但我是 gradle 新手,所以我不知道它可以做的很多事情。

enter image description here

这是资源管理器中的项目结构
enter image description here

来自应用模块的 gradle.build

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
    }
}

// Manifest version information!
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}

def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def date = new Date()
def buildTime = date.format("dd.MM.yy", TimeZone.getTimeZone("UTC"))
def buildTimeInternal = date.format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion

        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"

        buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
        buildConfigField "String", "BUILD_TIME", "\"${buildTimeInternal}\""

        testApplicationId "ru.ltst.u2020mvp.tests"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            storeFile file("../distribution/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
        release {
            storeFile file("../distribution/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix '.dev'
            versionNameSuffix '-dev'
            debuggable true
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard-project.txt')
            signingConfig signingConfigs.release
        }
    }

    productFlavors {
        internal {
            applicationId 'ru.ltst.u2020mvp.internal'
        }
        production {
            applicationId 'ru.ltst.u2020mvp'
        }
    }


    lintOptions {
        textReport true
        textOutput 'stdout'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

// TODO remove eventually: http://b.android.com/162285
configurations {
    internalDebugCompile
}

dependencies {
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:support-annotations:23.0.1'
    compile "com.android.support:appcompat-v7:23.0.1"
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'

    compile 'com.google.dagger:dagger:2.0.1'
    apt 'com.google.dagger:dagger-compiler:2.0'
    provided 'org.glassfish:javax.annotation:10.0-b28'

    compile 'com.squareup.okhttp:okhttp:2.3.0'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    internalDebugCompile 'com.squareup.retrofit:retrofit-mock:1.9.0'

    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.jakewharton.timber:timber:2.7.1'
    internalDebugCompile 'com.jakewharton.madge:madge:1.1.1'
    internalDebugCompile 'com.jakewharton.scalpel:scalpel:1.1.1'

    compile 'io.reactivex:rxjava:1.0.8'
    compile 'io.reactivex:rxandroid:0.24.0'

    internalCompile 'com.mattprecious.telescope:telescope:1.4.0@aar'

    // Espresso 2 Dependencies
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
        exclude module: 'support-annotations'
    }
}

// change apk name
android.applicationVariants.all { variant ->
    for (output in variant.outputs) {
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk')) {
            def fileName = "u2020-mvp-${output.name}-${buildTime}.apk"
            output.outputFile = new File(outputFile.parent, fileName)
        }
    }
}

// print build finish time
gradle.buildFinished { buildResult ->
    def buildFinishDate = new Date()
    def formattedDate = buildFinishDate.format('yyyy-MM-dd HH:mm:ss')
    println "Build finished: ${formattedDate}"
}

有人可以向我解释它是如何工作的吗?

当我更改构建变体时,Java 内容会更改。 (例如,对于 internalDebug 变体,它是 main、internal、internalDebug,然后对于 internalRelease 构建变体,它变成了 main、internal、internalRelease)。

我问的原因是我在 gradle 文件中看不到任何“internalRelease”字样,所以我不明白构建变体是如何创建的逻辑以及它如何定义为不同构建变体显示哪些模块

最佳答案

调试无签名测试,发布有签名发布;点击左上角机器人,将android转为project,你就明白了;

关于android - android中的不同口味,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348334/

相关文章:

android - qt qml : deploying sqlite database to android using . qrc 文件不工作

android - 授予 ACCESS_MOCK_LOCATION 权限以在 Marshmallow 中使用 adb 进行测试失败

java - 成功使用Android通过HDMI控制外接显示器

java - Gradle-从Jar文件中忽略特定的jar

c# - 构建软件补丁的好习惯是什么?

linux - GNU make - 只依赖于文件存在而不是修改时间

java - wrap_content 不会调整字体大小吗?

java - 从 `build.gradle`获取值到代码

gradle - Gradle无法使用声明为pom.xml的多个版本解决依赖关系

visual-studio-2010 - 没有为Visual Studio “SQLBuildTask”任务提供必需参数 “DatabaseName”错误的值