Not able to generate signed .apk due to including proguard - java

I am trying to generate a signed .apk in android studio. But I have not been able to do the same showing me the following error. I have tried searching a lot and found no solution. Please see the following code:
Warning:com.fasterxml.jackson.databind.ext.DOMSerializer: can't find
referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
Warning:com.fasterxml.jackson.databind.ext.PathDeserializer: can't
find referenced class java.nio.file.Path
Warning:com.fasterxml.jackson.databind.ext.PathDeserializer: can't
find referenced class java.nio.file.Paths
Warning:com.fasterxml.jackson.databind.ext.PathDeserializer: can't
find referenced class java.nio.file.Path
Warning:com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector$Java7Support:
can't find referenced class java.beans.Transient
Warning:com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector$Java7Support:
can't find referenced class java.beans.ConstructorProperties

Two possibilities:
1.Try disabling minify. Set minify to false on release build type and try to generate Apk.
2.Exclude the required java class files from minify using the proguard file. Libraries including Jackson usually needs to be excluded from minify.

Related

Why can't Xamarin import Spongy Castle?

I get tons of error regarding SpongyCastle's auto-generated .cs files after importing them, even though Xamarin generated them.
The Java library that I created needs the dependency, and I imported it into the Jars folder together with my Java library.
How to fix this?
If it is a Java library that is referenced by your Java library and you do not need to access it via C# user code, then you do not need to create a C# bindings for it.
Flag that .jar/.aar with a build type of:
EmbeddedReferenceJar : Use this to compile against and include it in your binding library.
or
ReferenceJar : Use this to compile against but not include it in your binding library. You will need to supply it in your final APK in another way.
Re: Build Actions

Resolving a "duplicate definition of library class" in ProGuard

I have a Java project which includes the Xerces library.
When I process the project with Proguard, I get the warning:
Note: duplicate definition of library class [org.w3c.dom.html.HTMLDOMImplementation]
I see in Xerces that this class exists, and that a same class exists in the rt.jar of JDK 1.6.
The jar file created by ProGuard does not launch (error: "A Java Exception Has Occurred").
How can I solve this problem? Thx!
(note: I work with Netbeans)
1) Either you should remove the class from one of the library (which is not advisable as it might break other classes)
2) Find a jar withouth this class. For e.g. the class which you are using in your application might be available in a number of jars. So get the jar where this conflicting class is not present but other classes which you want are present (this might take some time)
3) (and best) just ignore the error. I don't think it should give any problem. Based on which jar occurrs first in the class path, the class will be picked up.

Eclipse export Signed APK fails with SDK 12 and Compatibility LIbrary

I'm trying to export a signed obfuscated version of my Android application and I keep getting this error. I recently added the v4 compatibility library and haven't been able to export a signed APK since then. Any help would be appreciated.
Notes: Using SDK 12 and the default proguard.cfg
Here's the console output:
Proguard returned with error code 1. See console
Warning: android.support.v4.os.ParcelableCompatCreatorHoneycombMR2: can't find superclass or interface android.os.Parcelable$ClassLoaderCreator
Warning: android.support.v4.os.ParcelableCompatCreatorHoneycombMR2: can't find referenced class android.os.Parcelable$ClassLoaderCreator
Warning: android.support.v4.os.ParcelableCompatCreatorHoneycombMR2: can't find referenced class android.os.Parcelable$ClassLoaderCreator
Warning: there were 3 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars'),
or perhaps the '-dontskipnonpubliclibraryclasses' option.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:308)
at proguard.ProGuard.initialize(ProGuard.java:210)
at proguard.ProGuard.execute(ProGuard.java:85)
at proguard.ProGuard.main(ProGuard.java:499)
-dontwarn **CompatCreatorHoneycombMR2 was the answer.

Proguard issues with jar files, how to find the missing jar?

When I try to export my apk with Proguard I get a lot of errors (over 400) similar to:
Warning: org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper
and
org.codehaus.jackson.xc.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource
I am using the Jackson Json library, and the errors seem related to that.
Researching this error I found the following from Proguards FAQ:
If there are unresolved references to classes or interfaces, you most likely forgot to specify an essential library. For proper processing, all libraries that are referenced by your code must be specified, including the Java run-time library. For specifying libraries, use the -libraryjars option.
Searching around on SO I found a lot of unanswered questions related to this, but the general sense was that the jar file I am using (in this case Jackon JSON) is relying on more libraries and they need to be added to Proguard's config file some how.
However, I can't figure out how to determine what jars are needed and where they are. The warnings mention a lot of different packages such as javax.ws.rs.ext, org.joda.time, org.codehaus.stax2, javax.xml.stream, etc.
How do I determine what jars contain those packages? For example, what jar is required for the javax.ws.rs.ext.** classes?
How do I figure out where those jars are and what path would be used with -libraryjars in Proguard?
Thanks much
Edit: I should also mention that I am using an Android Library Project setup. The jars are in the main Library project, and the actual working project has their build paths including the jars in the Library project. Don't know if that makes a difference but thought I should mention it.
Update Just to test, I completely removed the jackson far from the build path and from my code and now Proguard completes successfully. The questions still remain... What is the correct approach for handling these errors?
Does the Android export wizard in Eclipse automatically add the /lib/ jars to proguard or do they all have to be added manually in the proguard config file like this:
-libraryjars C:/Project/lib/somjar.jar
I did try that for the jackson one but it didn't make any difference. Does this mean I also have to find all of the jars that are needed for the classes mentioned in the warnings and add those? Would they be in the sdk or in the java installation?
Sorry if these are stupid questions, but I have been trying to figure this out for the last couple hours and have no idea what to do.
Thanks again
Update Again
So more searching, combined with Benjamin's suggestion, I found some of the missing classes were in rt.jar, which is in the jdk's lib folder. So I ended up adding
-libraryjars <java.home>/lib/rt.jar
To the proguard.cfg file and brought the warnings from 485 down to 204. Hey I guess that's something... The remaining warnings describe classes that I cannot find at all. The app works just fine without running proguard, so these classes must be somewhere right? Or are these warnings that I should use -dontwarn with?
The remaining classes are in these packages:
org.joda.time.
org.codehaus.stax2.
javax.ws.rs.
So now I just need a way to figure out:
What jars have these classes
Where are these jars so I can include them in the proguard config file
I've had similar problems with Proguard and similar errors I was using an osmdroid.jar which built OK unobfuscated. This jar must have had external dependencies which my application didn't need. Fortunately the authors listed the jars needed and once I downloaded them and told Proguard via the -libraryjars option, the Proguard build was OK.
Re your missing jars (which you probably don't really need, but Proguard thinks you might!), you should find them at:
org.joda.time
(The jar's inside the zip)
org.codehaus.stax2.
javax.ws.rs.
I only can provide an answer for the first part:
Give
http://www.findjar.com
a try, there you might find the names of the needed jar files
like so
You don't need to include the libraries for Proguard; you need to instead instruct Proguard to keep the class names and some other stuff. I toyed around with it a bit myself, and I ended up with something similar to this discussion:
-keepnames class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**
If you're still experiencing crashes—and I would suggest testing vigorously!—you might want to keep Jackson completely intact with:
-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**
(Note that the latter produces a larger file.)

Indirectly referenced from required .class file

I'm getting an error message when I try to build my project in eclipse:
The type weblogic.utils.expressions.ExpressionMap cannot be resolved. It is indirectly referenced
from required .class files
I've looked online for a solution and cannot find one (except for those sites that make you pay for help). Anyone have any idea of a way to find out how to go about solving this problem? Any help is appreciated, thanks!
How are you adding your Weblogic classes to the classpath in Eclipse? Are you using WTP, and a server runtime? If so, is your server runtime associated with your project?
If you right click on your project and choose build path->configure build path and then choose the libraries tab. You should see the weblogic libraries associated here. If you do not you can click Add Library->Server Runtime. If the library is not there, then you first need to configure it. Windows->Preferences->Server->Installed runtimes
Add spring-tx jar file and it should settle it.
Have you Googled for "weblogic ExpressionMap"? Do you know what it is and what it does?
Looks like you definitely need to be compiling alongside Weblogic and with Weblogic's jars included in your Eclipse classpath, if you're not already.
If you're not already working with Weblogic, then you need to find out what in the world is referencing it. You might need to do some heavy-duty grepping on your jars, classfiles, and/or source files looking for which ones include the string "weblogic".
If I had to include something that was relying on this Weblogic class, but couldn't use Weblogic, I'd be tempted to try to reverse-engineer a compatible class. Create your own weblogic.utils.expressions.ExpressionMap class; see if everything compiles; use any resultant errors or warnings at compile-time or runtime to give you clues as to what methods and other members need to be in this class. Make stub methods that do nothing or return null if possible.
This issue happen because of few jars are getting references from other jar and reference jar is missing .
Example : Spring framework
Description Resource Path Location Type
The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.beans.factory.annotation.Autowire. Fix the build path then try building this project SpringBatch Unknown Java Problem
In this case "org.springframework.beans.factory.annotation.Autowire" is missing.
Spring-bean.jar is missing
Once you add dependency in your class path issue will resolve.
I was getting this error:
The type com.ibm.portal.state.exceptions.StateException cannot be resolved. It is indirectly referenced from required .class files
Doing the following fixed it for me:
Properties -> Java build path -> Libraries -> Server Library[wps.base.v61]unbound -> Websphere Portal v6.1 on WAS 7 -> Finish -> OK

Categories