問題描述
我對 Android 開發完全陌生,似乎無法解決此錯誤:錯誤:程序類型已存在:android.support.v4.media.MediaBrowserCompat$CustomActionCallback"
I completely new to Android Development and can't seem to resolve this error: "Error: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback"
這是我的依賴:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
implementation "android.arch.navigation:navigation-fragment:1.0.0-alpha01"
implementation "android.arch.navigation:navigation-ui:1.0.0-alpha01"
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
testImplementation 'junit:junit:4.12'
}
我在 Google 上搜索了一些內容,最后在開發者頁面上找到了有關解決重復的類錯誤"的信息,但我仍然無法解決這個問題.非常感謝您的幫助!
I've googled some and ended up on the developer page about "Resolve duplicate class errors", but I'm still not able to fix this. Help would be very much appriciated!
推薦答案
選項1
以下對我有用在 gradle.properties 文件中添加以下內容
Following worked for me Add the following in your gradle.properties file
android.useAndroidX = true
android.enableJetifier = false
選項 2(如果上述方法不起作用)
Option 2 (if above does't work)
Android 工作室
->導航
->類
- 檢查是否包含非項目類
- 復制完整的類路徑 android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
- 查看它的用途.您可能需要刪除其中之一.
選項 3您可能會包含包含模塊的包,因此請使用以下方法排除 support-v4 模塊
Option 3 you might be including package which is including modules as well so exclude the support-v4 module with following method
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
exclude group: 'com.android.support', module:'support-v4'
}
您可以從項目存儲庫中的命令行使用 ./gradlew :YOURPROJECT:dependencies
分析沖突模塊.特別檢查您的第三方庫是否出現com.android.support-":
You can analyze the conflicting modules using ./gradlew :YOURPROJECT:dependencies
from a command line in your project repository.
Check especially your third party libraries for occurences of "com.android.support-":
然后從這些依賴項中排除沖突的模塊,例如:
Then exclude the conflicting modules from these dependencies like:
implementation ("com.jakewharton:butterknife:8.8.1") {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotation'
exclude group: 'com.android.support', module: 'support-compat'
}
這篇關于程序類型已存在:android.support.v4.media.MediaBrowserCompat$CustomActionCallback的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!