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.
Related
I downloaded the Codename One tutorial project, added some custom code with libraries but when building the project I get 'Compliance Check Failed' error. This error is cauesed by multiple Proguard warnings like:
there were # unresolved references to library class members.
there were # unresolved references to program class members.
These libraries are working fine just the proguard warnings create an error. I want to add '-dontwarn' option to the proguard config file but the problem is there is no such file. Any ideas how to correct this error? I'm using IntelliJ Idea. Thanks for any help.
You can use the build hint android.proguardKeep to add the additional parameters e.g.:
android.proguardKeep=-keep class com.mypackage.ProblemClass { *; }`
You can add the build hints in Codename One Settings. See the developer guide for more.
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.
After updating dependencies on Gradle Android build to use com.android.support:support-v4:22.2.0 from local Maven extras repository (within SDK), Proguard started throwing these problems.
Warning: android.support.v4.app.DialogFragment: can't find referenced class android.support.v4.app.DialogFragment$DialogStyle
Warning: android.support.v4.app.FragmentTransaction: can't find referenced class android.support.v4.app.FragmentTransaction$Transit
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ResolvedLayoutDirectionMode
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayoutDirectionMode
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayerType
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$AccessibilityLiveRegion
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ImportantForAccessibility
Warning: android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$OverScroll
Warning: android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$EdgeGravity
Warning: android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$LockMode
Warning: android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$State
Warning: there were 11 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Simply adding -dontwarn android.support.v4.** solves the problem, but I'd like an more specific/elegant solution, than ignoring all problems on support.v4 package
Can anybody tell what rules should be added, so these classes/#interfaces are correctly processed by Proguard?
The only solution is what you have mentioned, i.e -dontwarn android.support.v4.**. This is actually taken from the <path-to-android-sdk>/tools/proguard/proguard-android.txt, where it says:
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
It is safe to set don't warn for the support library classes according to the Android team. You can do this via:
## Support library
-dontwarn android.support.**
I am running Proguard via the Maven Plugin, you can see my configuration here: https://github.com/sanity/tahrir/blob/proguard-debug/pom.xml#L61
You can see the complete output of "mvn -DskipTests assembly:assembly" here: https://gist.github.com/ee1081179496e11916cb
Despite quite a bit of searching I cannot find any explanation of what causes this error, nor now I can fix it?
Your input contains a library class that depends on a program class. ProGuard warns about it and doesn't allow it, unless you specify -dontwarn. You should remove that option and check ProGuard's warnings for details.
See the ProGuard manual > Introduction
See the ProGuard manual > Troubleshooting > Warning: library class ... depends on program class ...
For me, having
proguard.config=proguard-project.txt
caused the same error.
Correcting to include both sdk and my config file like below fixed it.
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
Has someone tried to use MessagePack with an Android app?
Is it possible? I have tried to use the Jar from msgpack-java and received the following Exception:
Caused by: java.lang.ExceptionInInitializerError
at org.msgpack.Packer.pack(Packer.java:532)
at org.msgpack.MessagePack.pack(MessagePack.java:31)
... 15 more
Caused by: java.lang.ExceptionInInitializerError
at org.msgpack.template.TemplateRegistry.<clinit>(TemplateRegistry.java:38)
... 17 more
Caused by: java.lang.VerifyError: org.msgpack.template.BeansFieldEntryReader
at org.msgpack.template.builder.BeansTemplateBuilder.<init (BeansTemplateBuilder.java:42)
at org.msgpack.template.builder.BuilderSelectorRegistry.initForJava(BuilderSelectorRegistry.java:73)
at org.msgpack.template.builder.BuilderSelectorRegistry.<clinit>(BuilderSelectorRegistry.java:38)
... 18 more
The code that I use is very simple
PrintWriter out = new PrintWriter(socket.getOutputStream());
Message msg = new Message();
msg.body = "asdasdasd";
msg.from = "qwe";
msg.to = "ttt";
byte[] bytes = MessagePack.pack(msg);
out.print(bytes);
out.flush();
I have javassist.jar, msgpack-0.5.2.jar, slf4j-api-1.6.2.jar and slf4j-jdk14-1.6.2.jar in my lib directory.
In my server application this code works fine with the same libraries.
(Hopefully) FINAL UPDATE
msgpack : 0.6.8 works on Android without any problems
msgpack-rpc : 0.7.0 works on Android with one caveat.
Specifically, you need to add the following to onCreate for API Level 8 (Android 2.2.1), and possibly lower:
java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
due to this bug.
If you want to see a simple example, here's a pair of projects set up for this purpose:
https://github.com/mikkoz/msgpack-android-test-server/tree/master/msgpack-android-test-server
https://github.com/mikkoz/msgpack-android-test-client/tree/master/msgpack-android-test-client
Previous Versions
UPDATE: as of 0.6.7 msgpack should be compatible with Android (there is a small dependency exclusion issue). Check the text below for msgpack-rpc (which also might be adapted in the future).
NOTE: If you're also using msgpack-rpc, you need to do the following steps:
Download the msgpack-rpc source from git://github.com/msgpack/msgpack-rpc.git (specifically, the "java" folder).
Change the main msgpack artifact version to the one you've built.
In org.msgpack.rpc.loop.netty.NettyEventLoop, change the NioClientSocketChannelFactory to OioClientSocketChannelFactory(getWorkerExecutor()).
Build the MessagePack-RPC in the same way as in the case of the main MessagePack JAR (see Step 11 above).
The NettyEventLoop replacement is due to this issue:
http://markmail.org/message/ypa3nrr64kzsyfsa .
Important: I've only tested synchronous communication. Asynchronous might not work.
And here's the reason for msgpack not working with Android prior to 0.6.7:
The reason for the error is that MessagePack uses several java.beans classes that are not included in the Android SDK. You're probably using the MessagePackBeans annotation.
This is a similar problem to the one described here, for which the general solution is outlined here. Unfortunately, in our case it requires a rebuild of msgpack. Here's what I did (you can almost certainly skip Steps 5 and 8, but I haven't tried it that way) :
Download the MessagePack source from https://github.com/msgpack/msgpack-java.git.
Import the MessagePack source as a project in your IDE.
Download the Apache Harmony source for the relevant packages from http://svn.apache.org/repos/asf/harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java .
Copy these packages into your MessagePack project's src/main/java folder:
java.beans
java.beans.beancontext
org.apache.harmony.beans
org.apache.harmony.beans.internal.nls
In your MessagePack project, remove the following classes:
PropertyChangeListener
IndexedPropertyChangeEvent
PropertyChangeEvent
PropertyChangeListenerProxy
PropertyChangeSupport
Rename the java.beans packages to something different, e.g. custom.beans .
Change all java.beans references to the renamed ID, so again e.g. custom.beans. This applies especially to BeansFieldEntryReader (this class is the reason for the original error).
Change the custom.beans references for the five classes you removed in Step 5 back to java.beans.
In the org.apache.harmony.beans.internal.nls.Messages class, comment out the method setLocale, and remove the imports associated with it.
Remove all classes that still have errors, except Encoder. In that class, comment out all references to the classes you've removed. You should now have an error-free project.
Build the MessagePack JAR:
If you're using Maven, change the version in the pom.xml to something unique, run Maven build with the install goal, then add the dependency in your Android project with that version.
If you're not using Maven, you have to run the jar goal for Ant with the included build.xml. Replace the msgpack JAR in your Android project with this one.
If you're publishing your app, remember to include the relevant legal notice for Apache Harmony. It's an Apache License, just like MessagePack.
That should do it. Using your example code, and my own data class, I was successfully able to pack and unpack data.
The entire renaming ritual is due to the fact that the DEX compiler complains about java.* package naming.
There is a critical msgpack bug saying data packed with msgpack will get corrupted on the Dalvik VM. http://jira.msgpack.org/browse/MSGPACK-51
There is an ongoing effort by #TheTerribleSwiftTomato and the MessagePack core team to get MessagePack working on Android, please see the related GitHub issue. The fix mentioned in #TheTerribleSwiftTomato's answer is to be found here.
Update
I've managed to get it at least running on Android by (painstakingly) adding all the necessary javassist Classes which are currently required for the build to succeed. An extra 600KB gain in size, yet at least it seems to work. All in all, it appears to be working to some extent on Android, eventually check out the lesser-known resources about Message Pack such as its User Group and its Wiki for more information.
On a side-note, be sure to use a HTTP Request Library (such as LoopJ's Android Async HTTP or Apache's HttpClient) which can handle binary data.
Last but not least you can ping me if there is interest in this jar which makes MessagePack seemingly work on Android – credits go out of course to #TheTerribleSwiftTomato who supplied the fix above!
I suggest you write this in the main proguard-rules file-
-dontwarn org.msgpack.**
-keep class org.msgpack.** { *; }