Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build issues with new AndroidX namespace and D8 #1103

Closed
vrendina opened this issue Sep 22, 2018 · 8 comments
Closed

Build issues with new AndroidX namespace and D8 #1103

vrendina opened this issue Sep 22, 2018 · 8 comments

Comments

@vrendina
Copy link

When migrating to AndroidX and D8 I was not able to build because of the following error:

Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.app.INotificationSideChannel","sources":[{}],"tool":"D8"}

I was able to get the build to work again by excluding the support library group from my build.gradle file:

debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1' exclude group: 'com.android.support'

It looks like there is a support library dependency that is causing this problem.

// We don't need the latest version of the support library (there are no bugs that impact what
// LeakCanary relies on), we're sticking a bit older because most apps will be using a more
// recent version and they'll automatically resolve to higher version without having to
// necessarily resort to a resolution strategy. This is also the version we use in
// leakcanary-support-fragment.
//noinspection GradleDependency
implementation 'com.android.support:support-core-utils:26.0.0'

What would be the best approach?

@JakeWharton
Copy link
Collaborator

You need to specify android.enableJetifier=true and android.useAndroidX=true in your gradle.properties which will automatically rewrite dependencies to use AndroidX.

@vrendina
Copy link
Author

vrendina commented Sep 22, 2018

Hi Jake thank you for the response. Both are set to true, but I am still seeing this problem when building.

android.enableJetifier=true
android.useAndroidX=true

https://stackoverflow.com/a/51049986/5125812

@JakeWharton
Copy link
Collaborator

When you run the dependencies task you should see the android.support.* transitive dependencies replaced with androidx.*. Do you?

@vrendina
Copy link
Author

This this the output for the debug build variant:

+--- com.squareup.leakcanary:leakcanary-android:1.6.1
| +--- com.squareup.leakcanary:leakcanary-analyzer:1.6.1
| | +--- com.squareup.leakcanary:leakcanary-watcher:1.6.1
| | --- com.squareup.haha:haha:2.0.4
| | --- org.jetbrains.trove4j:trove4j:20160824
| --- com.android.support:support-core-utils:26.0.0
| +--- com.android.support:support-annotations:26.0.0
| --- com.android.support:support-compat:26.0.0
| --- com.android.support:support-annotations:26.0.0

@vrendina
Copy link
Author

Sounds like this is a gradle/jetifier issue. Thanks for pointing me in the right direction.

@vrendina
Copy link
Author

In case anyone sees this in the future the problem was with my Android Gradle plugin version. I was using 3.1.0 and needed to be using at least 3.2.0-alpha14 according to the docs. Now when I run the dependencies task I can see that all transitive dependencies of Leak Canary have been converted to the new androidx.* namespace.

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.

+--- com.squareup.leakcanary:leakcanary-android:1.6.1
| +--- com.squareup.leakcanary:leakcanary-analyzer:1.6.1
| | +--- com.squareup.leakcanary:leakcanary-watcher:1.6.1
| | --- com.squareup.haha:haha:2.0.4
| | --- org.jetbrains.trove4j:trove4j:20160824
| --- androidx.legacy:legacy-support-core-utils:1.0.0-rc01 -> 1.0.0
| +--- androidx.annotation:annotation:1.0.0
| +--- androidx.core:core:1.0.0
| | +--- androidx.annotation:annotation:1.0.0
| | +--- androidx.collection:collection:1.0.0
| | | --- androidx.annotation:annotation:1.0.0
| | +--- androidx.lifecycle:lifecycle-runtime:2.0.0
| | | +--- androidx.lifecycle:lifecycle-common:2.0.0
| | | | --- androidx.annotation:annotation:1.0.0
| | | +--- androidx.arch.core:core-common:2.0.0
| | | | --- androidx.annotation:annotation:1.0.0
| | | --- androidx.annotation:annotation:1.0.0
| | --- androidx.versionedparcelable:versionedparcelable:1.0.0
| | +--- androidx.annotation:annotation:1.0.0
| | --- androidx.collection:collection:1.0.0 ()
| +--- androidx.documentfile:documentfile:1.0.0
| | --- androidx.annotation:annotation:1.0.0
| +--- androidx.loader:loader:1.0.0
| | +--- androidx.annotation:annotation:1.0.0
| | +--- androidx.core:core:1.0.0 (
)
| | +--- androidx.lifecycle:lifecycle-livedata:2.0.0
| | | +--- androidx.arch.core:core-runtime:2.0.0
| | | | +--- androidx.annotation:annotation:1.0.0
| | | | --- androidx.arch.core:core-common:2.0.0 ()
| | | +--- androidx.lifecycle:lifecycle-livedata-core:2.0.0
| | | | +--- androidx.lifecycle:lifecycle-common:2.0.0 (
)
| | | | +--- androidx.arch.core:core-common:2.0.0 ()
| | | | --- androidx.arch.core:core-runtime:2.0.0 (
)
| | | --- androidx.arch.core:core-common:2.0.0 (*)
| | --- androidx.lifecycle:lifecycle-viewmodel:2.0.0
| | --- androidx.annotation:annotation:1.0.0
| +--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
| | --- androidx.annotation:annotation:1.0.0
| --- androidx.print:print:1.0.0
| --- androidx.annotation:annotation:1.0.0

@gurpreet433
Copy link

You need to specify android.enableJetifier=true and android.useAndroidX=true in your gradle.properties which will automatically rewrite dependencies to use AndroidX.

hahaha and it will break 150 different other things........fucking useless shit android

@pyricau
Copy link
Member

pyricau commented Jul 1, 2019

@gurpreetsudan Please read our code of conduct, this is not an appropriate comment in this community.

@square square locked as too heated and limited conversation to collaborators Jul 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants