I am using two sdk's in my app. My sdk is using a compiled obfuscated jar file which is causing conflict with other sdk when add together as dependency in an app.
Due to which I am getting a compile time error as follows
Duplicate class a.a found in modules module-core-31.2.5-runtime (com.random1.android.sdk:module-core:31.2.5) and random2-core-4.0.0-runtime (com.abc.xyz:random2-core:5.0.0)
Duplicate class b.a found in modules module-core-31.2.5-runtime (com.random1.android.sdk:module-core:31.2.5) and random2-core-4.0.0-runtime (com.abc.xyz:random2-core:5.0.0)
How to resolve this as this code comes from jar and these SDK's are already compiled?
Class names such as a.a or a.b look like identifiers generated by obfuscators.
If you're sure both SDKs use the very same JAR (in which case I don't see why this would happen), then there are generally two options:
Leave out this dependency from one of the SDKs:
https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html#sec:excluding-transitive-deps
Use a custom class loader based on the Bootstrap class loader to which you can add all unique resources found by the System class loader.
Given that it's a compile time error, you're probably left with the first option only.
Related
I recently extracted some code from my Android application project into separate kotlin modules (the build.gradle files declare the "java-library" and "kotlin" plugins).
Now, the task ':app:minifyQaWithR8' is failing with the message:
AGPBI: {"kind":"error","text":"Type com.myapp.ext.models.AckResponse
is defined multiple times:
E:\projects\myapp\ext\build\.transforms\35656f2face08400c6d53844207373f0\jetified-ext.jar:com/myapp/ext/models/AckResponse.class,
E:\projects\myapp\app\build\tmp\kotlin-classes\qa\com\myapp\ext\models\AckResponse.class"}],"tool":"R8"}
I tried deleting each module's build folder, then invaldate cache/restart, then assemble, and got a similar result with a different class. But both times, the locations were the same: one was in .transforms\35656f2face08400c6d53844207373f0\jetified-ext.jar and one in app\build\tmp\kotlin-classes\qa
In a similar question a member of the R8 team suggests that one of these locations represents a dependency, and one represents the app code, however, I cannot find any instance of the class in question in my application code, nor any indication that my module is being imported more than once.
It may be relevant that two of my modules do have a lot of the same classes, however I'm using the following statement to only include one of them in the build:
if(api_version == "ext2") {
implementation project(":ext2")
}else{
implementation project(":ext1")
}
The packages in these modules do not appear in the main application code.
What other steps can I take to track down the root of this issue?
As it turns out, there were in fact duplicate classes in my project. I was just unable to find them at first because the package name in the file did not correspond to the folder where the file was located.
In my android app, I had a module labelled base. Inside base were a couple classes which acted as base lifecycle classes(Controller, ViewModel, etc.). My app was working just fine with these class local inside my project. I decided to move those out into their own library so that they could be reused on future projects. So I've published my library via jitpack and now add that library as a dependency in my gradle file.
My issue is that now it seems like all the code has been obfuscated and Koin cannot find definitions for my ViewModel classes. For example, the error I get it
Caused by: h.a.c.f.e: No definition found for 'c.c.a' has been found. Check your module definitions.
I'm using ViewModel{} block to inject my view models in my koin modules but no I don't even know what classes it can not find definitions for because all the code has been obfuscated. Has anyone encountered this and can point me in right direction? The only change I made was delete the local files and publish those files to a library which I now have as a dependency.
The problem resolved itself, I have no idea how or why. I created a new release on my github and used that version and Wa-Lah.
I have a library and it depends on Android-support-v4 (The JobIntentService class). I'm going to use it in Basic4Android.
There are two ways of adding supprt-v4 dependency to project:
Add <dependsOn>com.android.support:support-v4</dependsOn>
to library xml.
Add
dependsOn>support-annotations</dependsOn>
<dependsOn>support-compat</dependsOn>
<dependsOn>support-v4</dependsOn>
<dependsOn>support-core-ui</dependsOn>
<dependsOn>support-core-utils</dependsOn>
<dependsOn>support-fragment</dependsOn>
<dependsOn>support-media-compat</dependsOn>
to that xml.
If I use the first way, I can't find JobIntentService. If I use the second way it's fine, but It will have a conflict with the AppCompat library.
So how an I have a complete code of support-v4 without experiencing conflicts?
I know that JobIntentService exists in support-compat part of android-support-v4, but adding it beside com.android.support:support-v4 still causes duplications.
Since the first way uses Maven artifacts to get your library from Jcenter, it might download an old version that does not include this class in it's class path.
To resolve this clear libraries of B4A placed in the sdk m2repository
folder named b4a_remote, delete it and let the B4A redownload the files. Therefore it will download fresh and updated libraries that contain this class.
I have services_intermediates.jar that contains com.android.server.devicepolicy.DevicePolicyManagerService. Using this I can compile my code (that uses DPMS) but it crashes when run on device reporting no class DevicePolicyManagerService found.
I don't want to package the whole intermediate jar with my app and so I use "provided" in gradle dependency not "compile".
On a broader perspective, how to use classes that are under /framework in AOSP but not available at runtime for use in some application package?
If I need to use some library in multiple modules and add the line
compile 'example.path_to_library'
to both modules build.gradle,
will it create only one instance of the library classes and point to that or each module will have 2 separate libraries of the same stuff?
it will create only one instance of the library classes and point to that.
The library will be downloaded in your External Libraries folder and both the modules will access the same library.
if it solves your problem..do check this answer as correct..thank you, have a good day :)