Is there any documentation for 'dx'?
In particular, I am interested in knowing what the --core-library option does.
What is the 'dx' tool?
The dx tool converts Java class files into a *.dex (Dalvik executable)* file.
Where is it?
The dx.jar file was original located under android-sdk/platforms/android-X/tools/lib/ before (especially in Android 3 and Android 4) and was moved to android-sdk/platform-tools/lib/ later.
How does it fit in Android?
The Java source files are converted to Java class files by the Java compiler.
The dx tool converts Java class files into a *.dex (Dalvik executable)* file. All class files of the application are placed in this .dex file. During this conversion process redundant information in the class files are optimized in the .dex file.
For example, if the same String is found in different class files, the .dex file contains only one reference of this String.
These .dex files are therefore much smaller in size than the corresponding class files.
The .dex file and the resources of an Android project, e.g., the images and XML files, are packed into an .apk (Android Package) file.
To understand better, look at the Android build process:
FYI:
The program AAPT (Android Asset Packaging Tool) performs APK creation.
The resulting .apk file contains all necessary data to run the Android application and can be deployed to an Android device via the ADB (Android device bridge) tool.
Reference
This is a special purpose flag that is only used when building some of the framework JAR files (core.jar, framework.jar, etc.). Normally, dx will refuse to process any java.* or javax.* classes. So this option is used for core.jar, where all those classes are actually defined.
Here's a relevant blurb from the dx source (dalvik/dx/src/com/android/dx/command/dexer/Main.java), that gets printed if you try to include a java.* or javax.* class in an application.
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
The --core-library option on Dx will bypass the stupidity check that prevents you from accidentally including Java core libraries in your Android app.
Dx will barf if you try to include a library that contains packages in the java.* or javax.* namespace. The thinking is that classes in that namespace are likely to depend on other JDK "core" classes, which will break your app since they (may) not be present on Android.
Now, of course, just because a Java package starts with java.* or javax.* does not necessarily mean that it depends on the JDK proper. It may work perfectly fine in Android. The recommendation, if you know what you are doing, if you know that your java/x.* classes don't depend on JDK core classes, is to use a tool like JarJar to repackage the JAR file under a different namespace.
That being said, to get around the stupidity check, add the --core-library option to dx. Change the last line of $ANDROID_HOME/platform-tools/dx from,
exec java $javaOpts -jar "$jarpath" "$#"
to,
exec java $javaOpts -jar "$jarpath" --core-library "$#"
In my case, I was including a library that depended on Jackson, which depends on JAXB. For me, overriding the stupidity check was acceptable because the library's use of Jackson was only for JSON and not for XML serialization (I only include the JAXB API library, not the implementation). of course I wish there was a cleaner way to go about this, but rewriting the top-level library to avoid using Jackson was not an option.
Related
Why I'm getting below error when running the application? no error while building the app.
trouble processing "javax/security/cert/CertificateException.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
[2015-01-15 18:24:25 - ProjectName] Dx 1 error; aborting
[2015-01-15 18:24:25 - ProjectName] Conversion to Dalvik format failed with error 1
You are attempting to add a java or javax class to your project. This is not supported in general.
In this specific case, you are attempting to add a javax class that already exists in Android. That is utterly pointless, as the copy in Android will trump whatever copy is in this library.
The library that you are trying to use is not designed for use on Android (and would be seriously suspect on regular Java), and it will require modification. You may be better served using another library.
From what I read, this error could be caused by duplicate references to classes existing in diff jar files and that seemed to be the case after I fiddled with the Build Path. BUT, all I have was the android.jar and the android-support-v4.jar on my Build path and under the Referenced libraries which I need to get a clean build.
I cleaned the project, deleted the R.java, closed and reopened the project but am still getting this right off the bet. What else can I do to fix this? I need both .jar files and they are the only ones included in my project.
Console Log:
[2012-01-29 13:05:30 - HelloFragmentLayout] Dx
trouble processing "javax/security/auth/callback/PasswordCallback.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
[2012-01-29 13:05:30 - HelloFragmentLayout] Dx 1 error; aborting
[2012-01-29 13:05:30 - HelloFragmentLayout] Conversion to Dalvik format failed with error 1
I had the same problem while trying to run an example app written for android 3 under android 4. I commented-out the body of every method in every class and tried to remove the android.jar from the classpath and I don't get the error message anymore. And it works even when I comment-in the code previously out-commented... strange :( Unfortunately I'm not sure if this is the proper solution since I get a NPE while trying to run the app in question. What about you?
I have faced with the same problem, and I realized that I have added Android library twice, also the JRE environment. Just make sure that Java build path of the project only contains one Android platform as the library, and not JRE. This should resolve the issue.
Remove any other library or jar files that you might be using apart from the android library. Chances are you might be using the Android library and also have added the jar for android from "Add Jar" option. If so, remove the additional jar. After that, a clean build should solve your problem.
In my Android appliction in eclipse I get the following error:
[2011-11-03 19:39:12 - MiniPauker 1.0] Dx
trouble processing "java/crcis/pauker/AddCardActivity$1.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
[2011-11-03 19:39:12 - MiniPauker 1.0] Dx 1 error; aborting
[2011-11-03 19:39:12 - MiniPauker 1.0] Conversion to Dalvik format failed with error 1
this error only appears when run my project. I search long time to the right solution but all possible solutions don't work. I use android 4.0 and Eclipse 3.6,now
by the way, this project worked in Android 2.1 but in Android 4.0 No!!!
Your package name starts with java, which is reserved for core Java packages. You should rename your package if at all possible.
I was getting this because I had manually added android.jar to the build libraries because it was saying it wasn't finding the android libraries. The fix was to...
Remove android.jar from the build libraries
Right click on the project, go to "Android Tools", and select "Fix Project Properties"
Hope this helps.
You have to check that your project (or dependencies libraries) doesn't contain android.jar in build path (Project>Properties>Java Build Path>Order and Export).
If your main project contains android.jar in Android Private Libraries then you have to check build path for all libraries which were added to your project and remove android.jar from build path.
Modify the error caused by the jar package's scope attribute, from compile-> provided, this operation can be modified in File-> Project Structure-> Dependencies or in the project view app folder in the build.gradle file there dependencies , The corresponding jar package compile modified
like this:
enter image description here
when i add a webservice client on my eclipse project, the console show me the bottom text. What i can do to solve this problem? thanks
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.
If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.
[2011-05-10 14:33:09 - BPass Webservice Test] Dx 1 error; aborting
[2011-05-10 14:33:09 - BPass Webservice Test] Conversion to Dalvik format failed with error 1
You need to configure Eclipse to pass the --core-library flag when it calls dx. This Javax packages page describes how to do this if you're using ant to build your Android project.
I need to do LDAP authentication of my users in Android application , for the same I am using JNDI lookup method and need to include JNDI.jar in my build path , but android is not letting me do so and throwing the following error
[2011-02-17 15:08:33 - DHCAndroid]: Dx trouble processing
"javax/naming/AuthenticationException.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*) when
not building a core library.
This is often due to inadvertently including a core library file in
your application's project, when using an IDE (such as Eclipse). If
you are sure you're not intentionally defining a core class, then this
is the most likely explanation of what's going on.
However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example, from a
non-Android virtual machine project. This will most assuredly not
work. At a minimum, it jeopardizes the compatibility of your app with
future versions of the platform. It is also often of questionable
legality.
If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine distribution,
as opposed to compiling an application -- then use the
"--core-library" option to suppress this error message.
If you go ahead and use "--core-library" but are in fact building an
application, then be forewarned that your application will still fail
to build or run, at some point. Please be prepared for angry customers
who find, for example, that your application ceases to function once
they upgrade their operating system. You will be to blame for this
problem.
If you are legitimately using some code that happens to be in a core
package, then the easiest safe alternative you have is to repackage
that code. That is, move the classes in question into your own package
namespace. This means that they will never be in conflict with core
system classes. JarJar is a tool that may help you in this endeavor.
If you find that you cannot do this, then that is an indication that
the path you are on will ultimately lead to pain, suffering, grief,
and lamentation.
[2011-02-17 15:08:33 - DHCAndroid]: Dx1 error; aborting [2011-02-17
15:08:33 - DHCAndroid] Conversion to Dalvik format failed with error 1
As soon as i remove the jar the error disappears, removing the jar is not an option , please help with the way to do it
Regards,
Smriti Garg
Find another LDAP library, then, one that is not in the javax namespace. What you want to do with this JAR is not possible.
Add the dex parameter --core-library to the [ANDROID_SDK]\platform-tools\dx.bat.
Change line ~59 of dx.bat: 'set params=' to 'set params=--core-library'
This enables the Android build process to allow including javax pacakges.
Like the error message says:
move the classes in question into your own package namespace.
[...] JarJar is a tool that may help you in this endeavor.
Repackage the JNDI code into your own namespace, by using JarJar. Then rely on your new jar instead.