android中不同的风格

时间:2015-10-26 14:32:34

标签: android gradle build

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

enter image description here

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

来自app模块的

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}"
}

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

当我更改构建Variant时,java内容会发生变化。 (例如,它是internalDebug变体的main,internal,internalDebug,然后它变为main,internal,internalRelease for internalRelease build variants)。

我问的原因是我没有看到任何" internalRelease" gradle文件中的单词,所以我不理解构建变体是如何创建的逻辑以及它如何定义为不同构建变体显示的模块

1 个答案:

答案 0 :(得分:1)

调试没有签名的测试和发布带签名的发布;单击左上角的机器人,然后将android转为项目,你就会理解;