CrossWalk with ProGuard - android

I am trying to enable ProGuard on a Cordova/CrossWalk application project.
The project is using a CrossWalk v13 jar rather thank compiling.
I have tried both of the following ProGaurd config options:
https://crosswalk-project.org/documentation/about/faq.html
https://crosswalk-project.org/documentation/embedding_crosswalk.html
I keep getting an 'occasional' startup crash with the following:
Mostly on first launches.
Any suggestions ?
Thanks!

I've added the following to my crosswalk and have not been having issues.
# XWalk
-keep class org.xwalk.core.** { *; }
-keep class org.crosswalk.engine.** { *; }
-keep class org.chromium.** { *; }
-keepattributes **
-dontwarn android.view.**
-dontwarn android.media.**
-dontwarn org.chromium.**
I'm including crosswalk not as a jar but as a gradle dependency by first adding the repo in the repository block:
maven { url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2' }
And then adding the dependency
compile 'org.xwalk:xwalk_core_library_beta:18.48.477.2'

Related

Proguard (R8) negate operator not working to keep anything except certain packages

The negator (exclamation mark) in proguard should allow me to keep anthing but the apache libraries:
-keep class !org.apache.**
According to those answers. That's the way to go:
How to negate classname with Proguard
Enable Proguard for only two packages in large Android application
Android proguard Ignore All Classes except of one
Proguard Android do not obfuscate anything except few classes
Proguard: How to keep everything except specific condition?
Can we shrink all classes but only obfuscate some with proguard?
However, it obfuscates all classes in my APK.
That's part of my build.gradle (I have Android Studio 3.5.3)
compileSdkVersion 29
buildToolsVersion "29.0.2"
//...
buildTypes {
release {
minifyEnabled true
proguardFiles /*getDefaultProguardFile('proguard-android.txt'),*/ 'proguard-rules.pro'
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources false
}
}
dependencies {
//Utility libs
implementation 'org.apache.commons:commons-collections4:4.1'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation group: 'commons-io', name: 'commons-io', version: '2.5'
}
After I added -printconfiguration to my proguard-rules.pro file I saw there are numerous -keep rules following my -keep class !org.apache.**
-printconfiguration
-keep class !org.apache.**
# Referenced at ***anonymized***\app\build\intermediates\merged_manifests\release\AndroidManifest.xml:180
-keep class android.support.v4.app.CoreComponentFactory { <init>(); }
# Referenced at ***anonymized***\app\build\intermediates\merged_manifests\release\AndroidManifest.xml:180
-keep class com.mycompany.MyApplication { <init>(); }
# Referenced at C:\Users\***anonymized***\.gradle\caches\transforms-2\files-2.1\7f5f0b3369d8fa8a72a20e2278ec0acc\appcompat-v7-28.0.0\res\layout\abc_action_menu_item_layout.xml:17
-keep class android.support.v7.view.menu.ActionMenuItemView { <init>(...); }
That approach suggested by Ezekiel Baniaga also didn't work. Instead it keeps everything including the apache packages:
proguard-rules.pro
-printconfiguration
-dontshrink
-dontoptimize
-dontobfuscate
-keep,allowshrinking,allowoptimization,allowobfuscation class org.apache.**
I had to add ,** to get it working. Thanks T. Neidhart!
-keep class !org.apache.**,**
The previous example preserved class names but still obfuscated members. So I had to add { *; }:
-keep class !org.apache.**,** { *; }
That's how I obfuscate multiple packages (I have to use them all in one keep rule!)
-keep class !org.apache.**, !org.zeroturnaround.**, !com.drew.**, ** { *; }
To find out what my problem is with -dontshrink -dontoptimize -dontobfuscate -keep,allowshrinking,allowoptimization,allowobfuscation class org.apache.** I could add -whyareyoukeeping according to https://www.guardsquare.com/en/products/proguard/manual/usage
You should file a bug report with the R8 project if this does not work anymore.
In order to keep using Proguard in the meantime, you can add this to your gradle.properties files:
android.enableR8=false
Further tests show that the implicit behavior of ProGuard is not implemented like that in R8.
So a rule like:
-keep class !org.apache.**
will implicitly keep all other classes when using ProGuard, but not when using R8. To achieve the same behavior with R8, change the rule to this:
-keep class !org.apache.**,**

Android Data Binding do not work after proguard

Link to project - File manager
After i'm enabling obfuscation, application crash, when i try to show fragment from library project that use data binding.
Error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcorp/wmsoft/android/lib/filemanager/databinding/WmFmFileManagerViewLayoutBinding;
at corp.wmsoft.android.lib.filemanager.ui.widgets.nav.a.onCreateView(Unknown Source)
But Android Studio->Build->Analyze APK, show that i have this class inside APK:
library project proguard-rules.pro:
-dontwarn android.databinding.**
-keep class android.databinding.** { *; }
-keep class corp.wmsoft.android.lib.filemanager.databinding.** { *; }
Please help to solve this problem.

In Android Retrofit2 SimpleXml converter not working with minifyEnabled=true

I'm using following dependencies of retofit2 for xml and gson parsing.
compile 'com.squareup.retrofit2:converter-simplexml:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
All is working fine and data parsing is correctly in debug and released apk. But when I release apk by using minifyEnabled=true and shrinkResources=true ,then xml parsing is not working any more. Gson was also causing problem and was resolved by applying SerializedName annotation to each attribute of Model because proguard renames attributes while generating apk which causes parsing issue.
How can i resolve the xml parsing issue as well? I want to use minifyEnabled necessarily.
Following commands are from Progurad Rules File.
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
-dontwarn org.codehaus.mojo.animal_sniffer.**
-dontwarn java.nio.file.**
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-dontwarn javax.xml.stream.**
# SimpleXMLParsing
-keep public class org.simpleframework.** { *; }
-keep class org.simpleframework.xml.** { *; }
-keep class org.simpleframework.xml.core.** { *; }
-keep class org.simpleframework.xml.util.** { *; }
-keepattributes ElementList, Root
-keepclassmembers class * {
#org.simpleframework.xml.* *;
}
-dontwarn jp.co.cyberagent.android.gpuimage.**

Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called” in Android Studio

Seen at least 2 similar questions, but both considering eclipse non gradle builds.
I'm trying to assemble release with gradle using:
./gradlew myapp:assembleRelease --stacktrace
Besides newest Google proguard example my proguard.txt contains:
# ButterKnife
-keep class *$$ViewInjector{}
-dontwarn butterknife.Views$InjectViewProcessor
-dontwarn butterknife.internal.**
#JodaTime
-dontwarn org.joda.time.**
#Apache
-dontnote org.apache.**
-dontwarn org.apache.**
This seemed to remove all the warnings but now struggling with mysterious
Caused by: java.lang.UnsupportedOperationException: Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called
...and I have no clue what it means.
I had the same issue and never discovered the root of the issue. I did find that if you add a rule to skip optimization in your proguard file it stops the build error from happening.
-dontoptimize
Here is a correct proguard config for those 3 libraries:
# ButterKnife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { #butterknife.InjectView *;}
#JodaTime
-dontwarn org.joda.time.**
#Apache
-keep public class org.apache.commons.io.**
-keep class org.apache.** { *; }
-dontnote org.apache.**
-dontwarn org.apache.**
Not sure if it was a gradle update, but that doesn't happen anymore
-dontoptimize specifies not to optimize the input class files, I am
not sure if it is a good idea to disable optimization, better will be
to enable or disable individual optimizations.
In your case you can use -optimizations optimization_filter
-optimizations !class/merging/vertical*,!class/merging/horizontal*
Proguard will perform all optimizations, except the ones that merges classes vertically and merges classes horizontally.
more info here

How to make Proguard ignore external libraries?

I want to use Proguard mainly for obfuscation reasons.
My problem is that I have three libraries, Twitter4J and two signpost libraries. These libraries caused errors when I tried to create an signed APK. To get over this I put the following in the proguard.config file...
-dontwarn org.apache.commons.codec.binary.**
-dontwarn org.slf4j.**
-dontwarn com.sun.syndication.io.**
-dontwarn com.sun.syndication.feed.synd.*
While this got rid of the errors in the console, when i loaded my signed APK onto my mobile phone it instantly crashed. The DDMS said this was due to a class not found in Twitter4J.
Getting rid of the "dontwarns" above did not help. Neither did adding dontshrink dontoptimise.
I would like Proguard to completely ignore the libraries (as they are open source anyway). Is this possible?
Try this:
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
Cf post from #CaspNZ:
Android Proguard with external jar
You should be able to add to the proguard.cfg the following lines to exclude all classes within a package (and subpackages)
-keep class org.apache.commons.codec.binary.**
-keep interface org.apache.commons.codec.binary.**
-keep enum org.apache.commons.codec.binary.**
-keep class org.slf4j.**
-keep interface org.slf4j.**
-keep enum org.slf4j.**
-keep class com.sun.syndication.io.**
-keep interface com.sun.syndication.io.**
-keep enum com.sun.syndication.io.**
-keep class com.sun.syndication.feed.synd.**
-keep interface com.sun.syndication.feed.synd.**
-keep enum com.sun.syndication.feed.synd.**
I'd like to add that you should sync your project with Gradle files after adding proguard rules, otherwise they may not work.

Categories

Resources