Proguard + RenderScript support library error - android

I have a project that is using the new RenderScript support library and is also using proguard for obfuscation.
Proguard was working great on the code when using the normal RenderScript SDK (android.renderscript.*). And the code is working great with the RenderScript support library when compiled in a non-release build where proguard does not run.
But, bring the two together and the result is this:
Warning: android.support.v8.renderscript.RenderScript: can't find referenced class android.os.SystemProperties
Warning: android.support.v8.renderscript.RenderScript: can't find referenced class android.os.SystemProperties
Warning: android.support.v8.renderscript.RenderScriptThunker: can't find referenced method 'android.renderscript.RenderScript create(android.content.Context,int)' in class android.renderscript.RenderScript
You should check if you need to specify additional program jars.
Warning: there were 2 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Warning: there were 1 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'.
I know just enough about proguard to be dangerous. One thing I have learned is that the suggestions in the warning/error messages tend not to necessarily point at the actual cause of the issue. This time is no different: implementing the suggested changes in the warnings results in no change of the output.
Can the RenderScript support library be used with proguard? And if so, is there some magic that I need to add to my proguard config to make it work?

-dontwarn android.support.v8.**
actually encountered this yesterday...

For androidX
-keep class androidx.renderscript.** { *; }

Combining the previous two ansers, in any modern app that uses Renderscript, you should add the follwing to your proguard-rules.pro file.
# Render Script
-keep class android.support.v8.renderscript.** { *; }
-keep class androidx.renderscript.** { *; }
This will take care of both apps that use the Android support library, or Android X

Related

How to find out which classes cannot be resolved by ProGuard Android

After adding ProGuard rules for all libraries I am using, I still get this warning:
Warning: there were 14 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)
I know that I can probably use the -dontwarn option to get rid of this warning, but therefore I need to know which packages/classes/interfaces cannot be resolved. Android does not support a global "-dontwarn".
In the log file I find so many Notes and Warnings, but none of them seem to relate the above message.
If you receive a Warning: there were X unresolved references to classes or interfaces then look for lines in your build log that contain the word Warning, such as this:
Warning: com.package.Class1: can't find referenced class org.library.Class2
Lines like this will tell which classes ProGuard is trying to work on and which classes can't be found in the input jars. In the example above, class Class1 would reference Class2 of a library but Class2 was not found in the build path.
As you mentioned, you can simply add -dontwarn <class regex> to ignore those warnings but ideally you should check them one-by-one to make sure that your configuration is correct and all required dependencies are being imported correctly.

Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU

I started getting the message with the latest Android Build Tools (ABT) v19.0.3 today. At first glance, I thought this might be an issue with ABT. However, a closer investigation reveals that this message:
android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
is only shown when Proguard is used. Answers on the net has yeilded no solution for me. Perhaps, this is only an issue with Proguard (the version I'm using is bundled with Android SDK v22.3).
I have added the following directives to proguard-project.txt file, but it makes no difference:
-keep interface android.support.v4.** { *; }
-keep class android.support.v4.** { *; }
Does anyone else come across this message and has a possible solution? Maybe Eric from Proguard might be able to shed some light into this issue. Maybe a code cleanup is required with Proguard? I'm interested to know the solution.
The note says that a support class is using reflection to access a runtime class that isn't present in the target runtime. In general, it could be a sign of compatibility problems. In this case, it's harmless; the developers of the support library are precisely using reflection to avoid any linking problems with different runtime environments. You can suppress the note with:
-dontnote android.support.**

socialauth-android: proguard errors when exporting apk

Using socialauth-android, when I try to export my project I get these warnings:
Warning: org.brickred.socialauth.util.SocialAuthUtil: can't find referenced class javax.servlet.http.HttpServletRequest
Warning: there were 111 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.
Warning: there were 140 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code or update the library versions.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:330)
at proguard.ProGuard.initialize(ProGuard.java:212)
at proguard.ProGuard.execute(ProGuard.java:87)
at proguard.ProGuard.main(ProGuard.java:484)
Could someone help?
Problem is gone using this proguard cfg:
-keep class org.brickred.** { *; } -dontwarn org.brickred.**
Do you have the jars directly in your libs? Or are you getting them through maven? Which sdk version are you running?
If you add jars in at compile time, it might not get included in proguard processing. The jars has to be in place after pre-build target is ran.

Android proguard and library projects

the proguard is killing me with messages like that one:
"[proguard] Warning: class [facebook/bin/classes/com/facebook/internal/FileLruCache$StreamHeader.class] unexpectedly contains class [com.facebook.internal.FileLruCache$StreamHeader]"
and the final warning is:
[proguard] Warning: there were 332 classes in incorrectly named files.
[proguard] You should make sure all file names correspond to
their class names. [proguard] The directory hierarchies must
correspond to the package hierarchies. [proguard] If you
don't mind the mentioned classes not being written out, [proguard]
you could try your luck using the '-ignorewarnings' option.
Seems to me I haven't adjusted the library projects that I am using (like facebook) with the proguard.
I don't really want to obfuscate the lib projects, but the lines
-keep class com.facebook.** { *; }
-keep interface com.facebook.** { *; }
does not to do the trick.
Can you enlighten me on that one?
Thanks
Cfr. ProGuard manual > Troubleshooting > Warning: class file ... unexpectedly contains class ...
It seems that your configuration contains a -injars option that doesn't point to the root directory of the packages and classes (.../facebook/bin/classes).
However, the standard Android build process already specifies all necessary -injars options for you, so you shouldn't add any.
Ok, I fixed in with many -dontwarn options in proguard config file.
Also, I don't obfuscate anything that is not in my main package (-keepclass !com.yyy.** { *; } and keepinterface as well). This seems to work nicely.

Problems compiling an Android App with Ant and Proguard

I have an Android App which consists on different modules. The Main module is using some libs like Google's GSON or the v4.support.package. A custom build script with the right proguard.cfg will build it, too.
Now I must integrate another "Android-Library" which uses partly the same libs (GSON support.v4). Beside from getting a lot of Notes like
Note: duplicate definition of program class [com.google.gson.Gson]
I get also some Notes like
[proguard] Note: com.google.gson.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
[proguard] Note: the configuration refers to the unknown class 'sun.misc.Unsafe'
that I find strange cause i have some 'keeps' in my Proguard.cfg especially for that:
-keepattributes Signature, Annotation
-keep class com.google.gson.** {*;}
-keep class sun.misc.Unsafe { *; }
which works well on my project without referencing the module-library inside it.
I'm on the Latest SDK and Tools, and added a custom proguard.cfg to the module-library, which works well on the module-lib itself (if build in standalone-mode).
It seems to me, that the build is not depending on custom proguard.cfg inside library-projects. Any idea on what to try highly appreciated
I finally found a solution for it myself:
with the last Android Tools (16), every Android-Library gets compiled on its own first.
So when the lib has not a "standart" build and defines some custom build script including proguard --keeps, and this --keeps are defined on the same Project (excluding Android SDK classes, as thei're not compiled) it leads to an proguard error.
The Solution was do remove proguard out of the lib and copy the --keeps inside the main App

Categories

Resources