androidstudioで発生した、クラスが2つのモジュールに重複しているというエラーを直したい
前提
androidが提供しているコードラボのナビゲーションコンポーネントの範囲を勉強していたら上記に書いたようなエラーが出ました。(エラーコードは下記)
実際に行ったことは、メインアクティビティに2つのフラグメントを設定するといったことです。その際にgradleファイルに少し書き足しましたが、チュートリアルの指示通りです。
実は、このチュートリアルを行うのは2回目で、1回目も同じところでエラーになり、解決できなかったためやり直しました。ですが、また同じところでエラーになりました。
エラーコードにはモジュール名が出ていますが、このモジュールがどこに入っているかわかりません。そのため、何のファイルを提示したらよいかわかりません。とりあえず、一番可能性のありそうなgradleファイルを張っておきます
発生している問題・エラーメッセージ
Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified-lifecycle-viewmodel-ktx-2.2.0-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0) and lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1) Go to the documentation to learn how to Fix dependency resolution errors.
該当のソースコード
kotlin
1/* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16plugins { 17 id 'com.android.application' 18 id 'kotlin-android' 19 id 'kotlin-kapt' 20 id 'androidx.navigation.safeargs.kotlin' 21} 22 23android { 24 compileSdkVersion 33 25 26 defaultConfig { 27 applicationId "com.example.wordsapp" 28 minSdkVersion 19 29 targetSdkVersion 33 30 versionCode 1 31 versionName "1.0" 32 33 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 34 } 35 36 buildTypes { 37 release { 38 minifyEnabled false 39 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 40 } 41 } 42 compileOptions { 43 sourceCompatibility JavaVersion.VERSION_1_8 44 targetCompatibility JavaVersion.VERSION_1_8 45 } 46 47 kotlinOptions { 48 jvmTarget = '1.8' 49 } 50 51 buildFeatures { 52 viewBinding = true 53 } 54} 55 56dependencies { 57 implementation "androidx.core:core-ktx:$core_ktx_version" 58 implementation "androidx.appcompat:appcompat:$appcompat_version" 59 implementation "com.google.android.material:material:$material_version" 60 implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version" 61 implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" 62 implementation "androidx.navigation:navigation-ui-ktx:$nav_version" 63 64}
試したこと
チュートリアルの完成形のコードを実行するとしっかり動きます。ですが、自分で作ってみるとエラーになってしまいます。チュートリアルをそのまままねしているだけだと思うのですが。
また、gradleにdependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
}
を記述しましたが、下のエラーになります
”Duplicate class androidx.lifecycle.ViewModelLazy found in modules jetified-lifecycle-viewmodel-ktx-2.2.0-runtime (androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0) and lifecycle-viewmodel-2.5.1-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.1)
Go to the documentation to learn how to Fix dependency resolution errors.”
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
