android external jar issue - java

In search of a way to upload an image, I added a lot of external JARs following this simple explanation:using-multipartentity-in-android-applications
But when I try co compile the code I'm getting an error:
[2012-12-14 11:37:55 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/apache/http/ConnectionClosedException;
I have never used external libraries before. Can someone tell me how to fix that?

The same class/classes may be defined in multiple libraries. That's why you are getting this error. You need to check which classes are overlapping and resolve the issue by re-organizing or removing some external libraries.
It might also be an eclipse issue. Try cleaning your project.
See the following threads:
Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
Unable to execute dex: Multiple dex files define
Error when building apk - "Multiple dex files define Lcom/google/ads/Ad"

If you type
org.apache.http.auth.AUTH auth;
somewhere in your code, then select the AUTH part, right click it and hit Declarations > Workspace, you'll where this class is declared. It's in android.jar, but in my project it was also in two separate versions of httpclient-4.x.x.jar (one had got added in as a dependency of another part of the project).
Removing the earlier version of httpclient-4.x.x.jar seems to have fixed this for me; you may find you have multiple libraries included in your project that declare this class (other than android.jar) and removing one or more will help too.

Right click the src and gen folders and select Build Path > Remove from Build Path. then Right Click > Build Path > Use as Source Folder

Related

Compiling application with Tika with Java 13 - problems loading modules

I'm trying to migrate a Java application that uses Tika from OracleJDK 1.8 to OPenJDK 13.
My IDE is Eclipse.
I have created the file module-info.java to indicate the required modules for my application.
In order to be able to use Tika classes such as AbstractParser, Detector, etc., I have added requires org.apache.tika.core; in module-info.java.
My code also uses the class org.apache.tika.parser.pdf.PDFParserConfig to extract embedded images:
PDFParserConfig pdfConfig = new PDFParserConfig();
pdfConfig.setExtractInlineImages(true);
context.set(PDFParserConfig.class, pdfConfig);'
I get the compilation error:
PDFParserConfig cannot be resolved to a type
Eclipse suggests to add requires org.apache.tika.parsers; to module-info.java: Eclipse suggestion screenshot.
When I add this module requirement to module-info.java, the application compiles properly.
That is, at this stage we have included in module-info.java:
module myapp {
/** others ... */
requires org.apache.tika.core;
requires org.apache.tika.parsers;
}
However, when trying to execute the compiled application, we get the error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Admin\.m2\repository\org\apache\tika\tika-parsers\1.24\tika-parsers-1.24.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.tika.parser.onenote.OneNoteParser not in module
Inspecting the project Libraries in Eclipse, I can see that tika-core and tika-parsers (v1.24) are both modular: Eclipse Java Build Path
In conclusion: If I don't add org.apache.tika.parsers as a required module, the application won't compile, and if I add it I get the runtime error saying org.apache.tika.parser.onenote.OneNoteParser is not in the module.
I have inspected the JAR files for these packages to see the dependencies they have. The core packages seems to be right:
$ jar --file=tika-core-1.24.jar --describe-module
No module descriptor found. Derived automatic module.
org.apache.tika.core#1.24 automatic
requires java.base mandated
contains org.apache.tika
contains org.apache.tika.concurrent
contains org.apache.tika.config
contains org.apache.tika.detect
contains org.apache.tika.embedder
contains org.apache.tika.exception
contains org.apache.tika.extractor
contains org.apache.tika.fork
contains org.apache.tika.io
contains org.apache.tika.language
contains org.apache.tika.language.detect
contains org.apache.tika.language.translate
contains org.apache.tika.metadata
contains org.apache.tika.mime
contains org.apache.tika.parser
contains org.apache.tika.parser.digest
contains org.apache.tika.parser.external
contains org.apache.tika.sax
contains org.apache.tika.sax.xpath
contains org.apache.tika.utils
...but the 'parsers' jar gives an error:
$ jar --file=tika-parsers-1.24.jar --describe-module
Unable to derive module descriptor for: tika-parsers-1.24.jar
Provider class org.apache.tika.parser.onenote.OneNoteParser not in module
Does this mean the jar package for parsers is not well formed?
Is there any workaround for this?
Thank you.
EDIT:
If I try with version 1.24.1, I get the execution error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Admin\.m2\repository\org\apache\tika\tika-parsers\1.24.1\tika-parsers-1.24.1.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.tika.parser.external.CompositeExternalParser not in module
That is: the failing class is CompositeExternalParser instead of OneNoreParser.
Inspecting META-INF/services/org.apache.tika.parser.Parser of tika-parsers-1.42.1.jarI can see the entryorg.apache.tika.parser.external.CompositeExternalParser` but the package does not contain this class.
So, it seems to be an error in this META-INF file. Id this due to an error when compiling the package and submitting it to Maven Central?
I've found a JIRA issue, TIKA-2929, where they say "Apache Tika needs to be on the Java Classpath, not the module path". I've tried this, but, as explained before, I get a compilation error if I don't add it to the module path and set requires org.apache.tika.parsers;.
This is a hard puzzle...
Ran into the same issues.
Also found the faulty entries in
org.apache.tika.parser.Parser (and also org.apache.tika.parser.Detector) in META-INF/services/
A quick fix is to ...
Unpack those files
delete the lines that seem to reference non existing classes
pack them back into the jar
My project compiled after that.
For sure no longterm solution, but since even older versions i tried ran into that problem, it might help out some people.

Decompiled Dalvik class - not all imports available

I decompiled dex and when browsing one of the classes I noticed that it contains imports from custom namespace like 'ua.blah.blah.ClassName'. When I started searching for it - seems like it is not in the dex file. I tried several tools for dex dumping and none of them helped.
So I'm wondering how is it possible for this apk\dex to work? Where this missing piece can be? It is cleanly not a standard class (like java.blah.blah).
Also I tried to search for DexClassLoader, so that may be it downloads this part from somewhere - no entries found..
The package name can be either to one of your ofuscated classes or a library class already ofuscated.
If its not on your source structure then its a jar/aar/gradle dependency.
Check into the build.gradle the packages.
Also, I don't know if it was a jar where it will be after compiled+descompiled.

How do I remove duplicate libraries appearing in Eclipse /bin/dexedLibs folder for Android dev?

I've seen this error reported several times, but none of the solutions I have read seem to help me. I'm getting the following error:
Dex Loader] Unable to execute dex: Multiple dex files define Landroid/annotation/SuppressLint;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/annotation/SuppressLint;
I did some digging around and I'm seeing these jar files in the /bin/dexedLibs folder:
android-support-v4-198bc014c99a20da45e22ed9cbf6acfc.jar
annotations-548f83e84eb7d75caedbdd94af586669.jar
annotations-c206a845ecee15ca74bd8ea29f715ccd.jar
google-play-services-90fd245eca6bf1f2b0d2bb25ec3948cc.jar
google-play-services_lib-6007bc6f3ac755b4866fa4a11c4e1704.jar
guice-3.0-no_aop-12e0ac277316bccd821359aa41181ed8.jar
javax.inject-384e1baadfa688e537ac642df7b9e932.jar
jsr305-1.3.9-13c6c964842f2bc7643c588e6fdc4754.jar
ormlite-android-4.47-185a20bcc9d996b5de6d6ca2aff0d0d5.jar
ormlite-core-4.47-42acd47179ed45763a3ec81ac92a2f20.jar
roboguice-2.0-f9de91c4687c33313255e5dd6fd324b3.jar
simple-xml-2.7.1-d80fa5a8427ec77885976924091eb340.jar
teklibrary-core-1.0.0-SNAPSHOT-cd7381a5468da36c532837d7604e95b3.jar
See the duplicate annotations and google_play_services jar files. This is what my eclipse looks like. I don't know how Google Play Services and Annotations are appearing in both Android Private Libraries and Android Dependencies.
This is where my Google Play Services is getting added to the project. The reason I have it added that way was due to an issue with the following line in code in AndroidManifest.xml where #integer/google_play_services_version wasn't being recognized.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
In Project Properties | Java Build Path | Order and Export, I have unchecked Android Dependencies.
So the question, anyone know how to resolve this issue:
[2013-11-29 10:30:49 - TekJobsAppAndroid2] Dx
trouble writing output: already prepared
[2013-11-29 10:30:49 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/annotation/SuppressLint;
[2013-11-29 10:30:49 - TekJobsAppAndroid2] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/annotation/SuppressLint;
Thanks in advance
Please note that I consistently do the following:
Delete the contents of the BIN folder
Clean Project
Build Project
Open Java Build Path ->Open Libraries Tab-> Expand all ->Find Duplicate -> Remove Them.
Delete Bin Folder.
Clean Project

Unable to execute dex: Multiple dex files define Lorg/OpenUDID/OpenUDID_manager$ValueComparator;

I'm developing for Android in Eclipse for not a long time ago and recently I encountered a problem. I created a library in which i use two additional jar libraries: appbooster.jar and adcolony.jar. After i added the created library to the main application, on launching it says:
E/AndroidRuntime(22887):
java.lang.NoClassDefFoundError:com.appsfire.appbooster.jar.af_NotificationsManager
E/AndroidRuntime(22887):at com.testlib.MainActivity.onCreate(MainActivity.java:14)
...
I added the appbooster.jar and adcolony.jar to the main application too (Properties-->Java Build Path-->Libraries-->Add External JARs). The same result:
E/AndroidRuntime(26403): FATAL EXCEPTION: main
E/AndroidRuntime(26403): java.lang.NoClassDefFoundError:com.appsfire.appbooster.jar.af_NotificationsManager
E/AndroidRuntime(26403):at com.testlib.LibClass.initiateAppBooster(LibClass.java:9)
Then i went to (Properties-->Java Build Path-->Order and Export) from main application and checked those 2 jar files (appbooster and adcolony). Now it says:
[2013-09-16 16:54:24 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/OpenUDID/OpenUDID_manager$ValueComparator;
[2013-09-16 16:54:24 - TestApp] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/OpenUDID/OpenUDID_manager$ValueComparator;
Can anybody please help me. I've been working on this error for quite a long time.
Both appbooster.jar and adcolony.jar bundle the OpenUDID libraries. Delete those files from one of the libraries, e.g.:
zip adcolony.jar -d org/OpenUDID/*
Where did you put the JAR libraries? They should be under your libs folder within your Android application. This seems the most likely possibility because your Android Java code cannot read those classes that are in those JAR packages. So I would definitely check whether they are actually in the libs directory within your Android project.
Please see the following article.
Under your libs folder, check to see if there are more than one of the same .jar file i.e gson-1.0 and gson-1.0(1). Delete the latter if there is.

GWT super-source gives unable to resolve class java/lang/Object in development mode

I am trying to emulate some java.lang and java.io classes, e.g. OutputStream within GWT.
I have created a "super" package in my module and referenced it using super-source.
My package structure looks like
com/example/gwt/client
com/example/gwt/server
com/example/gwt/shared
com/example/gwt/super
com/example/gwt/super/java/io/OutputStream.java
com/example/gwt/mymodule.get.xml
and mymodule.xml contains an entry
<super-source path="super" />
Within Eclipse all of the files within the super folder are in error - to be expected because the package structure is wrong. .class files are being generated in the WEB-INF/classes folder, again with the "wrong" package structure so should be ignored.
When I run my application in development mode I get lots of
unable to resolve class java/lang/Object
errors. What am I doing wrong?
Rename ....get.xml to ....gwt.xml?
You can exclude "super" from the eclipse build path.
Try right-clicking or the build path menu exclusion options..
There was nothing wrong with the approach - just the execution.
I had compile errors in the emulated classes which were being masked by the fact that Eclipse was showing errors because of the "incorrect" package structure. Running the compiler from within Eclipse flushed these out.
It also seems that deleting the gwt-unitCache might have helped. As I was moving code around it seems that there were stale entries in here that were still being referenced.

Categories

Resources