我将使用混淆器混淆我的源代码。
我的源代码定义了一些硬编码字符串,我不知道如何防止混淆器混淆我的字符串值(在下面的示例中是“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
我认为问题出在 String 上,因为当我保留处理数据库的类时,我的应用程序就不会再崩溃了!!
============================================= =====
更新 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
关于android - 不要混淆混淆器中的硬编码字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721724/