簡體   English   中英

谷歌材料設計庫錯誤程序類型已經存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy

[英]Google material design library error Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy

每當我嘗試構建項目時添加implemntation 'com.google.android.material:material:1.0.0-alpha1'時,Android Studio 都會說:

程序類型已經存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy Message{kind=ERROR, text=程序類型已經存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[Unknown source文件],工具名稱=Optional.of(D8)}

這是我的gradle腳本:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "it.smart.bab3"
        minSdkVersion 21
        targetSdkVersion 'p'
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
}

我是新來的這種類型的錯誤,我沒有發現這個錯誤。 謝謝

我也一直在為這個問題苦苦掙扎一整天。 最后我成功地編譯並運行了該項目。

首先,擺脫這個:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'

在 gradle.properties 文件中添加以下內容:

android.useAndroidX = true
android.enableJetifier = false

最后,同步項目然后編譯。

如果它不起作用,請清理項目,然后重建。

PS:我無法讓 targetSdkVersion 'p' 工作。 我的 build.gradle 文件最終如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "com.github.alvarosct02.demo"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

希望它也適用於你。

我浪費了 2 天尋找解決方案。 任何仍在尋找解決方案的人都可以按照以下步驟操作:

  1. 將您的 Android Studio 更新到最新版本。

  2. 將 compileSdkVersion 和 targetSdkVersion 更新為 28。

     android { compileSdkVersion 28 defaultConfig { applicationId "com.your.appid" minSdkVersion 19 targetSdkVersion 28 versionCode 50 versionName "1.50" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true setProperty("archivesBaseName", "your-app-$versionName") resConfigs "en" } }
  3. 轉到您的項目結構並將您的 gradle 版本更改為4.10

  4. 首先添加此依賴項:

     implementation 'com.google.android.material:material:1.0.0'
  5. 現在刪除所有支持庫依賴項:

     implementation "com.android.support:design:$SUPPORT_LIBRARY_VERSION" implementation "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION" implementation "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION" implementation "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION" implementation "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION" implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:multidex:1.0.3' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" androidTestImplementation('com.android.support.test.espresso:espresso- core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.google.code.findbugs', module: 'jsr305' })
  6. 現在將以下內容粘貼到您的gradle.properties文件中:

     android.useAndroidX = true android.enableJetifier = true
  7. 在您的項目級build.gradle文件中:

     dependencies { classpath 'com.android.tools.build:gradle:3.2.0' classpath 'com.google.gms:google-services:4.1.0' };

對於那些使用Butterknife 的人,在你的項目級 build.gradle 文件中添加以下行:

allprojects {
    repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url "https://dl.bintray.com/drummer-aidan/maven/" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  }
}

並在您的模塊build.gradle文件中添加以下依賴項:

 implementation "com.jakewharton:butterknife:9.0.0-SNAPSHOT"
 annotationProcessor "com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT"
  1. 現在轉到Build > Rebuild Project那么你可能會遇到很多錯誤。
  1. 現在參考這個鏈接。

    它包含所有(android.support) 和(androidx.*) 依賴項的列表。

    的替換所有舊的導入
    (使用 android studio [ctrl + shift + R] 的 replaceAll 功能可以節省一些時間)。
  1. 最后在用新庫重構所有舊庫之后:
    再次重建項目,希望它可以工作。

注意:您也可以在 android studio 中使用Refactor > Migrate to androidx但它對我不起作用。

將 ButterKnife 升級到 8.8.1 版后,我開始收到此錯誤。

所以,我運行命令gradle -q dependencies來生成一個依賴報告,之后你應該看到 D8 來自哪里。 在我的例子中來自“ButterKnife”庫:

+--- com.jakewharton:butterknife:8.8.1
|    |    \--- com.android.support:support-compat:d8

您還可以通過轉到 Android Studio Gradle 視圖(在 Android Studio 工具欄中導航到“View/Tool Windows/Gradle”),然后在“My-Project-Name/Tasks/”下選擇目標“androidDependencies”來查看您的 android 依賴項android”(雙擊運行或右鍵單擊運行)。

為了解決這個問題,我在我的“app/build.gradle”中添加了這段代碼exclude module: 'support-compat' ,如下所示:

implementation ('com.jakewharton:butterknife:8.8.1') { 
     exclude module: 'support-compat' 
} 
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

希望它適用於其他人:] 干杯!

Android Studio v3.2+ 解決了這個問題。 它還在 Refactor 菜單下添加了“Migrate to AndroidX”項。 無需解決方法或回滾。

從 beta 通道更新 Android Studio 以使用 3.2+ 或等待穩定版本發布。

編輯:Android Studio v3.2 現在處於穩定通道。 重要的是您不再使用支持庫並遷移到 AndroidX 庫,因為對舊支持庫的支持已經結束。

如果您包含的庫對 Android 支持庫具有傳遞依賴關系,您還必須使用jetifier功能,該功能是 Android Gradle 插件版本 3.2.0-alpha14 或更高版本的一部分。 您可以通過運行 Gradle dependencies任務來確定您是否有依賴於支持庫的庫。

來自 Android 開發者的博文( https://android-developers.googleblog.com/2018/05/hello-world-androidx.html ):

如果您依賴引用舊支持庫的庫,Android Studio 將更新該庫以通過依賴關系轉換來引用 androidx。 Android Gradle Plugin 3.2.0-alpha14 會自動應用依賴關系轉換,它會重寫 JAR 和 AAR 依賴項(以及傳遞依賴項)的字節碼和資源以引用新的 androidx 打包類和工件。 我們還將提供一個獨立的翻譯工具作為 JAR。

在你的gradle.properties文件中,確保你有:

android.enableJetifier=true android.useAndroidX=true

我在一個小項目中遇到了 Leak Canary 的這個問題,它通過將 Android Gradle 插件升級到適當的版本來解決。 https://github.com/square/leakcanary/issues/1103

轉到 app/build.gradle,在依賴項中,刪除這一行:

implementation "com.android.support:appcompat-v7

嘗試添加

android.enableD8 = false

到 gradle.properties 文件。

用這個

   apply plugin: 'com.android.application'
   apply plugin: 'kotlin-android'

   android {
   compileSdkVersion 28
   defaultConfig {
       applicationId "ir.uncode.newdesign"
       minSdkVersion 16
       targetSdkVersion 27
       versionCode 1
       versionName "1.0"
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguardrules.pro'
       }
    }
    }

   dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
   implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
   implementation 'com.android.support:design:28.0.0-alpha3'
   implementation 'com.android.support.constraint:constraint-layout:1.1.1'
   implementation 'com.android.support:animated-vector-drawable:28.0.0-alpha3'}
   repositories {
    mavenCentral()
   }

如果問題仍然存在,請更改類和 xml 上的“導入”。

喜歡 :

import androidx.fragment.app.Fragment;

import android.support.v4.app.Fragment;

或者

import androidx.core.app.ActivityCompat;

import android.support.v4.app.ActivityCompat;

或者

com.google.android.material.bottomappbar.BottomAppBar

android.support.design.bottomappbar.BottomAppBar

如果你想使用com.android.support:support-v4:28.0.0-alpha1

那么你必須使用

com.android.support:design:28.0.0-alpha1

代替

com.google.android.material:material:1.0.0-alpha1.

如果您使用的是 Android Studio V. 3.2.1 ,您只需轉到工具欄打開 Refactor -> migrate to AndroidX,Android Studio 將處理其余的工作。

我正在使用 android studio 3.3版本。 我浪費了一天半的時間尋找這個解決方案。 我嘗試了這篇文章中的所有答案,但沒有任何幫助。 然后我找到了幫助我解決錯誤的鏈接。

我刪除了我添加的以下依賴項,

implemntation 'com.google.android.material:material:1.0.0'

相反,我使用了android設計支持庫,

implementation 'com.android.support:design:27.1.1'

嘗試在 gradle.properties 文件中設置android.enableJetifier=trueandroid.useAndroidX=true

如果您將3.1.0更改為3.2.0

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
}
  1. 你需要轉移到androidx

  2. 刪除所有以import android.support.*開頭的import android.support.*

  3. 將所有導入更改為import androix.*和相應的組件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM