首页 > 解决方案 > 如何使用模块和动态功能运行 UI 测试

问题描述

我目前正在玩动态功能。我无法运行任何 UI 测试。

我的应用程序有三个模块,如图所示:

在此处输入图像描述

在下面,您将找到每个模块的build.gradle文件。

应用程序

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
}

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.test.test"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 7
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            debuggable = false
        }
    }

    flavorDimensions "environment"
    productFlavors {
        dev {
            dimension "environment"
            applicationIdSuffix ".dev"
        }
        prod {
            dimension "environment"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    dynamicFeatures = [':dynamicFeatureA']
}

dependencies {
    implementation project(':shared')

    // Firebase
    implementation platform('com.google.firebase:firebase-bom:25.12.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-auth-ktx'

    api 'com.google.android.play:core:1.9.0'
} 

共享

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.3"

    defaultConfig {
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 7
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    // Retrofit + OkHttp
    api 'com.squareup.retrofit2:retrofit:2.6.2'
    api 'com.squareup.retrofit2:converter-gson:2.1.0'
    api 'com.squareup.okhttp3:logging-interceptor:4.2.1'

    // Tests
    api("junit:junit:4.13.1")
    api 'androidx.test.ext:junit:1.1.2'
    api 'androidx.test.espresso:espresso-core:3.3.0'
    api "androidx.arch.core:core-testing:2.1.0"
    api "io.mockk:mockk:1.10.4"
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
    api "io.mockk:mockk-android:1.10.4"
    api 'com.squareup.okhttp3:mockwebserver:4.2.2'
    api 'androidx.test.uiautomator:uiautomator:2.2.0'
    api 'androidx.test.ext:junit:1.1.2'
    api 'androidx.test:runner:1.3.0'
    api 'androidx.test:rules:1.3.0'
    api 'androidx.test:core:1.3.0'
    api 'androidx.test.ext:truth:1.3.0'

    // Kotlin
    api "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
    api 'androidx.core:core-ktx:1.3.2'
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
    api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'

    api 'androidx.appcompat:appcompat:1.2.0'
    api 'com.google.android.material:material:1.2.1'

    api "androidx.constraintlayout:constraintlayout:2.0.4"
}

动态特征A

plugins {
    id 'com.android.dynamic-feature'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}
android {
    compileSdkVersion 29
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.test.test"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 7
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "environment"
    productFlavors {
        dev {
            dimension "environment"
            applicationIdSuffix ".dev"
        }
        prod {
            dimension "environment"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation project(":app")
    implementation project(":shared")
}

尝试运行我的 UI 测试时,出现以下错误

Android resource linking failed
/.gradle/caches/transforms-2/files-2.1/d3cf80163c3f5e54a1f3dc792b3bfaac/jetified-core-1.9.0/AndroidManifest.xml:13:5-226: AAPT: error: resource style/Theme.PlayCore.Transparent (aka com.test.test.dev.test:style/Theme.PlayCore.Transparent) not found.
    
/.gradle/caches/transforms-2/files-2.1/2bbe030940076efec6cce94c1a3439fe/jetified-play-services-basement-17.0.0/AndroidManifest.xml:23:9-25:69: AAPT: error: resource integer/google_play_services_version (aka com.test.test.dev.test:integer/google_play_services_version) not found.

标签: androidtestinggradledynamic-feature-module

解决方案


推荐阅读