Proguard configuration for Android Support v4 22.2.0 - java

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.**

Related

How to use protobuf with proguard

After adding protobuf dependency to a project that is using proguard for releases I run into the following issues:
Warning: ***.***.Api: can't find referenced method 'com.google.protobuf.Descriptors$FileDescriptor getDescriptor()' in library class com.google.protobuf.AnyProto
Warning: ***.***.Api$Information: can't find referenced method 'com.google.protobuf.Any$Builder toBuilder()' in library class com.google.protobuf.Any
Warning: ***.***.Api$Information: can't find referenced method 'com.google.protobuf.Any$Builder mergeFrom(com.google.protobuf.Any)' in library class com.google.protobuf.Any$Builder
Warning: ***.***.Api$Information: can't find referenced method 'com.google.protobuf.Any buildPartial()' in library class com.google.protobuf.Any$Builder
Warning: ***.***.Api$Information$Builder: can't find referenced method 'com.google.protobuf.Any build()' in library class com.google.protobuf.Any$Builder
Warning: ***.***.Api$Information$Builder: can't find referenced method 'com.google.protobuf.Any$Builder mergeFrom(com.google.protobuf.Any)' in library class com.google.protobuf.Any$Builder
Warning: ***.***.Api$Information$Builder: can't find referenced method 'com.google.protobuf.Any buildPartial()' in library class com.google.protobuf.Any$Builder
Warning: ***.***Service: can't find referenced method 'com.google.protobuf.Any pack(com.google.protobuf.Message)' in library class com.google.protobuf.Any
In my case the problem was that another dependency already had a transitive dependency on protobuf-javalite and it conflicted with the protobuf-java I was adding.
As per https://github.com/protocolbuffers/protobuf/issues/8104#issuecomment-887076083:
protobuf-java and protobuf-javalite should
never be included in the same project [...] if you're using Gradle, we
recommend an approach like this:
https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html#sec:excluding-transitive-deps
Telling the system to exclude protobuf-javalite because you explicitly
depend on protobuf-java is technically OK, but this might have
negative side effects to performance or code size on mobile platforms,
it also might be totally fine for you, your mileage may vary.
The problem was solved for me after excluding protobuf-javalite like this
configurations {
all*.exclude group: 'com.google.protobuf', module: 'protobuf-javalite'
}

Can't find referenced method 'java.lang.Object injectMembers(dagger.MembersInjector,java.lang.Object)

Recently I upgrade Dagger 2.13 to 2.19, I have the below compile error at Proguard stage of this warning.
Warning: com.mypackage.MyClass_Factory: can't find referenced method 'java.lang.Object injectMembers(dagger.MembersInjector,java.lang.Object)' in program class dagger.internal.MembersInjectors
This also happens from Dagger 2.14.1 onwards. This happens only to MyClass which is in a library I include.
If I use
-dontwarn com.mypackage.MyClass_Factory
Then it will crash on runtime
java.lang.NoSuchMethodError: No static method injectMembers(Ldagger/MembersInjector;Ljava/lang/Object;)Ljava/lang/Object; in class Ldagger/internal/MembersInjectors; or its super classes (declaration of 'dagger.internal.MembersInjectors' appears in MyClass
Which means the warning from Proguard is a legit warning I should take care.
I search and found the issue is reported in https://github.com/google/dagger/pull/950#issuecomment-353223029
The solution by #ronshapiro is
You should shade the dagger.internal from one (or both) of the libraries. The old one is probably easiest
What does shade the dagger.internal means? How to solve my problem?

Android Facebook SDK Eclipse Proguard

I've installed the Facebook SDK and has no errors but I can't seem to export it as part of my android project. I get the below error when enabling ProGuard:
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.Task$TaskCompletionSource
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.AppLink$Target
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.AppLink
Warning: com.facebook.applinks.FacebookAppLinkResolver$2: can't find referenced class bolts.AppLink$Target
Warning: com.facebook.messenger.MessengerUtils: can't find referenced class bolts.AppLinks
Warning: com.facebook.messenger.MessengerUtils: can't find referenced class bolts.AppLinks
You should check if you need to specify additional program jars.
Warning: there were 62 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
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)
at proguard.ProGuard.main(ProGuard.java:492)
I added the below to my ProGuard file but I still get the error:
-keep class com.facebook.** {
*;
}
How should I configure ProGuard to use the Facebook SDK?
I am using these settings in my proguard-project.txt:
# Facebook Audience Network
-keep class com.facebook.ads.** { *; }
-keep class com.facebook.ads.internal.** { *; }
-keep class com.google.ads.mediation.facebook.FacebookAdapter {*;}
-keep class com.google.android.exoplayer.** {*;}
-dontwarn com.facebook.ads.**
-dontwarn com.google.android.exoplayer.**
ProGuard is telling you that the Facebook SDK references classes in the bolts package but ProGuard can't find those classes because, most likely, you're not including Bolts in your application.
To fix this, you can either:
Tell ProGuard to ignore the missing dependency by adding the line
-dontwarn bolts.**
to the ProGuard configuration file. Doing this shouldn't cause a problem because the Facebook SDK can detect internally whether Bolts is present and only try to use it in that case.
Add Bolts as a dependency of your project by putting these lines in your Gradle file:
dependencies {
compile 'com.parse.bolts:bolts-tasks:1.4.0'
compile 'com.parse.bolts:bolts-applinks:1.4.0'
}
Option 1 is probably the best choice unless you actually need Bolts.

Not able to generate signed .apk due to including proguard

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.

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.

Categories