Can't enable Proguard on Android project containing jsch lib - android

I am trying to use Proguard to obfuscate my Android app which makes use of the library jsch-1.50.jar for uploading files to an SFTP server.
When I do an export from Eclipse, I get warnings "can't reference class" and nothing is produced. I have tried all manner of options to tell Proguard to ignore the jsch classes, but it's not making any difference and therefore I wonder if I am misunderstanding how this works. I am not too worried about the optimisation, but I would like the code obfuscated.
I have setup the proguard-properties as follows:
-keep class com.jcraft.jsch.jce.*
-keep class * extends com.jcraft.jsch.KeyExchange
-keep class com.jcraft.jsch.**
-keep class com.jcraft.jzlib.ZStream
-keep class com.jcraft.jsch.Compression
-keep class org.ietf.jgss.*
-libraryjars /libs/jsch-0.1.50.jar
The project-properties file contains an entry for "proguard.config=proguard-project.txt".
The output from the export with duplicates removed:-
Warning: com.jcraft.jsch.jcraft.Compression: can't find referenced class com.jcraft.jzlib.ZStream
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.Oid
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSManager
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSException
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSContext
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.MessageProp
Warning: there were 44 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Error: Please correct the above warnings first.
Would very much appreciate any pointers.
Thanks
Mike

After a bit more investigation, I found the following...
I had forgotten to include jzlib-1.1.1.jar in the project with the corresponding
-libraryjars /libs/jzlib-1.1.1.jar
entry in the proguard-properties.txt.
Also to ignore the warning regards references to "class org.ietf.jgss", I tried the suggested method of excluding the referencing class
-libraryjars /libs/jsch-0.1.50.jar(!com.jcraft.jsch.jgss/GSSContextKrb5.class)
but that didn't help. In the end, I went with :-
-dontwarn org.ietf.jgss.**

Related

Proguard build failed(Eclipse)

This question already have been asked many times, but I am not able to resolve it. I am trying to export my app using eclipse for final release, but I am getting the below error.
I already added
-keep class com.afollestad.materialdialogs.*{ *; }
-dontwarn com.afollestad.materialdialogs.**
-dontshrink
Error resolved, but after running my app crashed.
please help me
this is the error:
Proguard returned with error code 1. See console
Warning: com.afollestad.materialdialogs.util.DialogUtils: can't find referenced method 'android.content.res.ColorStateList getColorStateList(int)' in class android.content.Context
Warning: com.afollestad.materialdialogs.util.DialogUtils: can't find referenced method 'int getColor(int)' in class android.content.Context
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile them and try again.
Alternatively, you may have to specify the option
dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:321)
at proguard.ProGuard.initialize(ProGuard.java:211)
at proguard.ProGuard.execute(ProGuard.java:86)

Java.exe exited with code 1. Xamarin

Trying to make archive for publishing and has this error
Java heap size is set to 1G.PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
PROGUARD : warning : there were 148 unresolved references to classes or interfaces.
PROGUARD : warning : there were 2 unresolved references to program class members.
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1833,3): error MSB6006: "java.exe" exited with code 1.
I made archive for publishing at Friday and everything was ok. Yesterday I have updates and installed them, but this didn't solve the problem
What's wrong?
Problem is solved
create file named proguard.cfg inside Android project in the solution. Right click and set Build Action to ProguardConfig.
I add this to proguard file
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
Make sure you save file as UTF-8 and NOT UTF-8 BOM

kotlin android proguard error

I'm trying to build an apk and proguard it but it fails with messages like:
Error:ProGuard: [radis] Warning: kotlin.dom.EventListenerHandler: can't find superclass or interface org.w3c.dom.events.EventListener
Error:ProGuard: [radis] Warning: kotlin.dom.CloseableEventListener: can't find referenced class org.w3c.dom.events.EventTarget
Error:ProGuard: [radis] Warning: kotlin.dom.CloseableEventListener: can't find referenced class org.w3c.dom.events.EventListener
Error:ProGuard: [radis] Warning: kotlin.dom.DomPackage: can't find referenced class org.w3c.dom.events.MouseEvent
Error:ProGuard: [radis] Warning: kotlin.dom.DomPackage: can't find referenced class org.w3c.dom.events.Event
I added in my proguard.cfg, -dontwarn on kotlin.dom.** but it does not help.
I was not using standard proguard-android-optimized so I edited my config to match as much as possible (I have ACRA config as well) and add -dontwarn kotlin.** and -dontwarn org.w3c.dom.events.* and it's proguarding now.
Another problem pops up with Dexing I'm still investigating

Proguard and Netty on Android

Basically I am trying the same as this guy: How can I tell proguard to assume a package is not used? but am not able to add any comments.
I keep getting warnings like this:
Warning: org.jboss.netty.logging.Slf4JLogger: can't find referenced class org.slf4j.Logger
Basically, org.jboss.netty.logging.Slf4JLogger is referencing third party library class org.slf4j.Logger which is not part of my project. org.jboss.netty.logging.Slf4JLogger is not used either.
So I try to tell proguard not to load/use org.jboss.netty.logging.Slf4JLogger as proposed by Eric Lafortune but constantly fail in doing so.
I added -injars libs/netty-3.3.1.Final.jar(!**Slf4JLogger) or -injars libs/netty-3.3.1.Final.jar(!**Slf4JLogger.class) but this does not seem to do anything. Even
-injars libs/netty-3.3.1.Final.jar("!whatever is in here") yields the same results so I assume this option does not do anything...
How can I tell Proguard to not consider several specific classes in the netty.jar?
Using the latest ADT (18.0) which fixes some problems with ProGuard integration (as compared to ADT 16.00), I was able to successfully run my Netty based app with the following additional ProGuard Settings:
# Get rid of warnings about unreachable but unused classes referred to by Netty
-dontwarn org.jboss.netty.**
# Needed by commons logging
-keep class org.apache.commons.logging.* {*;}
#Some Factory that seemed to be pruned
-keep class java.util.concurrent.atomic.AtomicReferenceFieldUpdater {*;}
-keep class java.util.concurrent.atomic.AtomicReferenceFieldUpdaterImpl{*;}
#Some important internal fields that where removed
-keep class org.jboss.netty.channel.DefaultChannelPipeline{volatile <fields>;}
#A Factory which has a static factory implementation selector which is pruned
-keep class org.jboss.netty.util.internal.QueueFactory{static <fields>;}
#Some fields whose names need to be maintained because they are accessed using inflection
-keepclassmembernames class org.jboss.netty.util.internal.**{*;}
My conclusions about why a specific line is needed may not be 100% precise and this is definitly not the must tuned solutions but at least it works. Feel free to edit if you think you can improve this.

Mobclix and Proguard

I'm trying to use Proguard to obfuscate my code. I use Mobclix for advertisements, and when I build my APK it's spitting out an error:
org.eclipse.core.runtime.CoreException: Proguard returned with error code 1. See console
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:228)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.doExport(ExportWizard.java:290)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard.access$0(ExportWizard.java:229)
at com.android.ide.eclipse.adt.internal.wizards.export.ExportWizard$1.run(ExportWizard.java:214)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: Proguard Error 1
Output:
Warning: com.mobclix.android.sdk.MobclixContactsCursorEntityIterator: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsCursorEntityIterator: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5$EntityIteratorImpl: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsEntityIterator: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity$NamedContentValues
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity$NamedContentValues
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity$NamedContentValues
Warning: com.mobclix.android.sdk.MobclixContactsSdk5: can't find referenced class android.content.Entity
You should check if you need to specify additional program jars.
Warning: there were 17 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)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.runProguard(BuildHelper.java:527)
at com.android.ide.eclipse.adt.internal.project.ExportHelper.exportReleaseApk(ExportHelper.java:187)
... 4 more
Now, I have put the Mobclix recommended bits from their documentation into my proguard.cfg:
-keep public class com.mobclix.android.sdk.*
-keep class com.mobclix.android.sdk.MobclixJavascriptInterface
-keepclassmembers class com.mobclix.android.sdk.MobclixJavascriptInterface
{
public void *(...);
<methods>;
}
-keepclassmembernames class
com.mobclix.android.sdk.MobclixJavascriptInterface {
public void *(...);
<methods>;
}
Anything else I should be doing? Thanks a million
The messages explain that some Mobclix classes (like com.mobclix.android.sdk.MobclixContactsCursorEntityIterator) depend on Android runtime classes (like android.content.Entity) that are not present in your input jars or library jars. In general, that could be a sign of serious problems: if that part of the code is ever executed, it will fail with NoClassDefFoundError (even without obfuscation).
It looks like the Entity class has been introduced in Android SDK 7, so I presume that you are building against an older SDK. Again assuming that your code runs fine in spite of this missing class, you can let ProGuard accept the somewhat inconsistent input with
-dontwarn android.content.Entity*
Note that -keep options don't come into play here. ProGuard performs the consistency checks before considering any -keep options.
Also see ProGuard manual > Troubleshooting > Warning: can't find referenced class
Maybe change
-keep public class com.mobclix.android.sdk.*
to
-keep public class com.mobclix.android.sdk.**

Categories

Resources