可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Whenever i add implemntation 'com.google.android.material:material:1.0.0-alpha1'
when i try to build my project Android Studio says:
Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy Message{kind=ERROR, text=Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[Unknown source file], tool name=Optional.of(D8)}
This is my gradle script:
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' }
I'm new ith this type of errors, and i didn't find anithing with this error. Thanks
回答1:
I've been struggling all day with this issue too. Finally I managed to compile and run the project successfully.
First of all, get rid of this:
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'
Add the following in your gradle.properties file:
android.useAndroidX = true android.enableJetifier = false
And finally, sync the project and then compile.
If it doesn't work, clean the project and then rebuild.
PS: I can't get targetSdkVersion 'p' to work. My build.gradle file end up as follows:
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' }
Hope it works for you too.
回答2:
I started getting this error after upgrading the ButterKnife to the version 8.8.1.
So, I run the command gradle -q dependencies
to generate a dependency report, after that you should see where D8 is coming from. In my case from the "ButterKnife" library:
+--- com.jakewharton:butterknife:8.8.1 | | \--- com.android.support:support-compat:d8
Also you can see your android dependencies by going to your Android Studio Gradle view (In Android Studio tool bar navigate to "View/Tool Windows/Gradle"), and selecting the target "androidDependencies" under "My-Project-Name/Tasks/android" (Double click to run or Right click and run).
To solve this problem I added this piece of code exclude module: 'support-compat'
to my "app/build.gradle" as below:
implementation ('com.jakewharton:butterknife:8.8.1') { exclude module: 'support-compat' } annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
Hope it works for someone else :] Cheers!
回答3:
I wasted 2 days looking for a solution. Anyone who's still looking for a solution can follow the steps below:
Update your Android Studio to the latest version.
Update your compileSdkVersion and targetSdkVersion to 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" } }
Go to File > Project Structure and change your gradle version to 4.10.

4. Add this dependency first:
implementation 'com.google.android.material:material:1.0.0'
5. Now remove all the support library dependencies:
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' })
Now paste the following into your gradle.properties file:
android.useAndroidX = true android.enableJetifier = true
In your project level build.gradle file:
dependencies { classpath 'com.android.tools.build:gradle:3.2.0' classpath 'com.google.gms:google-services:4.1.0' };
For those who are using Butterknife add below lines in your project level build.gradle file:
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" } } }
And in your module build.gradle file add below dependencies:
implementation "com.jakewharton:butterknife:9.0.0-SNAPSHOT" annotationProcessor "com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT"
- Now Goto Build > Rebuild Project then you might be getting a lot of errors.
- Now refer this link.
It has the list of all the old (android.support) vs new (androidx.*) dependencies.
Replace all your old imports with the new ones
(Use replaceAll feature of android studio [ctrl + shift + R] which will save you some time).
- Finally After refactoring all the old libraries with the new ones:
Rebuild the project again and hopefully it should work.
Note: You can also use Refactor > Migrate to androidx in android studio but it didn't work for me.
回答4:
Android Studio v3.2+ resolves this issue. It also adds a "Migrate to AndroidX" item under the Refactor menu. No work-around or rollback required.
Update Android Studio from the beta channel to use 3.2+ or wait until a stable version is released.
EDIT: Android Studio v3.2 is now in the stable channel. It is important you no longer use the support libraries and migrate to AndroidX libraries because support for the old support libraries has ended.
回答5:
Try to add
android.enableD8 = false
to gradle.properties file.
回答6:
If you want to use com.android.support:support-v4:28.0.0-alpha1
,
then you have to use
com.android.support:design:28.0.0-alpha1
instead of
com.google.android.material:material:1.0.0-alpha1.
回答7:
Use this
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() }
and If the problem persists change "import" on class and xml.
like :
import androidx.fragment.app.Fragment; import android.support.v4.app.Fragment;
or
import androidx.core.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
or
com.google.android.material.bottomappbar.BottomAppBar android.support.design.bottomappbar.BottomAppBar
回答8:
If you are including a library that has a transitive dependency on the Android support library you also have to use the jetifier
feature that is part of the Android Gradle plugin version 3.2.0-alpha14 or higher. You can determine if you have a library that depends on the support library by running your Gradle dependencies
task.
From the Android Developer's blog post (https://android-developers.googleblog.com/2018/05/hello-world-androidx.html):
If you depend on a library that references the older Support Library, Android Studio will update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied by the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. We will also provide a standalone translation tool as a JAR.
In your gradle.properties
file make sure that you have:
android.enableJetifier=true android.useAndroidX=true
I had this issue with Leak Canary on a small project and it was solved by upgrading the Android Gradle plugin to the appropriate version. https://github.com/square/leakcanary/issues/1103