混淆(Proguard)+ RenderScript 支持库错误

3
我有一个项目正在使用新的 RenderScript支持库,同时也在使用Proguard进行混淆。
当使用普通的RenderScript SDK(android.renderscript.*)时,Proguard在代码上运行良好。而且,在编译非发布版本的情况下,使用RenderScript支持库的代码也可以正常工作。
但是,将这两者结合起来的结果是这样的:
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'.

我对ProGuard的了解仅限于“知道一点点就够危险了”。 我学到的一件事是,警告/错误消息中的建议通常不一定指向实际问题的原因。 这次也不例外:按照警告中的建议进行更改并没有改变输出结果。
RenderScript支持库能否与ProGuard一起使用? 如果可以,是否需要在我的ProGuard配置中添加某些特殊设置才能使其正常工作?
3个回答

3

-dontwarn android.support.v8.**

实际上我昨天也遇到了这个问题...

有趣 - 那是因为使用了隐藏的API吗? - Scott W
不,这里发生的是这两个API被隐藏在适当的API级别检查后面以运行它们(但它们不存在于早期的目标版本中,因此需要支持库)。我们也可以通过反射间接地访问这些方法,但我们还没有做过类似的事情。 - Stephen Hines

2
最初的回答:
对于androidX,使用以下代码进行保留:
-keep class androidx.renderscript.** { *; }

0

结合前两个答案,在任何使用Renderscript的现代应用程序中,您都应该将以下内容添加到您的proguard-rules.pro文件中。

# Render Script
-keep class android.support.v8.renderscript.** { *; }
-keep class androidx.renderscript.** { *; }

这将同时处理使用Android支持库或Android X的应用程序


我遇到了这个问题描述中的崩溃。我进行了谷歌搜索,并找到了这个答案,然后通过结合之前两个答案,其中一个是使用支持库,另一个是使用AndroidX。如果您添加这两行代码,您可以在所有项目中支持渲染脚本,无论它们使用哪些库。 - Lucas P.
还有android.renderscript(没有x) - SerialSensor

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接