strongloop-community/loopback-sdk-android

getPackageInfo() and getSharedPreferences() fails

benmarten opened this issue · 9 comments

I am seeing these errors on Android 5.0:

  03-13 16:04:59.888    2351-2351/com.colibriapps.foodlr E/BeanUtil﹕ getPackageInfo() failed
      java.lang.IllegalAccessException: Cannot access method: android.content.pm.PackageInfo com.strongloop.android.loopback.LocalInstallation.getPackageInfo()
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.strongloop.android.remoting.BeanUtil.getProperties(BeanUtil.java:94)
              at com.strongloop.android.loopback.LocalInstallation.save(LocalInstallation.java:274)
              at com.colibriapps.foodlr.controller.main.MainActivity.saveInstallation(MainActivity.java:330)
              at com.colibriapps.foodlr.controller.main.MainActivity.updateRegistration(MainActivity.java:279)
              at com.colibriapps.foodlr.controller.main.MainActivity.onCreate(MainActivity.java:87)
              at android.app.Activity.performCreate(Activity.java:5933)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  03-13 16:04:59.888    2351-2351/com.colibriapps.foodlr E/BeanUtil﹕ getSharedPreferences() failed
      java.lang.IllegalAccessException: Cannot access method: android.content.SharedPreferences com.strongloop.android.loopback.LocalInstallation.getSharedPreferences()
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.strongloop.android.remoting.BeanUtil.getProperties(BeanUtil.java:94)
              at com.strongloop.android.loopback.LocalInstallation.save(LocalInstallation.java:274)
              at com.colibriapps.foodlr.controller.main.MainActivity.saveInstallation(MainActivity.java:330)
              at com.colibriapps.foodlr.controller.main.MainActivity.updateRegistration(MainActivity.java:279)
              at com.colibriapps.foodlr.controller.main.MainActivity.onCreate(MainActivity.java:87)
              at android.app.Activity.performCreate(Activity.java:5933)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Thank you for reporting the issue, @benmarten. How can I reproduce it locally on my machine, ideally in an emulator running Android 5.0?

It's happening here, on installation.save(...):

void saveInstallation(final LocalInstallation installation) {

    installation.save(new Model.Callback() {

        @Override
        public void onSuccess() { ... }

        @Override
        public void onError(final Throwable t) { ... }
    });
}

We are calling it in our MainActivity, all this code is taken from the android example app: https://github.com/strongloop/loopback-component-push/blob/master/example/android/src/com/google/android/gcm/demo/app/DemoActivity.java

Running on Android 5.0.

I managed to reproduce the issue using loopback-sdk-android version 1.5.1, the version 1.2.0 works correctly for me.

Timeboxed to 1 story point for Sprint 68.

@benmarten From what I found on my side, these messages are just warnings, not affecting application functionality. Is there any particular bug you are seeing in your application that makes you believe it's caused by these access errors?

I have submitted #72 that should remove these warnings.

no, no issues. i think its just warnings then. thx for the fix... i think this can be closed then.

I have just released a new version 1.5.2 that should fix these warnings. @benmarten could you please check it out and let me know how it works for you?

Thanks, all warnings are gone!

Great, thank you for confirming that my solution works :)