Included in the project proguard, apk is going, everything is fine, but the application does not work)

Proguard-rules.pro

-keepattributes InnerClasses -keepattributes EnclosingMethod -keepattributes *Annotation* -dontoptimize # Keep Butterknife -keep class butterknife.** { *; } -dontwarn butterknife.internal.** -keep class **$$ViewBinder { *; } -keepclasseswithmembernames class * { @butterknife.* <fields>; } -keepclasseswithmembernames class * { @butterknife.* <methods>; } # Keep Jackson stuff -dontwarn com.fasterxml.jackson.databind.** -keep class org.codehaus.** { *; } -keep class com.fasterxml.jackson.annotation.** { *; } # Keep Retrofit -dontwarn okio.** -dontwarn retrofit2.Platform$Java8 -keep class retrofit.** { *; } -keepclasseswithmembers class * { @retrofit.** *; } -keepclassmembers class * { @retrofit.** *; } # Keep Picasso -dontwarn com.squareup.picasso.** -keep class com.squareup.picasso.** { *; } -keepclasseswithmembers class * { @com.squareup.picasso.** *; } -keepclassmembers class * { @com.squareup.picasso.** *; } #Keep Usafe -dontwarn sun.misc.Unsafe #Keep Moxy -keep class **$$PresentersBinder -keep class **$$State -keep class **$$ParamsHolder -keep class **$$ViewStateClassNameProvider -keepnames class * extends com.arellomobile.mvp.* #Keep Anotations -keep class javax.inject.** { *; } -keep class javax.annotation.** { *; } 

Error occurs in the presenter

 @InjectViewState public class MainPresenter extends MvpPresenter<MainView> { @Inject Service service; public MainPresenter() { CamApp.getAppComponent().inject(this); } public void goLoginActivity(){ getViewState().goLoginActivity(); } public void goListCamerasActivity(){ isAvailableServer(); } private void isAvailableServer(){ Observable<Response> observable = RxUtils.wrapRetrofitCallIsAvailableServer(service.isAvailableServer("")); RxUtils.wrapAsync(observable) .subscribe(server -> { List<String> cookie = server.headers().values("Set-Cookie"); AuthUtils.setSessionId(cookie.get(0).split(";")[0].split("=")[1]); AuthUtils.setToken(cookie.get(1).split(";")[0].split("=")[1]); requestLoginDemo(); }, exception -> getViewState().showError(R.string.unknown_error)); } 

Writes that the service field - No such instance field: 'service'. With the proguard turned off, everything is working fine.

service

 public class Service { private CamAPI mCamApi; public Service(CamAPI mCamApi) { this.mSpaceCamApi = mSpaceCamApi; } public Call<BackendData> passwordRecovery(String cookie, String token, String email){ return mCamApi.passwordRecovery(cookie, token, email); } public Call<Response<ResponseBody>> getArchiveLink(String devCode, String date){ return mCamApi.getArchiveLink(devCode, date); } public Call<BackendData> isAvailableServer(String cookie){ return TextUtils.isEmpty(cookie) ? mCamApi.isAvailableServer() : mCamApi.isAvailableServer(cookie); } public Call<BackendData> login(String cookie, String token, String username, String password, boolean remember){ return mCamApi.login(cookie, token, username, password, remember); } public Call<BackendData> getAllCameraList(String cookie, String token){ return mSpaceCamApi.getAllCameraList(cookie, token); } public Call<BackendData> getCamera(String cookie, String token, Long id, boolean isMobile){ return mCamApi.getCamera(cookie, token, id, isMobile); } public Call<BackendData> ptz(String cookie, String token, Long id, String com){ return mCamApi.ptz(cookie, token, id, com); } public Call<BackendData> logout(String cookie, String token){ return mCamApi.logout(cookie, token); } 

}

  • It seems that this dagger is not zainzhektil, but not moxy. I advise you to try to remove @inject for the test and set the value in the constructor with the pens - senneco
  • Specify, Inject from dagger'a or any other libraries? .. For Dagger, too, there are rules for proguard. - Yura Ivanov
  • Yes, try turning the @Inject Service service into a regular Service field, and in the constructor call service = new Service. Only for verification. So we can understand some more =) - senneco
  • for dagger 2 like no rules needed in proguard - mister
  • Added a service class to the first post. In the service, added a constructor without parameters, in the presenter I tried to create an object through new in the constructor, wrote the same thing - No such instance field: 'service. If I include in proguard-dontobfuscate - everything works. - mister

0