com.android.builder.merge.DuplicateRelativeFileException - android

When I implement these two dependencies in my project:
For BTC implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
For BCH implementation 'cash.bitcoinj:bitcoincashj-examples:0.14.5.2'
This error will occur:
Caused by: com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'org.bitcoin.production.checkpoints.txt'
How can I resolve this?

This issue appears because bitcoincashj-examples library also transit org.bitcoinj:bitcoinj-core:0.14.5.2 dependency.
All that you need to do is exclude org.bitcoinj:bitcoinj-core:0.14.5.2 dependency from bitcoincashj-examples library.
implementation 'org.bitcoinj:bitcoinj-core:0.14.7'
implementation ('cash.bitcoinj:bitcoincashj-examples:0.14.5.2'){
exclude group: 'cash.bitcoinj', module: 'bitcoinj-core'
}

Related

java.lang.ClassNotFoundException: Didn't find class "io.ktor.client.HttpClientJvmKt"

I have create kotlin multiplatform project for handling API.
I integrated this in my main project but I am getting following exception.
java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/HttpClientJvmKt;
I tried to add following dependencies in my main project still issue persists.
dependencies {
implementation "io.ktor:ktor-client-core:1.3.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.7"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0"
}
packagingOptions {
exclude 'META-INF/kotlinx-io.kotlin_module'
exclude 'META-INF/atomicfu.kotlin_module'
exclude 'META-INF/kotlinx-coroutines-io.kotlin_module'
exclude 'META-INF/kotlinx-coroutines-core.kotlin_module'
}
Still I am getting this issue.
Any help would be appreciated.
In MPP you need to declare dependencies for each target.
For example:
commonMain needs to have the dependency you used above:
implementation "io.ktor:ktor-client-core:1.3.2"
androidMain needs to have it's own dependency:
implementation "io.ktor:ktor-client-okhttp:1.3.2"
iosMain also needs it's own dependency:
implementation "io.ktor:ktor-client-ios:1.3.2"
Note the suffix of ktor-client-xxxx.
So my guess is, you only need to replace the dependency in your main project to io.ktor:ktor-client-okhttp (or whichever client you prefer)

Program type already present: com.google.android.gms.common.util.VisibleForTesting

Hello I am getting following Error. I searched a lot, But none of the solution worked for me.
Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: com.google.android.gms.common.util.VisibleForTesting
My Gradle
dependencies {
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
implementation 'com.android.support:multidex:1.0.3'
implementation files('libs/AdiquityAndroidSDK.jar')
implementation files('libs/gdx-backend-android.jar')
implementation files('libs/libGoogleAnalyticsServices.jar')
implementation files('src/main/jniLibs/gdx.jar')
// implementation files('src/main/jniLibs/gdx-backend-android.jar')
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.facebook.android:facebook-android-sdk:4.33.0'
}
I have also used latest gms plugin.
classpath 'com.google.gms:google-services:4.0.1'
with gradle-wrapper 4.4 and build gradle 3.1.3.
Please Help me How to solve this.
After Searching a lot, getting Solution.
after remove implementation files('libs/libGoogleAnalyticsServices.jar') issue solved.
The issue was that the file with the same package and file name was present in two different jars one jar was of old google analytics services jar.
We have to resolve this conflict (I had removed my old jar as it was no longer needed) and the project would build.
In My case after downgrading "play services" back to version 12 issue is successfully fixed.
change
implementation('com.google.android.gms:play-services-gcm:16.0.0') {
exclude module: 'guava-jdk5'
}
implementation ('com.google.android.gms:play-services-maps:16.0.0'){
exclude module: 'guava-jdk5'
}
to
implementation('com.google.android.gms:play-services-gcm:12.0.0') {
exclude module: 'guava-jdk5'
}
implementation ('com.google.android.gms:play-services-maps:12.0.0'){
exclude module: 'guava-jdk5'
}

Program type already present: 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"
This is my dependencies:
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'
}
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!
Option 1
Following worked for me
Add the following in your gradle.properties file
android.useAndroidX = true
android.enableJetifier = false
Option 2 (if above does't work)
Android studio -> Navigate -> Class
Check include non-project classes
Copy full class path android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat
See where it is used. You may need to remove, one of them.
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'
}
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'
}
Im using flutter, and Im adding some native libraries in android, I tried the solutions posted here, but the trick for me was android.enableJetifier = true instead false
So, adding the following code to the gradle.properties, my apps are running:
android.useAndroidX = true
android.enableJetifier = true
if you still getting error after
# gradle.properties
android.useAndroidX = true
android.enableJetifier = false
then you probably forgot about main activity that calling android.support.v7.app.AppCompatActivity
change it to androidx.appcompat.app.AppCompatActivity
adding following plugins
cordova plugin add cordova-plugin-androidx
cordova plugin add cordova-plugin-androidx-adapter
solved the problem for me
At least for me the issue was with the implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' dependency. I went into the menu in Android Studio to create a Blank Fragment in Kotlin just to see what that would look like and the dependency above was added.
Once i removed that dependency the error went away.
Some of your existing dependencies are using older versions of support library, try this
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1' {
exclude group: 'com.android.support'
exclude module: 'support-v4'
}

Not able to remove transitive dependency from gradle in an Android Project

I am trying to remove the transitive dependencies from my Android project and for some reason exclude is not working when i try to remove a dependency from my particular dependency.
For example i want to remove support-annotations from my project
if i use
configurations {
all*.exclude group: 'com.android.support', module:'support-annotations'
}
The dependency gets excluded and from the dependency tree. i can see the dependency tree by using ./gradlew app:dependencies
But if i use
compile('com.android.support:support-v4:23.4.0')
{
exclude group: 'com.android.support', module:'support-annotations'
}
Then i still see the dependency in the dependency tree.
So my question is that why is it not working when i try to remove the dependency from a particular dependency ?
Update 1:
Also can anyone tell me what does the star (*) symbol next to dependency in the tree represent ?
Update 2
I am also using Fresco I tried the same thing with Fresco and exclude rule seems to work for it
Dependency Tree of Fresco
Dependency Tree when i exclude imagepipeline-base in Fresco
compile("com.facebook.fresco:fresco:0.9.0")
{
exclude group: 'com.facebook.fresco', module: 'imagepipeline-base'
}
As you can see the imagepipeline-base dependency gets excluded. So i don't know why this doesn't work for Android Support Annotations transitive dependency
So i have figured this out with the help of one of my friends. The reason why i was not able to remove support-annotation was because most of the other dependencies were using support-v4 as transitive dependency and those support-v4 also had their own copy of support-annotation.
Now there are 2 solutions to this
Solution 1:
exclude support-annotation from all the dependencies that containsupport-v4 as transitive dependency.
Solution 2:
exclude support-annotation only from my support-v4 dependency and remove support-v4 dependency from all other dependencies that have support-v4 as transitive dependency.
Note: Using one of the above approaches i was able to solve my problem and figure out how we can remove transitive dependencies when they are referenced from multiple dependencies.
And regarding the ( * ) symbol it means that the dependency tree is for that dependency is already shown. Instead of showing the whole tree for those dependencies again gradle shows ( * ) symbol with them.
Sample build.gradle file is available here
There is more graceful solution: you can use configueation.all block in your build.gradle file like in example below:
configurations.all {
exclude group: 'com.android.support', module: 'support-annotations'
}
It should exclude all transitive dependencies from all inner modules in your application.

gradle dependency error in android

In the following build.gradle, I added the configuration section to avoid double inclusion of support libraries. Support libraries are used in the main project and in the dependent projects like facebook sdk. Without the configuration section, I get "UNEXPECTED TOP-LEVEL EXCEPTION". Adding that configuration makes the error go away and the app all works fine.
Now, I'm trying to add RecyclerView to my app and I get RecyclerView class not found while inflating the recyclerview (although it builds ok). If I remove the facebook SDK and configuration section, the recyclerview works just fine.
Question: What changes can I make to the build.gradle to make the facebook SDK work and RecyclerView work? In other words, why is the config section excluding v7 when it is only supposed to exclude v4?
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:+'
compile 'com.android.support:support-v13:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.google.android.gms:play-services:4.4.52'
compile project(':facebook-3.15')
compile project(':parse-1.5.1')
compile project(':viewpagerindicator-2.4.1')
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
If you're having a dependency conflict with the v4 support library, you can just exclude it from one of the libraries via the gradle script:
compile ('com.android.support:recyclerview-v7:+') {
exclude module: 'support-v4'
}
I fixed that adding:
compile ('com.facebook.android:facebook-android-sdk:3.22.0#aar'){
exclude module: 'support-v4'
}
Found a solution to this:
Removed the config section in the build.gradle that excludes support-v4
It turns out that .aar files are basically a zip, so removed the support-v4 jar from the dependency .aar library (using 7-zip).
And now, I don't get the top-level exception and at the same time able to use recyclerview-v7.
If you are using dependency projects instead of .aar files, try removing the support-v4.jar files in the dependency projects before compiling.
Shouldn't the gradle build tool be intelligent enough to exclude the duplicate packages rather than having the users go thru this kind of workarounds and headaches?

Categories

Resources