Duplicate class org.apache.http.impl.client.CloseableHttpClient found in modules jetified-ipp-v3-java-devkit-5.0-jar-with-dependencies.2-jar-with-dependencies
(com.intuit.quickbooks-online:ipp-v3-java-devkit:5.0.2) and
jetified-oauth2-platform-api-5.0-jar-with-dependencies.2-jar-with-dependencies
(com.intuit.quickbooks-online:oauth2-platform-api:5.0.2)
Getting above error
I have tried
1.configurations {
runtime.exclude group: 'com.intuit.quickbooks-online', module: 'ipp-v3-java-devkit'
}
2. configurations {
implementation.exclude group: 'com.intuit.quickbooks-online', module: 'ipp-v3-java-devkit'
}
but no luck till yet
Related
I am trying to run a build on Android. I'm in the process of building a React-Native bridge for a Java library. However, I am getting a Duplicate class error which looks like follows:
Duplicate class org.apache.commons.lang3.builder.CompareToBuilder
found in modules commons-lang3-3.9.jar (org.apache.commons:commons-lang3:3.9)
and creditCardNfcReader-1.0.3-runtime.jar (com.github.pro100svitlo:creditCardNfcReader:1.0.3)
There are an entire list of these errors being printed out. There is also a slightly different error which looks like this:
Duplicate class bolts.BoltsExecutors$ImmediateExecutor found in
modules bolts-tasks-1.4.0.jar (com.parse.bolts:bolts-tasks:1.4.0)
and jetified-bolts-android-1.1.2.jar (com.parse.bolts:bolts-android:1.1.2)
My dependencies currently look like this in my build.gradle file:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'com.github.pro100svitlo:creditCardNfcReader:1.0.3'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
I have tried to exclude modules and groups from the dependencies with no luck yet. Here are a few approaches I have tried as recommended from several sources:
1.
implementation ("com.facebook.react:react-native:+") {
exclude group: 'com.parse.bolts', module: 'bolts-tasks'
}
2.
implementation ("com.facebook.react:react-native:+") { exclude module: 'bolts-tasks'}
3.
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+"
implementation 'com.github.pro100svitlo:creditCardNfcReader:1.0.3'
addUnimodulesDependencies()
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
configurations { runtime.exclude group: '*' }
I would really appreciate any help with finding a solution to this problem. Thanks in advance.
The exclude method of the configuration closure for a dependency excludes transitive dependencies. So, if your module dependency depends on other modules, you can exclude them from your build. You can check out the transitive dependencies of the 'com.facebook.react:react-native:+' module on its maven repo.
https://mvnrepository.com/artifact/com.facebook.react/react-native/0.20.1
Try specify the version of dependency instead of use '+' to avoid conflict.
Here is some reference to check on resolving the plugins and dependency jar conflicts.
jarjar package reference
The line part.writeTo(out);
throws java.lang.ClassCastException:
com.sun.mail.handlers.multipart_mixed cannot be cast to javax.activation.DataContentHandler
private static void getBodyAsRFC822(
MimePart part, boolean ignoreHeaders, ByteArrayOutputStreamout) {
try {
out.reset();
if (ignoreHeaders) {
OutputStream os = MimeUtility.encode(out, part.getEncoding());
part.getDataHandler().writeTo(os);
os.close();
} else {
part.writeTo(out);
out.close();
}
}
catch (Exception e) {
_log.error(e);
}
}
This is my build.gradle
compileOnly group: 'com.liferay', name: 'com.liferay.portal.instance.lifecycle', version: '2.0.0'
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.46.0"
compileOnly group: "org.osgi", name: "org.osgi.core", version: "6.0.0"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
compileInclude group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compileInclude group: 'org.apache.mina', name: 'mina-core', version: '2.0.16'
compileInclude group: 'javax.mail', name: 'mail', version: '1.4'
compileInclude group: "javax.servlet", name: "servlet-api", version: "2.5"
But multipart_mixed implements DataContentHandler, so it should be castable. Why isn't it?
Whenever a subclass apparently can't be typecasted to its legitimate superclass, you have duplicate classes, loaded by different classloaders. Find where you load the activation (superclass) classes, eliminate all but one (typically you'll need to eliminate the one class that your own project brings) and use the provided one from the framework.
The Exception message names the classes in question but omits the classloaders participating in the game, which is why the message, on first attempt to understand it, doesn't make much sense. As soon as you know about multiple classloaders, thus multiple instances of javax.activation.DataContentHandler, it makes more sense.
Edit: With the compileInclude statements in your build.gradle, you're effectively bundling all your dependencies into your own jar file. But the framework has its own version of these classes, and while they all have the same name, they'll now be different versions (not only numeric), loaded through different classloaders. You should only use compileInclude if you clearly are dependent on something that you'll never find in the OSGi runtime. Instead, use compileOnly or compile as default, and deploy the additional dependencies to the runtime, together with your module.
Check this article for a detailed description of what you've done.
I am learning how to use Dagger2. I created an example as shown below in the code. the issue I am facing is, the auto generated class by Daggers, the one
that should be called "DaggerInterfaceComponent" is never gets created. The below DaggerInterfaceComponent is underscored with red.
Please have a look at the build gradle App posted below.
code:
InterfaceComponent component = DaggerInterfaceComponent.builder().objectValuesModule(new ObjectValuesModule()).build();
Object injectedObject = component.getObjectValues();
int returnedInt = injectedObject.getreturnInteger();
int returnedStr = injectedObject.getReturnString();
int returnedObj = injectedObject.getReturnObject();
gradle App
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "com.google.dagger:dagger:2.11"
annotationProcessor "com.google.dagger:dagger-compiler:2.11"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
}
I am trying to add some Roboelectric unit tests to my app.
Using Roboelectric 3.0 i want to be able to test my activity PinActivity and the fragment that is in it.
import android.support.v7.app.AppCompatActivity;
import android.app.Fragment;
PinActivity extends AppCompatActivity {
gradle file contains:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
PinActivityTest contains: (Edited to add #Config did not fix)
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
#RunWith(RobolectricTestRunner.class)
#Config(constants = BuildConfig.class, sdk = 21)
public class PinActivityTest {
#Test
public void onCreate_shouldInflateLayout() throws Exception {
PinActivity activity = Robolectric.buildActivity(PinActivity.class).create().get();
assertNotNull(activity);
}
Currently getting:
WARNING: No manifest file found at .\AndroidManifest.xml.Falling back to the Android OS resources only. To remove this warning, annotate your test class with #Config(manifest=Config.NONE). and java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Why can't it find my AndroidManifest?
Anyone know how i can fix this or more Roboelectric tutorials with similar examples?
As log says, you forgot about #Config annotation, so it could not find your AndroidManifest file:
Try this:
#RunWith(RobolectricGradleTestRunner.class)
#Config(constants = BuildConfig.class, sdk = 21) public class PinActivityTest {
#Test
public void onCreate_shouldInflateLayout() throws Exception {
PinActivity activity = Robolectric.buildActivity(PinActivity.class).create().get();
assertNotNull(activity);
}
As Roboelectric not support already API23, I set up test sdk as API 21.
EDIT: Change also:
PinActivity activity = Robolectric.buildActivity(PinActivity.class).create().get()
to
PinActivity activity = Robolectric.setupActivity(PinActivity.class);
NOTE: My Robolectric dependencies looks now:
testCompile("org.robolectric:robolectric:3.0") {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
If you have any question, please free to ask.
Hope it help
I have an android application which uses fragments and has implemented ActionBarCompat. I wrote simple Robolectric test shown below:
#Test
public void shouldNotBeNull() throws Exception {
MainFragment mainFragment = new MainFragment();
startFragment(mainFragment);
assertThat(mainFragment, notNullValue());
assertThat(mainFragment.getActivity(), notNullValue());
}
private void startFragment(MainFragment fragment) {
FragmentActivity activity = new FragmentActivity();
shadowOf(activity).callOnCreate(null);
shadowOf(activity).callOnStart();
shadowOf(activity).callOnResume();
FragmentManager fragmentManager = activity.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(fragment, null);
fragmentTransaction.commit();
}
I am getting following exception:
java.lang.NullPointerException: null
at android.app.Activity.invalidateOptionsMenu(Activity.java:2595)
at android.support.v4.app.ActivityCompatHoneycomb.invalidateOptionsMenu(ActivityCompatHoneycomb.java:30)
at android.support.v4.app.FragmentActivity.supportInvalidateOptionsMenu(FragmentActivity.java:572)
at android.support.v4.app.Fragment.setHasOptionsMenu(Fragment.java:708)
at com.example.android.ui.MainFragment.onCreate(MainFragment.java:599)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:834)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:37)
at org.robolectric.shadows.ShadowLooper.post(ShadowLooper.java:198)
at org.robolectric.shadows.ShadowHandler.postDelayed(ShadowHandler.java:56)
at org.robolectric.shadows.ShadowHandler.post(ShadowHandler.java:51)
at android.os.Handler.post(Handler.java)
at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1322)
at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:541)
at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:525)
at com.example.android.ui.MainFragmentTest.startFragment(MainFragmentTest.java:36)
at com.example.android.ui.MainFragmentTest.shouldNotBeNull(MainFragmentTest.java:22)
When using something like this:
MainActivity activity = new MainActivity();
shadowOf(activity).callOnCreate(null);
shadowOf(activity).callOnStart();
shadowOf(activity).callOnResume();
where MainActivity is holder activity for MainFragment, I get the following exception:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.robolectric.res.builder.RobolectricPackageManager.getActivityInfo(RobolectricPackageManager.java:59)
at android.support.v7.app.ActionBarActivityDelegate.getUiOptionsFromMetadata(ActionBarActivityDelegate.java:157)
at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:53)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
at com.example.android.ui.MainActivity.onCreate(MainActivity.java:45)
at org.robolectric.shadows.ShadowActivity.invokeReflectively(ShadowActivity.java:176)
at org.robolectric.shadows.ShadowActivity.callOnCreate(ShadowActivity.java:121)
at com.example.android.ui.MainFragmentTest.startFragment(MainFragmentTest.java:28)
at com.example.android.ui.MainFragmentTest.shouldNotBeNull(MainFragmentTest.java:22)
I suspect it could be something about ActionBarCompat and Robolectric not being compatible. Any help would be appreciated.
As of Robolectric 2.4, it is supposed to support the Appcompat library. There are a few gotchas though as it doesn't work out of the box. Things that helped me:
Creating a project.properties file with the following contents
As described in the config manual:
target=android-19 android.library.reference.1=/../../build/intermediates/exploded-aar/com.android.support/appcompat-v7/20.0.0
android.library.reference.2=/../../build/intermediates/exploded-aar/com.android.support/support-v4/20.0.0
android.library.reference.3=/../../build/intermediates/exploded-aar/com.viewpagerindicator/library/2.4.1
Setting exculdes in build.gradle for Robolectric
Apparently Robolectric has its own versions of the support libraries so the following is needed to prevent possible duplicate dependencies (referenced from here):
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'appcompat-v7' }