Proguard - can't find referenced method - android

I have to upgrade my build tool to com.android.tools.build:gradle:3.1.3 with gradle 4.4. My project worked well with proguard previously. But after upgrading, there are a lot of issues as the one below:
MainActivity: can't find referenced method 'void setAlpha(float)' in program class android.view.View
...can't find referenced method 'void execute(java.lang.Runnable)' in program class android.os.AsyncTask
...can't find referenced method 'void overridePendingTransition(int,int)'
...can't find referenced method 'boolean canPause()' in program class android.widget.VideoView
Warning: library class android.app.AlarmManager$AlarmClockInfo depends on program class android.os.Parcelable$Creator
Warning: library class android.graphics.drawable.AdaptiveIconDrawable extends or implements program class android.graphics.drawable.Drawable
What did I miss in my proguard file?
After taking a lot of time looking at the log cat, I saw that every referenced method was Added in API level 11 or above (I am using if/else check) and my min sdk was 15. Any suggestion?

Proguard version is updated with the buildtools, maybe this is an issue with that Proguard version. Have you tried to downgrade (or updgrade) manually your Proguard version to see if the error still occurs ?
override it like this
buildscript {
configurations.all {
resolutionStrategy {
force 'net.sf.proguard:proguard-gradle:x.x.x' //here use whatever version you'd like
}
}
}
and look up your proguard version like this
./gradlew buildEnvironment

Related

Bazel build Android demo fail with Proguard

Can't build an Android demo with Bazel when proguard_specs is enable.
Error log:
...
Warning: kotlinx.coroutines.flow.internal.ChannelFlowMerge$collectTo$$inlined$collect$1$lambda$1: can't find enclosing method 'java.lang.Object emit$$forInline(java.lang.Object,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.ChannelFlowMerge$collectTo$$inlined$collect$1
Warning: kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$$inlined$collect$1$1: can't find enclosing method 'java.lang.Object emit$$forInline(java.lang.Object,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$$inlined$collect$1
Warning: kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$$inlined$collect$1$lambda$1: can't find enclosing method 'java.lang.Object emit$$forInline(java.lang.Object,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$$inlined$collect$1
Warning: kotlinx.coroutines.flow.internal.CombineKt$zipImpl$$inlined$unsafeFlow$1$lambda$1: can't find enclosing method 'java.lang.Object collect$$forInline(kotlinx.coroutines.flow.FlowCollector,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.CombineKt$zipImpl$$inlined$unsafeFlow$1
Warning: kotlinx.coroutines.flow.internal.FlowCoroutineKt$scopedFlow$$inlined$unsafeFlow$1$lambda$1: can't find enclosing method 'java.lang.Object collect$$forInline(kotlinx.coroutines.flow.FlowCollector,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.FlowCoroutineKt$scopedFlow$$inlined$unsafeFlow$1
Warning: there were 2 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)
Warning: there were 51 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Error: Please correct the above warnings first.
ProGuard, version 5.3.3
...
Note: kotlinx.coroutines.CommonPool accesses a method 'getPoolSize()' dynamically
Maybe this is library method 'java.util.concurrent.ForkJoinPool { int getPoolSize(); }'
Maybe this is library method 'java.util.concurrent.ThreadPoolExecutor { int getPoolSize(); }'
Note: there were 5 classes trying to access annotations using reflection.
You should consider keeping the annotation attributes
(using '-keepattributes *Annotation*').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 4 classes trying to access generic signatures using reflection.
You should consider keeping the signature attributes
(using '-keepattributes Signature').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 2 classes trying to access enclosing methods using reflection.
You should consider keeping the enclosing method attributes
(using '-keepattributes InnerClasses,EnclosingMethod').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 15 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 29 accesses to class members by means of introspection.
You should consider explicitly keeping the mentioned class members
(using '-keep' or '-keepclassmembers').
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Target //app/src/main:app failed to build
INFO: Elapsed time: 3.238s, Critical Path: 3.10s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
Bazel config:
android_binary(
name = "app",
manifest = "AndroidManifest.xml",
custom_package = "felix.duan.androidnavisample",
manifest_values = {
"minSdkVersion": "21",
"versionCode" : "2",
"versionName" : "2.0",
"targetSdkVersion" : "29",
},
proguard_generate_mapping = True,
proguard_specs = ["proguard-rules.pro"],
deps = [
":lib",
]
)
proguard-rules.pro:
-keep class org.jetbrains.annotations.** { *; }
-dontwarn org.jetbrains.annotations.**
Build tools:
bazel: v3.7.0-homebrew
rules_kotlin_version: legacy-1.4.0-rc4
android sdk: v30.0.2
Question A: How to solve this problem?
addition questions I found related to this:
Question B: Does Bazel consume transitive dependency proguard? If not, this could be the cause?
Question C: Does Bazel support R8? I found no direct info to this.
Since it's only a warning, maybe you can disable it in the proguard config:
-dontwarn kotlinx.coroutines.**
And then error which is Error: Please correct the above warnings first. might go away.

Glide 4.11.0 ProGuard QMediaStoreUriLoader$QMediaStoreUriFetcher Error

When I try to sign the apk, I get these two error messages:
com.bumptech.glide.load.model.stream.QMediaStoreUriLoader$QMediaStoreUriFetcher: can't find referenced method 'boolean isExternalStorageLegacy()' in library class android.os.Environment
com.bumptech.glide.load.model.stream.QMediaStoreUriLoader$QMediaStoreUriFetcher: can't find referenced method 'android.net.Uri setRequireOriginal(android.net.Uri)' in library class android.provider.MediaStore
I went through these two issues, but they are different error messages
Proguard error after adding Glide v4
https://github.com/bumptech/glide/issues/2807

Warning: can't find referenced method 'int save(int)' in library class android.graphics.Canvas

I'm using a no-longer maintained Umano's AndroidSlidingUpPanel library in one of my applications:
dependencies {
// .. redacted
implementation 'com.sothree.slidinguppanel:library:3.4.0'
}
Everything worked fine till now. Today I've tried to change the compileSdkVersion from 27 to 28, and the release build started to fail with a Proguard error (minifyEnabled set to true):
$ ./gradlew clean assembleRelease
> Task :app:transformClassesAndResourcesWithProguardForRelease FAILED
ProGuard, version 6.0.3
Reading input...
// many lines with 'Reading program jar...', redacted
Initializing...
Warning: com.sothree.slidinguppanel.SlidingUpPanelLayout: can't find referenced method 'int save(int)' in library class android.graphics.Canvas
// redacted
Warning: there were 1 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
BUILD FAILED in 2s
I'm using AGP v3.5.0, with android.enableR8=false configuration to favor Proguard over R8.
One of the comments in this issue suggests to ignore the warning using -dontwarn com.sothree.**, which indeed causes the build to pass.
Why this warning started to appear in the first place, and are there any possible ramifications for ignoring it?
Let's analyze the warning message:
Warning: com.sothree.slidinguppanel.SlidingUpPanelLayout: can't find
referenced method 'int save(int)' in library class
android.graphics.Canvas
Library's SlidingUpPanelLayout.java source file indeed includes a android.graphics.Canvas#save(int) method invocation:
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
This method is deprecated since API 26, and was marked as #removed in API 28.
The #removed annotation (along with #hide annotation) is being used by doclava tool (AOSP tool which generates public framework API stub, a.k.a. android.jar) to mark public class methods as hidden.
To summarize: the android.graphics.Canvas#save(int) method was removed from the public API, but it is still part of the runtime/framework (see also this). During minification stage Proguard analyzes the bytecode and obviously fails to find the not-anymore-public-api android.graphics.Canvas#save(int) method and displays the above warning.
This method is still present in runtime, therefore Proguard warning can be ignored given two caveats:
Since this method is not part of public API anymore, a particular vendor might alter the framework classes (i.e., by renaming/removing this method) in a way which will cause runtime errors.
This method might be removed in future AOSP version, and you probably won't notice that till this method will be called on affected device.
The warning ignore rule can be narrowed to:
-dontwarn com.sothree.slidinguppanel.SlidingUpPanelLayout
In a long run, I'd suggest to consider patching this library by yourself (by changing the functionality to use the parameterless android.graphics.Canvas#save() method), or if that's not possible - migrate to another solution.

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)

ant release proguard fails, but under eclipse works

I have a pretty big project with an elaborate proguard.cfg .
This project builds OK under eclipse, proguard runs without errors, and the app works perfectly, it's been my normal workflow for months.
I am trying to build it from command line using ant.
I have updated build.xml, etc.. on the projects and its library project using
android update project -p .
android update project -s --target android-17 -p .
The debug version, ant debug, gets built successfully
However, ant release fails proguard, complaining about missing classes.
From what I could decipher (a lot of non-faltal warnings pop up) the problems are related to a missing inner class in one of my (thousand) classes, and to missing R (resources) of a dependent library project. This is strange, both things do exist, the library projects gets built OK from eclipse & ant, and that inner class i don't know, the parent class is pretty trivial.
Why does it build under eclipse and not using command line? Shouldn't the updated build scripts produce the same result?
Proguard: Errors Related to LIbrary Project Resources
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.CustomViewBehind: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R$id
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.CustomViewBehind: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R$id
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.CustomViewBehind: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.SlidingMenu: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R$styleable
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.SlidingMenu: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R$styleable
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.SlidingMenu: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivityHelper: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R$layout
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivityHelper: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R$layout
[proguard] Warning: com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivityHelper: can't find referenced class com.jeremyfeinstein.slidingmenu.lib.R
Proguard: Related to inner class not found
[proguard] Warning: com.regaliz.gui.layouts.FunqRootLayout$2: can't find referenced class com.regaliz.gui.layouts.FunqRootLayout$1
[proguard] Warning: com.regaliz.gui.layouts.FunqRootLayout$3: can't find referenced class com.regaliz.gui.layouts.FunqRootLayout$1
[proguard] Warning: com.regaliz.gui.layouts.FunqRootLayout$SimpleAnimationListener: can't find referenced class com.regaliz.gui.layouts.FunqRootLayout$1
[proguard] Warning: com.regaliz.gui.layouts.FunqRootLayout$SimpleAnimationListener: can't find referenced class com.regaliz.gui.layouts.FunqRootLayout$1
[proguard] Warning: com.regaliz.gui.layouts.FunqRootLayout$SimpleAnimationListener: can't find referenced class com.regaliz.gui.layouts.FunqRootLayout$1
That's strange, I found the problem by trial and error.
The inner class not found was an innocent private anonymous runnable like:
private Runnable mBlinkRunner=new Runnable() {
public void run() {
.
. couple simple lines
.
}
};
I changed it to ...
protected Runnable mBlinkRunner=new Runnable() {
public void run() {
.
. couple simple lines
.
}
};
and it worked... I wonder why this happens, there should be like hundreds of runnables like these through the project.

Categories

Resources