I'm using two library that have dependencies of two different versions of Koin.
One of the library has org.koin:koin-android:2.0.1 and the other has io.insert-koin:koin-core-jvm:3.0.1 dependencies.
At compile time I got tons of Duplicate class error as below,
Duplicate class org.koin.android.BuildConfig found in modules jetified-koin-android-2.0.1-runtime (org.koin:koin-android:2.0.1) and jetified-koin-android-3.0.1-runtime (io.insert-koin:koin-android:3.0.1)
Duplicate class org.koin.android.ext.koin.KoinExtKt$androidContext$1 found in modules jetified-koin-android-2.0.1-runtime (org.koin:koin-android:2.0.1) and jetified-koin-android-3.0.1-runtime (io.insert-koin:koin-android:3.0.1)
Duplicate class org.koin.core.scope.Scope$injectOrNull$1 found in modules jetified-koin-core-2.0.1 (org.koin:koin-core:2.0.1) and jetified-koin-core-jvm-3.0.1 (io.insert-koin:koin-core-jvm:3.0.1)
Duplicate class org.koin.java.KoinJavaComponent$inject$1 found in modules jetified-koin-core-jvm-3.0.1 (io.insert-koin:koin-core-jvm:3.0.1) and jetified-koin-java-2.0.1 (org.koin:koin-java:2.0.1)
...
When I try to exclude one of them as below,
configurations {
all {
exclude group: "io.insert-koin", module: "koin-android"
exclude group: "io.insert-koin", module: "koin-core-jvm"
}
}
I got NoClassDefFoundError at runtime on the relevant one.
When exclude org.koin:koin-android:2.0.1
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.koin.core.KoinComponent" on path: DexPathList[[zip file "/data/app/...
When exclude io.insert-koin:koin-core-jvm:3.0.1
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.koin.core.component.KoinComponent" on path: DexPathList[[zip file "/data/app/...
How can I get to use both libraries?
Koin 3.x.x has no backwards compatibility. If there is no update on the sdk which uses Koin 2.x.x version, maybe you should better find an older version for the opposite library, which uses Koin 2.x.x. But please be aware Koin version 2.2.3 also has a different path than others (Because of jcenter limitations)
How can I get to use both libraries?
You can't use both versions of Koin at the same time, but you can tell Gradle to replace one version by the other at compile time. Note that it's not the same as excluding one of the versions altogether, but really replacing one by the other.
Here's an example:
eachDependency { details ->
// change org.koin:koin-androidx-viewmodel into io.insert-koin:koin-android
if (details.requested.group == 'org.koin' && details.requested.name == 'koin-androidx-viewmodel') {
details.useTarget group: 'io.insert-koin', name: 'koin-android', version: details.requested.version
}
}
You can read more in Gradle's doc https://docs.gradle.org/current/userguide/resolution_rules.html
It is only a partial solution though (and a hacky one too), as we're still limited by the API incompatibilities between Koin 2.x and 3.x. But if what you're using from Koin 2.x is still there in Koin 3.x, that should work.
Related
I keep getting this exception in my Android app when inflating a View located from a separate library. java.lang.NoSuchMethodError: No static method saveAttributeDataForStyleable in class or its super classes (declaration of 'androidx.core.view.ViewCompat'....
The other posts I've found related to this are suggest upgrading android support libraries, however I am using androidx libraries ( androidx.core 1.2.0 and androidx.appcompat 1.2.0). Also note for complicated business reasons I cannot upgrade the version of androidx.core used in com.myapp (1.2.0), however I can change the version used in com.mylibrary. Which is why I have this problem in the first place.
I found that saveAttributeDataForStyleable is located in androidx.core 1.3.0, but not in 1.2.0, so I switched everything in com.mylibrary to use androidx.core 1.2.0. However my com.myapp is still throwing the exception. I also already tried excluding the androidx.core library from the com.mylibrary dependency in com.myapp's build.gradle, so that the final app would reference androidx.core 1.2.0 anyway, but that also didn't work.
The app is com.myapp which has a library com.mylibrary.
SimpleView which has the inflate exception is located in com.mylibrary, which is another package I own that I've published my mavenLocal(). com.mylibrary is using androidx.core 1.2.0 and androidx.appcompat 1.2.0.
build.gradle of com.mylibrary:
{
implementation("androidx.appcompat:appcompat:1.2.0") {
exclude group: "androidx.core", module: "core"
}
implementation("androidx.core:core:1.2.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.2"){
exclude group: "androidx.core", module: "core"
}
}
build.gradle of com.myapp:
implementation("com.mylibrary") {
exclude group: "androidx.core", module: "core"
}
Full exception:
com.myapp.views:layout/my_layout: Error inflating class com.mylibrary.SimpleView
Caused by: android.view.InflateException: Binary XML file line #44 in com.myapp.views:layout/my_layout: Error inflating class com.mylibrary.SimpleView
Caused by: java.lang.reflect.InvocationTargetException: null
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:854)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at com.mylibrary.ParentSubView.<init>(Unknown Source:55)
at com.mylibrary.ParentView.<init>(Unknown Source:5)
at com.mylibrary.ParentView.<init>(Unknown Source:16)
at com.myapp.MyStore.setupParentView(MyStore.kt:94)
Caused by: java.lang.NoSuchMethodError: No static method saveAttributeDataForStyleable(Landroid/view/View;Landroid/content/Context;[ILandroid/util/AttributeSet;Landroid/content/res/TypedArray;II)V in class Landroidx/core/view/ViewCompat; or its super classes (declaration of 'androidx.core.view.ViewCompat' appears in /data/app/com.myapp/base.apk)
at androidx.appcompat.widget.AppCompatBackgroundHelper.loadFromAttributes(AppCompatBackgroundHelper.java:51)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:83)
at com.mylibrary.SimpleView.<init>(Unknown Source:5)
at com.mylibrary.SimpleView.<init>(Unknown Source:10)
at com.mylibrary.SimpleView.<init>(Unknown Source:11)
... 25 common frames omitted
Also note for complicated business reasons I cannot change the version
of androidx.core used in com.myapp, even though I can change the version used in com.mylibrary, which is why I'm stuck with using androidx.core:1.2.0 in the first place.
I figured it out. Breaking down the error message:
java.lang.NoSuchMethodError: No static method saveAttributeDataForStyleable(Landroid/view/View;Landroid/content/Context;[ILandroid/util/AttributeSet;Landroid/content/res/TypedArray;II)V in class Landroidx/core/view/ViewCompat; or its super classes (declaration of 'androidx.core.view.ViewCompat' appears in /data/app/com.myapp/base.apk)
at androidx.appcompat.widget.AppCompatBackgroundHelper.loadFromAttributes(AppCompatBackgroundHelper.java:51)
at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:83)
at com.mylibrary.SimpleView.<init>(Unknown Source:5)
This is saying saveAttributeDataForStyleable is missing. I implemented androidx.core 1.2.0 and androidx.core 1.3.0 in my source code and was able to find that saveAttributeDataForStyleable was introduced in androidx.core 1.3.0. This means com.mylibrary.SimpleView, which extends AppCompatImageView, is somehow still referencing a newer version of androidx.core (androidx.core.1.3.0+) when it's getting compiled and published as a library to my local maven repository. This results in my SimpleView.class file still having saveAttributeDataForStyleable() in it.
Then, when com.myapp is running and goes to inflate com.mylibrary.SimpleView, it sees the call to saveAttributeDataForStyleable() in AppCompatImageView and attempts to call it. But since com.myapp only has androidx.core 1.2.0 in it's dependencies, it can't find that function in any of com.myapp's source files. This is what is meant by No such method...or its super classes (declaration of 'androidx.core.view.ViewCompat' appears in /data/app/com.myapp/base.apk).
So from above, I deduced that androidx.core 1.3.0 or higher was still lurking in my com.mylibrary dependency graph.
I ran ./gradle dependencies from com.mylibrary to find that androidx.core was actually resolving to androidx.core 1.7.0 because of a dependency of another dependency. Also androidx.core was showing up in so many places in the dependency graph that I just put this at the top of my build.gradle:
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.core') {
details.useVersion "1.2.0"
}
}
}
But then I still was getting the exception. How was androidx.core 1.3.0+ still getting into my project?
I finally looked at the class AppCompatBackgroundHelper (which I should have done in the first place) and it's located in the androidx.appcompat library. My com.mylibrary package was using androidx.appcompat 1.2.0 so I went to Maven repository to see appcompat's dependencies: https://mvnrepository.com/artifact/androidx.appcompat/appcompat
And under 1.2.0 you can see its Compile Dependencies are androidx.core:1.1.0. Doh. So even though I excluded androidx.core from the appcompat line of my build.gradle, that isn't enough because the AppCompatImageView in that library makes a clear call to saveAttributeDataForStyleable() and thus imports androidx.core:1.3.0 files as a dependency anyway.
The final solution was switching the build.gradle in my com.mylibrary to:
{
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.core:core:1.2.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.2")
}
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.core') {
details.useVersion "1.2.0"
}
if (details.requested.group == 'androidx.appcompat') {
details.useVersion "1.1.0"
}
}
And I added the last line for safe measure.
After compiling com.mylibrary and publishing to mavenLocal(), and importing into com.myapp, everything worked.
Issue:
I'm using Dexguard to obfuscate codes for release build.
Previously, I could build as normal without errors.
However, when I add this dependency com.github.hyperledger:iroha-java:7.0.0, the release build process failed with an error in the screenshot below:
I guess the library internally depends on io.grpc:protoc-gen-grpc-java, but somehow Dexguard SDK can't find the dependency with the correct artifactType = dexguard-consumer-rules.
What I have tried:
adding io.grpc:protoc-gen-grpc-java:1.33.1
downgrading/upgrading version of iroha-java
Now I am not sure if the problem is caused by Dexguard or the iroha-java library.
So in case you have experiences related to this issue, please guide.
Dexguard can be causing the issue. In our experience it might be beneficial to just set up some rules within it so it would avoid the library. That should work.
In case someone also faced this error:
The solution is to downgrade iroha version to 5.2.1 and exclude io.grpc from it.
implementation('com.github.hyperledger.iroha-java:client:5.2.1') {
exclude group: 'io.grpc', module: 'protoc-gen-grpc-java'
}
I'm building a sftp upload and download project with spring integration in intellij and i'm having problems with these methods: ObjectUtils.unwrapOptional, AnnotationAttributes.getAliasedStringArray. When i run the project i get the NoSuchMethodError error for one of the methods mentioned above. I'm not finding a spring-core jar that contains both of them, the current jar i'm using in gradle is: 'compile group: org.springframework', name: 'spring-core', version: '5.0.8.RELEASE' which doesn't contain the getAliasedStringArray method at AnnotationAttributes class. Can somebody help me with the version of the jar which contains both methods? Thanks
AnnotationAttributes.getAliasedStringArray was depreciated as of 4.3.6.RELEASE and was replaced by AnnotationAttributes.getStringArray (check out the specification for 5.0.8.RELEASE).
Essentially, you'll either have to change the implemenation to the new method as the deprecated method is not in the version your using or you'll have to down grade your version.
I am building a web application and I am using Dropwizard 1.3.0, which has a dependency on jetty-io 9.4.8. This dependency has conflicts with another package (dropwizard-websocket-jee7-bundle 2.0.0), because it seem to fetch the wrong version number.
I looked into tha package, and found the method that has been renamed in 9.4.x - AbstractWebSocketConnection.java from 9.3.x - AbstractWebSocketConnection.java. The issue is that even though in Gradle the dependency tree shows I fetched 9.4.8 (the new one which I need), I still get the older, 9.3.x java file which causes the conflicts. I tried to Invalidate Caches / Restart and rebuild the whole project, but I seem to get the outdated file all the time.
What are the possible solutions for this?
If your bad class are imported by a transitive dependency, try to exclude explicit the transitive dependency.
For example if your required library is 'my.group:requiredLibrary:2.0.0' and there are another version in 'my.group:someDependency:0.1.5' you can do like this:
dependencies{
compile 'my.group:requiredLibrary:2.0.0'
compile ('my.group:someDependency:0.1.5'){
exclude group: 'my.group' module:'requiredLibrary'
}
}
Try forcing a particular version in your build.gradle
Example here: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
I do know Multiple dex problems have been reported a lot of times before, but none of the solutions seems to work in my case.
Console:
Unable to execute dex: Multiple dex files define Lbolts/AggregateException;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lbolts/AggregateException;
One of the popular solutions is unmarking the 'Android private libraries' container from buildpath. I cannot do that because there are a few more libraries in that container that i need.
Another solution is unmarking any duplicate library explicitly added in .jar form. I have no such libraries.
The duplicate library in my case is: android-support-v7-appcompat.jar
I have it (directly referenced from the sdk folder) in these two containers:
1.) Android Private Libraries
2.) Android Dependencies
The problem is that i just cannot untick any of these two containers completely, because both of them contain other necessary libraries. But i also am unable to remove just this duplicate .jar file from either containers.
EDIT:
N.B. When i add the android-support-v7-appcompat library_project to my project, it enters into both containers. There must be some way so that goes into only one.
Can any one help me how i can do it?
RESOLVED
bolts-android library was the real trouble here. There were two different versions of it causing a conflict. The FacebookSDK library brings bolts-android-1.1.2, and android-support-v7-appcompat brings bolts-android-1.1.4.
I unmarked Android Private Libraries container in the FacebookSDKlibrary project, which contained bolts-android-1.1.2. As a result, my project now had only one version, bolts-android-1.1.4, settling the conflict. It runs fine now.
Also, turns out, the duplicate android-support-v7-appcompat entries were not an issue.
i encountered this recently on my react native project, you can go to your android folder of your project . and in terminal hit this command "./gradlew app:dependencies" to see dependencies tree. i found two package for android bolts under facebook sdk . if you exclude this package from facebook sdk things will work fine again
compile ('com.facebook.react:react-native:+') {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
This can happen when adding facebook SDK to Android, you can solve it with:
compile ("com.facebook.android:facebook-android-sdk:4.1.0") {
exclude group: 'com.parse.bolts', module: 'bolts-android'
}
as react version has updated to 0.31.0,when you want to integrate com.facebook.fresco:animated-gif:0.10.0 which has com.parse.bolts has well,you may do like this:
compile ('com.facebook.react:react-native:+') {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
compile ('com.facebook.fresco:animated-gif:0.10.0'){
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}