I am trying to use SQLite android bindings to have a custom encrypted SQLite DB in my android app. It all works fine and I am about to publish my app. I am trying to use ProGuard for code obfuscation and compression but does not seem to work fine with SQLite android bindings. My released app crashes on startup because it cannot find few .so files used by SQLite. I am not sure what should be the correct ProGuard rule to keep those libraries.
Right now I have added only this to my ProGuard:
-keep class org.sqlite.**
Usually,
-keep class org.sqlite.** { *; }
-keep class org.sqlite.database.** { *; }
would do the trick.
Verify your mapping.txt for what ProGuard is already done, and make sure that your models are not got renamed. If so, you may need
-keep class com.your.modelspackage.**
-keepclassmembers com.your.modelspackage.** { *; }
Hope it helps
Related
Just wondering what exactly this means.
-keep class !com.my.package.** { *; }
Does it mean not obfuscate anything. Does it defeat the purpose of using proguard?
It will obfuscate your package classes including sub-packages and classes in them.
Why not if the app doesn't use any external library :)
Intro: I have in AS 1 project with 2 models:
Android library project with some "Public API class"
Android APP dependent on above library (the library module is on the dependency list)
Task: I want to obfuscate my library project because I want to expose it as public SDK but keep my code protected...
What I did: So I made custom ProGuard rules:
-dontshrink
-dontoptimize
-dontpreverify
-keep class com.org.my_public_api_class_name
I skip all other stages in order to eliminate where the bug is to only obfuscation stage.
Result: Build of the APP module fails with errors like
Error: cannot find symbol class my_public_api_class_name
It seems for me that the problem is that the obfuscation NOT skipped the class I wanted to, so now he has some meaningless name and therefore in the APP, where I'm using him, The original name not exist.
Thanks,
To exclude your class from obfuscation, try this:
-keep class com.org.my_public_api_class_name**
-keepclassmembers class com.org.my_public_api_class_name** {*;}
I've searched discuss.cocos for an example but there isn't one. Feeling this to be a more OS agnostic platform to ask on I search for enlightenment here.
I got a massive headache after turning it on by writing
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
in project.properties in my project's base directory.
I couldn't copy-past text because the console display in Eclipse immediately cleared and presented like there was nothing wrong but I got "error code 1. See console" type of message, repeatedly.
Though the problem appears to be with twitter4j I'm sure there are many more warnings that scrolled by before that, well, I'm not sure, the whole thing was so sudden.
I've trawled this site for help and while most advice consists of adding dontwarn lines I feel I need to be exporting libraries instead of, as I did with twitter4j, just copying the libjar to my project's own lib folder.
I've tried adding:
-dontwarn twitter4j.management.**
-dontwarn twitter4j.**
-dontwarn javax.management.**
-dontwarn com.google.api.client.googleapis.extensions.android.gms.**
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class twitter4j.** { *; }
-keep class java.lang.management.** { *; }
-keep class com.google.code.** { *; }
-keep class oauth.signpost.** { *; }
-libraryjars /libs/twitter4j-core-3.0.3.jar
-keep class twitter4j.**
-keepclassmembers class twitter4j.** {
<init>(...);
<methods>;
<fields>;
}
To proguard-project.txt but it had no effect. I'm tending not to want to bother with proguard since C++ is much better for obfuscation anyway. It's strange how none of the howto's I read promoted including the entire twitter4j project. I prefer the small 300kb library. But not if it's limiting optimisations in other respects.
My SDK is version 22.6 by the way.
____EDIT____
In looking for a complete example i found SDK/tools/proguard/examples/android.pro
I tried copy pasting the lot to no further effect but was disconcerted by the advice in the header of that file:
If you're using the Android SDK (version 2.3 or higher), the android tool
already creates a file like this in your project, called proguard.cfg.
It should contain the settings of this file, minus the input and output paths
(-injars, -outjars, -libraryjars, -printmapping, and -printseeds).
The generated Ant build file automatically sets these paths.
Android tool? proguard.cfg? Surely proguard knows the new files are merely instructed to reference the configs in the SDK/tools/proguard directory?
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
You say you're changing proguard-project.txt, but are you actually using that file? Have you changed project.properties to point to your file instead of the default android one?
proguard.config=proguard-project.txt
Your project.properties file should point to Android's default configuration and to your own project-specific configuration:
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
This is the standard line in the properties files that the Android SDK generates.
In your proguard-project.txt file, you can then add -keep options to avoid problems with code that performs reflection. In this case, you should also add -dontwarn options to reassure ProGuard that the missing dependencies are not a problem in practice. It will then proceed processing the application.
You should not add -libraryjars options, since the Android build process already automatically specifies all necessary -injars, -outjars, and -libraryjars for you.
My app is able to run without any issues during testing etc. But when I export out apk compiled with ProGuard, there are issues like random crashing and some features not working as expected.
I not sure is it due to the external jar libraries I have included in the project which is not properly configured in Proguard.
I have included the following in the proguard-android.txt file. I have two libraries so I added these:
-keep class org.apache.commons.net.** { *; }
-keep class org.jsoup.** { *; }
Is it the correct way? Is there any other way?
To add libraries just add -libraryjars ../libs/<libname>
After that you may need to keep classes and interfaces based on the errors you receive
I'm not using new relic in my app and it still shows class not found error.
Only solution that worked for me is to include new relic. I'm using eclipse.
App works in debug, now I want to use proguard and I'm new to it.
What do I need to write in proguard-project.txt to include newrelic in proguard.
Thanks!
After some testing and researching, to launch an Android app with NewRelic and have ProGuard enabled, just copy and paste the following snippet in your proguard.cfg file (or if you have yours specified as proguard-properties.txt):
-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses
Source
You'll need to add the following -keep code to your proguard.cfg file (or if you have yours specified as proguard-properties.txt):
-keep public class com.newrelic.** {
public *;
private *;}
Install the agent and add that code snippet to your progaurd.cfg file.
As for the issue with non-New Relic apps throwing errors when New Relic is installed, this seems to be an issue with the build path settings in Eclipse, you can open a support ticket with us at support#newrelic.com and we can take a look at your specific environment settings, but prior cases indicate that this isn't really a New Relic-specific error.