Hi. I am trying to compile my app using proguard, and I am getting an error with the backendless classes. I have added the proguard exceptions as suggested here https://backendless.com/documentation/users/android/users_requirements.htm, but it is not working. I am using backendless from gradle (compile ‘com.backendless:android:3.0.3’)
Please find attached my proguard-rules and error log.
Hi again. I found another problem while using proguard. I have this code:
BackendlessDataQuery dataQueryOptions = new BackendlessDataQuery();
dataQueryOptions.setPageSize(100);
Backendless.Persistence.of(MemeTemplate.class).find(dataQueryOptions, new AsyncCallback<BackendlessCollection<MemeTemplate>>() {
@Override
public void handleResponse(BackendlessCollection<MemeTemplate> response) {
if (response != null && response.getCurrentPage() != null) {
mTemplates = response.getCurrentPage();
}
mAdapter.notifyDataSetChanged(mTemplates);
}
@Override
public void handleFault(BackendlessFault fault) {
Utils.getInstance(CatalogActivity.this).showErrorMessage(fault);
}
});
If I don’t use proguard, it works as expected, getting some results in BackendlessResponse object. But when I enable proguard, it doesn’t get anything, it returns a BackendlesResponse but getCurrentPage returns zero results instead of what I am expecting (about 20). I thought it could be because proguard is ofbuscating the classes names or the constants I am using for backendless keys, but I have checked with some log traces and the decompiled apk that it isn’t, both seems to be ok. This is where I initialize Backendless:
public class MyApplication extends Application {
public MyApplication() {
super();
}
@Override
public void onCreate() {
super.onCreate();
Backendless.initApp(this,
BuildConfig.BACKENDLESS_APP_ID,
BuildConfig.BACKENDLESS_SECRET_KEY,
BuildConfig.BACKENDLESS_VERSION);
// Map classes to Backendless tables
Backendless.Persistence.mapTableToClass(MemeTemplate.class.getSimpleName(), MemeTemplate.class);
}
}
Try adding the following directives in the proguard config:
-keep public class backendless.** {
public protected ;
}-keep public class YOURPACKAGE.* {
public protected *;
}
where “YOURPACKAGE” is the package name where the MemeTemplate class is placed.
I already had -keep public for my class. I have added it for backendless.**, but it is still not working. This is what I have in proguard for backendless:
-dontwarn com.backendless.**
-dontwarn weborb.**
-keep class weborb.** {*;}
-keep public class backendless.** {
public protected *;
}
-keep public class com.tactel.memegenerator.model.** {
public protected *;
}
Almost … Now I’m getting something more strange than before: a BackendlessCollection of 10 objects (expected 20 and in my code I have pageSize = 100) but all of them are empty: all properties return null.
No, we do not have a sample app that uses proguard. I just tried an example similar to yours and was able to get the results both in release and debug compilations with the following settings:
-dontwarn com.backendless.**
-dontwarn weborb.**
-keep class weborb.** {*;}
-keep class com.backendless.** { *; }
-keep class com.tactel.memegenerator.model.**.** { *; }
Please try it and let me know if it works for you.
Hi Andrés,
Please accept our apologies for taking so long to figure out and thanks for helping us find out the drawbacks in the docs.
Try the following rules:
# Backendless
-dontwarn com.backendless.**
-dontwarn weborb.**
-keep class weborb.** {*;}
-keep class com.backendless.** {*;}
-keep class com.tactel.memegenerator.model.** {*;}
# Backendless
Note that the last line has only single .** instead of double.
These rules should work fine, as they will keep Backendless’ and you models’ classes totally untouched.