首页 > 解决方案 > 安装导航组件后Android构建失败

问题描述

我正在尝试使用导航组件构建 android 项目。我的 android 项目是由 java 和 kotlin 编写的,带有一些第三方库(一些库很旧)。

当我将以下代码添加到我的应用程序的 build.gradle 文件中以便按照 gogole 站点描述的方式安装导航组件时([导航组件][1])

dependencies {
  def nav_version = "2.3.3"

  // Java language implementation
  implementation "androidx.navigation:navigation-fragment:$nav_version"
  implementation "androidx.navigation:navigation-ui:$nav_version"

  // Kotlin
  implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
  implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

  // Feature module Support
  implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"

  // Testing Navigation
  androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"

  // Jetpack Compose Integration
  implementation "androidx.navigation:navigation-compose:1.0.0-alpha05"
}

之后我的项目构建失败并出现以下错误。

Execution failed for task ':<<ProjectName>>:transformClassesWithByteCodeTransformForDebug'.
> java.util.concurrent.ExecutionException: java.lang.RuntimeException: cannot find META-INF.versions.9.module-info: module-info found in META-INF/versions/9/module-info.class

该模块是 java9 功能,并且 module-info.class 似乎是 java9 所必需的,即使我用 java8 编译我的 android 项目。

正如一些后面的文章解释的那样,我还添加了以下声明,但这没有帮助。

packagingOptions {
        exclude "**/module-info.class"
    }

所有依赖项:

dependencies {
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    compile fileTree(include: ['*.jar'], dir: 'libs')

    // Support library
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.1'

    // viewmodel
    implementation "androidx.lifecycle:lifecycle-reactivestreams:2.1.0"
    implementation "androidx.lifecycle:lifecycle-extensions:2.1.0"
    implementation "androidx.lifecycle:lifecycle-runtime:2.1.0"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.1.0"
    androidTestImplementation "androidx.arch.core:core-testing:2.1.0"

    // room
    implementation "androidx.room:room-runtime:2.2.3"
    kapt "androidx.room:room-compiler:2.2.3"
    implementation "androidx.room:room-rxjava2:2.2.3"
    testImplementation "androidx.room:room-testing:2.2.3"
    androidTestImplementation "androidx.room:room-testing:2.2.3"

    // GMS
    implementation "com.google.android.gms:play-services-maps:15.0.2"
    implementation "com.google.android.gms:play-services-location:15.0.2"
    implementation "com.google.android.gms:play-services-tagmanager:16.0.8"
    // for Places SDK for Android
    implementation "com.google.android.libraries.places:places-compat:1.1.0"

    implementation 'com.google.maps.android:maps-ktx:1.5.0'
    implementation 'com.google.maps.android:maps-utils-ktx:1.5.0'

    // Google
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:14.0.1'

    // Directions API
    implementation "com.google.maps:google-maps-services:0.2.11"

    // GreenDao
    compile 'de.greenrobot:greendao:1.3.7'

    // Util
    compile 'com.deploygate:sdk:3.1'

    // Firebase
    implementation "com.google.firebase:firebase-core:16.0.9"
    implementation "com.google.firebase:firebase-messaging:18.0.0"
    implementation "com.google.firebase:firebase-dynamic-links:17.0.0"
    implementation "com.google.firebase:firebase-config:17.0.0"
    implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
    implementation 'com.google.firebase:firebase-analytics:17.6.0'

    // AppsFlyer
    implementation 'com.appsflyer:af-android-sdk:4.10.3@aar'
    implementation 'com.android.installreferrer:installreferrer:1.0'

    // Retrofit2
    compile "com.squareup.retrofit2:retrofit:2.3.0"
    compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
    compile "com.squareup.retrofit2:converter-moshi:2.3.0"
    implementation("com.squareup.retrofit2:converter-simplexml:2.3.0") {
        exclude group: 'xpp3', module: 'xpp3'
        exclude group: 'stax', module: 'stax-api'
        exclude group: 'stax', module: 'stax'
    }
    compile "com.squareup.retrofit2:retrofit-mock:2.3.0"
    compile "com.squareup.okhttp3:okhttp:3.8.0"
    testCompile "com.squareup.okhttp3:mockwebserver:3.8.0"
    compile "com.squareup.okhttp3:logging-interceptor:3.8.0"
    compile "com.squareup.moshi:moshi:1.5.0"
    compile "com.squareup.moshi:moshi-kotlin:1.5.0"
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxkotlin:2.2.0'

    // dagger
    implementation "com.google.dagger:dagger:2.25.4"
    implementation "com.google.dagger:dagger-android:2.25.4"
    implementation "com.google.dagger:dagger-android-support:2.25.4"
    kapt "com.google.dagger:dagger-compiler:2.25.4"
    kapt "com.google.dagger:dagger-android-processor:2.25.4"
    kaptTest "com.google.dagger:dagger-compiler:2.25.4"
    kaptAndroidTest "com.google.dagger:dagger-compiler:2.25.4"
    kaptAndroidTestDebug "com.google.dagger:dagger-compiler:2.25.4"

    implementation('com.github.bumptech.glide:glide:4.7.1') {
        exclude group: 'com.android.support'
    }
    implementation('jp.wasabeef:glide-transformations:3.3.0'){
        exclude group: 'com.android.support'
    }
    kapt 'com.github.bumptech.glide:compiler:4.5.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
    implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"

    // Kotlin Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-rx2:1.3.3'

    implementation 'com.jakewharton.timber:timber:4.6.0'

    // RxRelay
    implementation 'com.jakewharton.rxrelay3:rxrelay:3.0.0'

    // for Test
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test:rules:1.2.0'

    testCompile 'org.powermock:powermock-api-mockito2:1.7.3'
    testCompile 'org.powermock:powermock-module-junit4:1.7.3'
    testCompile 'org.mockito:mockito-core:2.19.0'
    androidTestCompile 'org.mockito:mockito-android:2.19.0'

    compile 'com.ethanhua:skeleton:1.0.0'

    //flexbox
    implementation 'com.google.android:flexbox:1.0.0'
    
    // runtime permission
    implementation "com.github.hotchemi:permissionsdispatcher:3.3.1"
    kapt "com.github.hotchemi:permissionsdispatcher-processor:3.3.1"

    // JTS
    implementation 'org.locationtech.jts:jts-core:1.17.1'

    // デバッグ用
    debugImplementation 'com.facebook.stetho:stetho:1.5.1'

    def nav_version = "2.3.3"

    // Java language implementation
    implementation "androidx.navigation:navigation-fragment:$nav_version"
    implementation "androidx.navigation:navigation-ui:$nav_version"

    // Kotlin
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

    // Feature module Support
    implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"

    // Testing Navigation
    androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"

    // Jetpack Compose Integration
    implementation "androidx.navigation:navigation-compose:1.0.0-alpha05"
}

你能告诉我如何解决这个问题。

谢谢 [1]:https ://developer.android.com/guide/navigation/navigation-getting-started?hl=ja

标签: androidgradlenavigationbuild.gradleandroidx

解决方案


推荐阅读