Bazel build Android demo fail with Proguard - android

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.

Related

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.

Android FirebasePerformance issue with Proguard

We implemented FirebasePerformance in our project and when are unable to build the project. I get below error in Proguard which has something to do with having a two classes with same name but different cases (A.class and a.class) in the external library (qrchart_obfuscation.jar). I am not very familiar with proguard also.
Reading thru sources, I am looking to add -dontwarn option in proguard but this will be my last resort since sources says to "use it only when you know what you are doing".
I still tried to add -dontwarn qr.android.chart and I compared Mapping.txt with my previous builds which does not have FirebasePerformance and I see a difference on the class (qr.android.chart) not sure if this detail helps
Appreciate your help and suggestions with proguard setup for FirebasePerformance.
Reading program directory [C:\...\build\intermediates\transforms\FirebasePerformancePlugin\adevelop\release\4] (filtered)
Warning: class [qr/android/chart/b/a.class] unexpectedly contains class [qr.android.chart.b.A]
Warning: class [qr/android/chart/b/b.class] unexpectedly contains class [qr.android.chart.b.B]
Warning: class [qr/android/chart/b/c.class] unexpectedly contains class [qr.android.chart.b.C]
Warning: class [qr/android/chart/b/d.class] unexpectedly contains class [qr.android.chart.b.D]
Warning: class [qr/android/chart/b/e.class] unexpectedly contains class [qr.android.chart.b.E]
Warning: class [qr/android/chart/b/f.class] unexpectedly contains class [qr.android.chart.b.F]
Warning: class [qr/android/chart/b/g.class] unexpectedly contains class [qr.android.chart.b.G]
Warning: class [qr/android/chart/b/h.class] unexpectedly contains class [qr.android.chart.b.H]
Warning: class [qr/android/chart/b/i.class] unexpectedly contains class [qr.android.chart.b.I]
Warning: class [qr/android/chart/b/j.class] unexpectedly contains class [qr.android.chart.b.J]
Warning: class [qr/android/chart/b/k.class] unexpectedly contains class [qr.android.chart.b.K]
Warning: there were 11 classes in incorrectly named files.
You should make sure all file names correspond to their class names.
The directory hierarchies must correspond to the package hierarchies.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass)
If you don't mind the mentioned classes not being written out,
you could try your luck using the '-ignorewarnings' option.
I saw this link with regards to Firebase performance and proguard issue during build of signed APK but different case -FirebasePerformance SDK external library issue in progaurd
The problem is the qr.android.chart library isn't using the dontusemixedcaseclassnames option when proguarding.
When building on a case insensitive file system (i.e., that Mac OSX likes to use), the byte code instrumentation process Firebase Performance uses runs into issues because the unarchived classes end up overwriting each other.
Your options are to either disable byte code instrumentation or ask for a new qr.android.chart library with the dontusemixedcaseclassnames option activated.
If you are working on macOS, I've found an ugly workaround for this. Create a case sensitive disk image and copy the project there, so firebase perf plugin can handle the case sensitive files.
How to create the disk image here: https://documentation.spryker.com/tutorials/howtos/ht-case-sensitive-file-system-mac.htm
For my project I needed a 5gb image.

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

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