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)
Related
I am developing an android application in which I am using two gradle dependency and both gradle dependency has libwebrtc.jar with different version so I want to exclude libwebrtc.jar from one of the dependency
dependencies {
implementation 'com.twilio:video-android:3.2.1'
implementation project(":webrtc-android-framework")
}
This two dependancy has libwebrtc.jar file with different version if I am remove the libwebrtc.jar file from the webrtc-android-framework module then some classes is not found so I can't remove the jar file so I want to exclude the libwebrtc.jar file from the com.twilio:video-android:3.2.1 dependancy
I am getting below error when build the application
Error: Program type already present: org.webrtc.BaseBitrateAdjuster
Below is the way enforcing a dependency version:
configurations.all {
resolutionStrategy.force 'your-dependency:version'
}
If you want to exclude the downstream dependencies depended by your dependencies, try below:
implementation "one-of-your-dependencies" {
exclude group:'org.webrtc'
}
Or more generally,
configurations.implementation.transitive = false
Or configurations.compile.transitive = false if you are using gradle version below 2.3.3.
Struggling to use Dagger 2 for UI testing powered by Espresso. I'm trying to generate a dedicated test #Component under androidTest directory but getting this error:
Error:Bad service configuration file, or exception thrown while constructing
Processor object: javax.annotation.processing.Processor:
Provider dagger.android.processor.AndroidProcessor could not be instantiated:
java.lang.NoClassDefFoundError: com/google/common/collect/SetMultimap
Here's how dependencies look like:
androidTestCompile "com.google.dagger:dagger:2.11",
androidTestCompile "com.google.dagger:dagger-android:2.11"
androidTestCompile "com.google.dagger:dagger-android-support:2.11"
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.11"
androidTestAnnotationProcessor "com.google.dagger:dagger-android-processor:2.11"
Have anyone faced with this and has a clue how to solve it?
Thanks.
Found a solution, basically, the culprit was lying in build.gradle just a few lines below:
configurations {
...
androidTestCompile.exclude group: 'com.google.guava', module: 'guava'
...
}
This line was excluding some useful stuff from Dagger library and preventing it from being compilable.
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.
I am trying to solve the problem,
I have some dependencies declared in build.gradle file for my android app, but the problem is that a lot of these dependencies use the same compat library, in my case appcompat-v7.
It is possible to exclude this library for each dependency
compile ('com.github......'){
exclude group: 'com.android.support', module: 'appcompat-v7'
}
But I need to do this in for each dependency
Another way is to use such expression
configurations {
compile.exclude module: 'appcompat-v7'
}
This works, but even If declare this library explicitly it is ignored compile 'com.android.support:appcompat-v7:+'
All what I need it is to include this library only once for the whole app, because if compile without exclude it will show a lot of errors like has been already defined.
Maybe there is an easier way to get this working. I would be grateful for any help, thanks.
We use a provided configuration in gradle (so that when we gradle:eclipse, the packages are included, but are not included when compiled into a jar, as these jars are expected to be provided at runtime). This configuration looks like the following:
configurations {
provided {
dependencies.all {dep ->
configurations.default.exclude group: dep.group, module:dep.name
}
}
compile.extendsFrom provided
}
This allows us to include dependencies as follows:
dependencies {
compile("org.scala-lang:scala-library:2.11.7")
compile("org.scala-lang:scala-compiler:2.11.7")
provided("org.apache.spark:spark-core_2_11:2.0.0")
}
Try creating a configuration which contains all dependencies where you want to exclude appcompat-v7, and then extend compile from this new configuration.
After updating android-support library to 22.2.0 project stopped compiling.
error: cannot access DialogStyle
class file for android.support.v4.app.DialogFragment$DialogStyle not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for android.support.v4.app.DialogFragment$DialogStyle not found
Can't find how to work around this issue.
Previously used version was 22.1.1
#takoli's answer works in most cases but if you have other dependencies that silently include support-v4 or if you are too lazy to explicitly exclude support-v4 everywhere here is another solution.
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:mediarouter-v7:22.2.0'
// Force stable version of support-v4
compile ('com.android.support:support-v4:22.1.1') {
force = true
}
Update:
AndroidAnnotations released a new version 3.3.2 that resolves this issue. If you are using AndroidAnnotations update to 3.3.2 and use the 22.2.0 support libraries without forcing the old version of support-v4. For more information see this thread
Here is a couple workarounds that worked for us:
Workaround 1 (some people see a NPE with this, some don't)
I just found a TEMPORARY workaround... till appcompat fixes this issue:
Create the following package in your project src/main/java
android.support.v4.app
Create the following new file:
DialogFragment$DialogStyle.java
Contents
package android.support.v4.app;
// todo remove this file when fixed in appcompat (https://code.google.com/p/android/issues/detail?id=175086)
public #interface DialogFragment$DialogStyle {
}
Workaround 2 (bit more ugly, but less potential for a build issue)
I found another work-around.... a bit more ugly... but has gotten us around this issue (including the NPE on the above work-around) till appcompat 22.2 is fixed.
Create the following package in your project src/main/java
android.support.v4.app
Copy the Google v4 FragmentDialog.java code
https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/app/DialogFragment.java
Rename the class (to something like TempFragmentDialog). You will get a "Duplicate" class error if you don't rename the class.
Any FragmentDialog, in your project, that has #Inject will need to extend your copy of the FragmentDialog (example: public class MyFragmentDialog extends TempFragmentDialog)
Try this, it resolved my issue:
compile ('com.android.support:appcompat-v7:22.2.0') {
exclude module: 'support-v4' }
compile ('com.android.support:recyclerview-v7:22.2.0') {
exclude module: 'support-v4' }
compile ('com.android.support:cardview-v7:22.2.0') {
exclude module: 'support-v4' }
compile ('com.android.support:design:22.2.0') {
exclude module: 'support-v4' }
// and exclude support-v4 from other dependencies as well that might include it
// finally add it, but avoid version 22.2.0...
compile ('com.android.support:support-v4:22.1.1')
There is no need to manually add the support-v4 library to your libs directory, the last import ensures that the right version is included in your project.
BTW all of this workaround is not your fault, blame others :)
I am using the work around found here https://code.google.com/p/android/issues/detail?id=175086#c9
I modified my build.gradle file to say the following in the dependencies section:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile ('com.android.support:appcompat-v7:22.2.0') {
exclude module: 'support-v4'
}
compile ('com.android.support:gridlayout-v7:22.2.0') {
exclude module: 'support-v4'
}
compile ('com.android.support:cardview-v7:22.2.0') {
exclude module: 'support-v4'
}
compile ('com.android.support:design:22.2.0') {
exclude module: 'support-v4'
}
You will also have to exclude it from any other dependencies that use the support library like dagger or facebook.
Then, I added the android-support-v4.jar file found in $ANDROID_HOME/extras/android/support/v4 to my libs directory, as that file does seem to have DialogFragment$DialogStyle.
Now, my build is fully working again, but I still hope this can get fixed soon.
Simply put, this is a bug in support library version 22.2.0
Just upgrade to the next update 22.2.1, works like a charm.
Just in case to not to skip an answer: here is also a discussion about this problem https://github.com/excilys/androidannotations/issues/1435
BTW, do you use Android Annotations in a project where this problem exists ?
It happens if you are using android.support.v4.app.DialogFragment.
Try to use android.app.DialogFragment instead.