android-不要在proguard中混淆硬编码的字符串
作者:互联网
我将使用proguard混淆源代码.
我的源代码定义了一些硬编码字符串,但我不知道如何防止proguard混淆我的String值(在下面的示例中为“ tbl_people”)
类
public class MyDaoObject {
public static final String TABLENAME = "tbl_people";
//other database code
}
如果字符串混淆,SQLite将无法使用该字符串创建表.
有很多像这样的硬编码字符串.如何配置proguard来做到这一点?
任何建议都欢迎.
================================================== ==
更新:
这是logcat:
07-13 17:55:12.310: E/AndroidRuntime(11148): FATAL EXCEPTION: main
07-13 17:55:12.310: E/AndroidRuntime(11148): Process: com.myapp, PID: 11148
07-13 17:55:12.310: E/AndroidRuntime(11148): java.lang.RuntimeException: Unable to create application com.myapp.AudioPhotoApplication: a.a.a.d: Could not init DAOConfig
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4470)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.app.ActivityThread.access$1500(ActivityThread.java:144)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.os.Handler.dispatchMessage(Handler.java:102)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.os.Looper.loop(Looper.java:136)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.app.ActivityThread.main(ActivityThread.java:5140)
07-13 17:55:12.310: E/AndroidRuntime(11148): at java.lang.reflect.Method.invokeNative(Native Method)
07-13 17:55:12.310: E/AndroidRuntime(11148): at java.lang.reflect.Method.invoke(Method.java:515)
07-13 17:55:12.310: E/AndroidRuntime(11148): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-13 17:55:12.310: E/AndroidRuntime(11148): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
07-13 17:55:12.310: E/AndroidRuntime(11148): at dalvik.system.NativeStart.main(Native Method)
07-13 17:55:12.310: E/AndroidRuntime(11148): Caused by: a.a.a.d: Could not init DAOConfig
07-13 17:55:12.310: E/AndroidRuntime(11148): at a.a.a.b.a.<init>(Unknown Source)
07-13 17:55:12.310: E/AndroidRuntime(11148): at a.a.a.b.a(Unknown Source)
07-13 17:55:12.310: E/AndroidRuntime(11148): at com.myapp.database.a.<init>(Unknown Source)
07-13 17:55:12.310: E/AndroidRuntime(11148): at com.myapp.AudioPhotoApplication.onCreate(Unknown Source)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
07-13 17:55:12.310: E/AndroidRuntime(11148): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4467)
07-13 17:55:12.310: E/AndroidRuntime(11148): ... 10 more
07-13 17:55:12.310: E/AndroidRuntime(11148): Caused by: java.lang.NoSuchFieldException: TABLENAME
07-13 17:55:12.310: E/AndroidRuntime(11148): at java.lang.Class.getField(Class.java:724)
07-13 17:55:12.310: E/AndroidRuntime(11148): ... 16 more
我认为问题来自字符串,因为当我保留处理数据库的类时,我的应用程序不再崩溃!
================================================== ==
更新2:
问题不是来自字符串值,而是字符串名称.这是我的问题:
https://groups.google.com/forum/#!msg/greendao/tyqjrx2otVo/PHExbn4iZk8J
解决方法:
您确定这是问题所在,因为ProGuard不会混淆其常见问题解答中所述的字符串:
No. String encryption in program code has to be perfectly reversible by definition, so it only improves the obfuscation level. It increases the footprint of the code. However, by popular demand, ProGuard’s closed-source sibling for Android, DexGuard, does provide string encryption, along with more protection techniques against static and dynamic analysis
proguard的作者回答了类似的问题(但那家伙希望对字符串进行混淆):
https://stackoverflow.com/a/12665420/1643188
标签:greendao,proguard,string,android 来源: https://codeday.me/bug/20191121/2052294.html