简体   繁体   English

在 android 上重构为动态功能模块时,构建失败并显示“task:features:catalog:createDebugCompatibleScreenManifests FAILED”

[英]Build fails with 'task :features:catalog:createDebugCompatibleScreenManifests FAILED' while refactoring to dynamic feature modules on android

Once I introduced dynamic feature modules into my app, I was able to successfully refactor feature one (orders), build and deploy.一旦我将动态功能模块引入我的应用程序,我就能够成功地重构功能一(订单)、构建和部署。 But on refactoring the second module, ie moving files and resources to that module, I get this error on build:但是在重构第二个模块时,即将文件和资源移动到该模块时,我在构建时收到此错误:


Execution failed for task ':features:catalog:createDebugCompatibleScreenManifests'.
> Failed to calculate the value of task ':features:catalog:createDebugCompatibleScreenManifests' property 'applicationId'.
   > Failed to query the value of property 'testedApplicationId'.
      > Collection has more than one element.

I have tried the following fixes:我尝试了以下修复:

  1. invalidate cache使缓存无效
  2. reclone project重新克隆项目
  3. ensure all gradle files are identical (except for applicationId bit)确保所有 gradle 文件相同( applicationId位除外)
  4. checked that there are no errors in the manifest files检查清单文件中没有错误
  5. confirmed that no two modules share the same application ID.确认没有两个模块共享相同的应用程序 ID。
  6. rebase the project to the last working commit.将项目重新设置为最后一个工作提交。

Any pointers as to what is causing this build issue?关于导致此构建问题的任何指示?

Other info: I'm using dependency injection with koin.其他信息:我正在使用 koin 的依赖注入。

App/Main module manifest.xml应用程序/主模块manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.app">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature
        android:name="android.hardware.camera2"
        android:required="false" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:name=".ExampleApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:networkSecurityConfig="@xml/network_security_config"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="${crashlyticsCollectionEnabled}" />

        <activity android:name="com.kyosk.app.ui.fragment.login.LoginActivity" />

        <activity android:name="com.kyosk.app.ui.activity.SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.kyosk.app.ui.activity.Home" />

        <service
            android:name=".service.MessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name=".location.services.LocationUpdatesService"
            android:exported="false" />
        <service
            android:name=".location.services.MapsLocationUpdatesService"
            android:exported="false" />

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
    </application>

</manifest>

App/Main module build.gradle应用/主模块build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

apply plugin: "androidx.navigation.safeargs.kotlin"

apply plugin: 'realm-android'

apply plugin: 'com.google.gms.google-services'

apply plugin: 'com.google.firebase.crashlytics'

apply plugin: (BuildPlugins.dependencyUpdateChecker)

android {

    compileSdkVersion AndroidSDK.compileSDKVersion
    buildToolsVersion Versions.buildTools

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion AndroidSDK.minimumSDKVersion
        targetSdkVersion AndroidSDK.targetSDKVersion
        versionCode Versions.versionCode
        versionName Versions.versionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
            manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
            applicationIdSuffix(".debug")
            versionNameSuffix("-debug")
            buildConfigField("String", "BASE_URL", debug_url)
        }

        staging {
            initWith(release)
            manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
            applicationIdSuffix(".staging")
            versionNameSuffix("-staging")
            buildConfigField("String", "BASE_URL", staging_url)
        }

        release {
            manifestPlaceholders = [crashlyticsCollectionEnabled: "true"]
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField("String", "BASE_URL", production_url)
        }
    }

    buildFeatures {
        viewBinding = true
        dataBinding = true
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    kapt {
        correctErrorTypes = true
    }

    dynamicFeatures = [':features:kiosks', ':features:catalog', ':features:checkout', ':features:summary', ':features:orders']
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation Libraries.kotlinStandardLibrary
    implementation Libraries.appCompat
    implementation Libraries.constraintLayout
    api Libraries.materialComponents
    implementation Libraries.navigationFragment
    implementation Libraries.navigationUI

    implementation Libraries.preferences

    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

    //firebase libs
    implementation Libraries.firebaseMessaging
    implementation Libraries.firebaseConfig
    // Recommended: Add the Firebase SDK for Google Analytics.
    implementation Libraries.firebaseAnalytics
    implementation Libraries.firebaseCrashlytics

    // DI
    api Libraries.koinAndroid
    api Libraries.koinLifecycle
    api Libraries.koinViewmodel

    //maps
    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    //own modules
    implementation project(path: ':location-services')
    implementation project(path: ':network')
    api project(path: ':helpers')

    //glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'

    kapt 'com.github.bumptech.glide:compiler:4.11.0'

    //loading button
    api Libraries.buttonProgress

    //pagination lib
    implementation Libraries.jdroidCoder

    //EventBus
    api Libraries.eventBus

    //logging
    api Libraries.timber

    //anko
    api Libraries.ankoDesign
    api Libraries.ankoCommons

    //play core library
    implementation(Libraries.playCore)
    implementation(Libraries.playCorektx)

    // paris for applying styles to views dynamically
    implementation 'com.airbnb.android:paris:1.7.2'

    // lottie for animations
    implementation 'com.airbnb.android:lottie:3.5.0'

    // Okhttp Profiler
    implementation Libraries.loggingInterceptor

    // Test libs
    testImplementation(TestLibraries.junit4)
    androidTestImplementation(TestLibraries.androidX)
    androidTestImplementation(TestLibraries.espresso)
    androidTestImplementation(TestLibraries.annotationLib)
}

Feature Module 1(orders) manifest.xml Feature Module 1(orders) manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    package="com.example.app.orders">

    <dist:module
        dist:instant="false"
        dist:title="@string/title_orders">
        <dist:delivery>
            <dist:install-time />
        </dist:delivery>
        <dist:fusing dist:include="true" />
    </dist:module>
</manifest>

Feature 1 (orders) build.gradle功能1(订购) build.gradle

apply plugin: 'com.android.dynamic-feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: (BuildPlugins.dependencyUpdateChecker)


android {
    compileSdkVersion AndroidSDK.compileSDKVersion
    buildToolsVersion Versions.buildTools

    defaultConfig {
        applicationId "com.example.app.orders"
        minSdkVersion AndroidSDK.minimumSDKVersion
        targetSdkVersion AndroidSDK.targetSDKVersion
        versionCode Versions.versionCode
        versionName Versions.versionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {}
        staging {}
        release {}
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    buildFeatures {
        viewBinding = true
        dataBinding = true
    }
}

dependencies {
    implementation project(":app")
    implementation project(path: ':network')
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation Libraries.kotlinStandardLibrary
    implementation Libraries.ktxCore
    implementation Libraries.appCompat
    implementation Libraries.constraintLayout
    implementation Libraries.materialComponents
    implementation Libraries.navigationFragment
    implementation Libraries.navigationUI

    implementation Libraries.buttonProgress
    implementation Libraries.ankoDesign
    implementation Libraries.ankoCommons

    implementation(Libraries.coroutinesAndroid)

    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

    // Test libs
    testImplementation(TestLibraries.junit4)
    androidTestImplementation(TestLibraries.androidX)
    androidTestImplementation(TestLibraries.espresso)
    androidTestImplementation(TestLibraries.annotationLib)
}

The issue ended up being a library I had imported.问题最终成为我导入的库。

The library had plugin apply plugin: 'com.android.application' instead of apply plugin: 'com.android.library'该库有插件apply plugin: 'com.android.application'而不是apply plugin: 'com.android.library'

As such, gradle build task was looking for applicationId and applicationName in the manifest, which was not there.因此,gradle 构建任务正在清单中寻找applicationIdapplicationName ,但它们并不存在。

Oops, developer error.糟糕,开发人员错误。

Uninstall the application from emulator and then restart it从模拟器中卸载应用程序,然后重新启动它

For me it happened when adding a new dynamic feature module with multiple flavors.对我来说,这是在添加具有多种风格的新动态功能模块时发生的。

I solved it by changing inside module.gradle :我通过更改内部module.gradle解决了它:

implementation project(path: ':app', configuration: 'default')

into进入

implementation project(":app")

Then add flavors into module.gradle然后将风味添加到模块中。gradle

flavorDimensions "app"

productFlavors {
    flavor1 {}
    flavor2 {}
    flavor3 {}
}

Here is my final module.gradle这是我的最终模块。gradle

apply plugin: 'com.android.dynamic-feature'

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.3'

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    flavorDimensions "app"

    productFlavors {
        flavor1 {}
        flavor2 {}
        flavor3 {}
    }

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

dependencies {
    implementation project(":app")
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 动态特性模块依赖 - Android dynamic feature modules dependencies Android Studio:Gradle-构建失败-任务&#39;:dexDebug&#39;的执行失败 - Android Studio: Gradle - build fails — Execution failed for task ':dexDebug' Android 构建失败并出现错误:任务 ':app:checkReleaseDuplicateClasses' 执行失败 - Android build fails with error: Execution failed for task ':app:checkReleaseDuplicateClasses' 构建失败的android,已弃用的功能 - Build failed android, deprecated features Android Studio 构建失败“任务 &#39;:app:kaptDebugKotlin&#39; 执行失败。” - Android Studio Build Fails “Execution failed for task ':app:kaptDebugKotlin'.” Android Studio:Gradle构建失败 - 任务'执行失败':compileDebugAidl' - Android Studio: Gradle build fails — Execution failed for task ':compileDebugAidl' 是否可以使用动态功能模块和 Koin 构建项目? - Is it possible to build a project with Dynamic feature modules and Koin? 动态功能模块中的 androidTest espresso 测试用例无法构建/运行 - 任务“:dfm:mergeLibDexDebugAndroidTest”执行失败 - androidTest espresso test cases in a Dynamic Feature Module failing to build/run - Execution failed for task ':dfm:mergeLibDexDebugAndroidTest' Android bundle build error with Dynamic Features:所有带有本机库的模块必须支持同一组ABI - Android bundle build error with Dynamic Features: All modules with native libraries must support the same set of ABI Android kernel 模块构建失败 - Android kernel modules build failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM