TODO-MVP

作者: zhuanghongji | 来源:发表于2016-08-22 23:34 被阅读212次
Android-代码结构图

由上图可知,项目分层1个app目录,4个测试目录
app目录分为:

4个测试目录分别是:
androidTest: UI层测试
androidTestMock: UI层测试,mock数据支持
test:业务层单元测试
mock:业务层单元测试,mock数据支持

首先,我们来看下build.gradle(Module:app)文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.example.android.architecture.blueprints.todomvp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }

    buildTypes {
        debug {
            minifyEnabled true
            // Uses new built-in shrinker http://tools.android.com/tech-docs/new-build-system/built-in-shrinker
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }

        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }
    }

    // If you need to add more flavors, consider using flavor dimensions.
    productFlavors {
        mock {
            applicationIdSuffix = ".mock"
        }
        prod {

        }
    }

    // Remove mockRelease as it's not needed.
    android.variantFilter { variant ->
        if(variant.buildType.name.equals('release')
                && variant.getFlavors().get(0).name.equals('mock')) {
            variant.setIgnore(true);
        }
    }

    // Always show the result of every unit test, even if it passes.
    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
        }
    }
}

/*
 Dependency versions are defined in the top level build.gradle file. This helps keeping track of
 all versions in a single place. This improves readability and helps managing project complexity.
 */
dependencies {
    // App's dependencies, including test
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion"
    compile "com.google.guava:guava:$rootProject.guavaVersion"

    // Dependencies for local unit tests
    testCompile "junit:junit:$rootProject.ext.junitVersion"
    testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
    testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"

    // Android Testing Support Library's runner and rules
    androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
    androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"

    // Dependencies for Android unit tests
    androidTestCompile "junit:junit:$rootProject.ext.junitVersion"
    androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion"
    androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

    // Espresso UI Testing
    androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
    androidTestCompile ("com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion")
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.espressoVersion"

    // Resolve conflicts between main and test APK:
    androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
    androidTestCompile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    androidTestCompile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
}

在defaultConfig中

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

是用来

在buildTypes中,relase模式下启用了混淆,我们来分析下下面两行代码:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'

proguard-rules.pro 文件代码:

# Some methods are only called from tests, so make sure the shrinker keeps them.
-keep class com.example.android.architecture.blueprints.** { *; }

-keep class android.support.v4.widget.DrawerLayout { *; }
-keep class android.support.test.espresso.IdlingResource { *; }
-keep class com.google.common.base.Preconditions { *; }

# For Guava:
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe

# Proguard rules that are applied to your test apk/code.
-ignorewarnings

-keepattributes *Annotation*

-dontnote junit.framework.**
-dontnote junit.runner.**

-dontwarn android.test.**
-dontwarn android.support.test.**
-dontwarn org.junit.**
-dontwarn org.hamcrest.**
-dontwarn com.squareup.javawriter.JavaWriter
# Uncomment this if you use Mockito
-dontwarn org.mockito.**

proguard-rules.pro 文件代码:

# Proguard rules that are applied to your test apk/code.
-ignorewarnings

-keepattributes *Annotation*

-dontnote junit.framework.**
-dontnote junit.runner.**

-dontwarn android.test.**
-dontwarn android.support.test.**
-dontwarn org.junit.**
-dontwarn org.hamcrest.**
-dontwarn com.squareup.javawriter.JavaWriter
# Uncomment this if you use Mockito
-dontwarn org.mockito.**

在上面的build文件中,发现有比较多的
rootProject.ext.compileSdkVersion
rootProject.ext.buildToolsVersion
rootProject.supportLibraryVersion
rootProject.espressoVersion
是因为?
我们来看下build.gradle(Project:todoapp)文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

// Define versions in a single place
ext {
    // Sdk and tools
    minSdkVersion = 10
    targetSdkVersion = 22
    compileSdkVersion = 23
    buildToolsVersion = '23.0.2'

    // App dependencies
    supportLibraryVersion = '23.4.0'
    guavaVersion = '18.0'
    junitVersion = '4.12'
    mockitoVersion = '1.10.19'
    powerMockito = '1.6.2'
    hamcrestVersion = '1.3'
    runnerVersion = '0.4.1'
    rulesVersion = '0.4.1'
    espressoVersion = '2.2.1'
}

下面这段代码:

task clean(type: Delete) {    delete rootProject.buildDir}

前面铺垫了这么久,终于到代码时间了

代码结构

参考文章:
InfoQ:Android官方MVP架构示例项目解析

相关文章

  • Google官方android架构todo-mvp(译)

    todo-mvp架构项目地址 todo-mvp 这个app版本被称作todo-mvp,给这个工程的其他示例提供一个...

  • GOOGLE TODO-MVP 学习笔记

    GOOGLE TODO-MVP 学习笔记 背景(可忽略):《GOOGLE TODO-MVP 学习笔记》这篇文章主要...

  • GoogleSamples MVP 中文文档 README

    todo-mvp 这个版本的应用叫做todo-mvp , 并为项目中的其他实例提供依据。这个实例旨在: 在不使用任...

  • todo-mvp

    todo-mvp 当前版本的app叫做 todo-mvp,为该 github 项目中的其他示例提供了一个基础。样本...

  • TODO-MVP

    由上图可知,项目分层1个app目录,4个测试目录app目录分为: 4个测试目录分别是:androidTest: U...

  • 002.MVP

    Android Architecture Blueprints 学习之 TODO-MVP(一) - 推酷 谷歌官方...

  • androd-architecture(架构)

    项目地址 googlesamples/android-architecture todo-MVP 该版本的应用程...

  • MVP学习

    本文主要学习google开源代码TODO-MVP 地址 https://github.com/googlesamp...

  • android-architecture之todo-mvp源码分

    博文出处:android-architecture之todo-mvp源码分析,欢迎大家关注我的博客,谢谢! And...

  • Google官方MVP示例之TODO-MVP

    Google官方MVP示例之TODO-MVP 欢迎转载,转载请注明源地址:http://blog.csdn.net...

网友评论

      本文标题:TODO-MVP

      本文链接:https://www.haomeiwen.com/subject/jmygsttx.html