hoko / hoko-android

HOKO Android SDK
http://hokolinks.com
Apache License 2.0
21 stars 9 forks source link

Setup routes on Android #21

Closed pawlowskim closed 7 years ago

pawlowskim commented 7 years ago

Hi, I'm trying to setup hoko on Android (react-native) app but I got the same error over and over.

@Override
    public void onCreate() {
        super.onCreate();
        Hoko.setup(this, getResources().getString(R.string.hoko_token));
        Hoko.setVerbose(true);
        setupDeeplinkRoutes();
    }

private void setupDeeplinkRoutes() {
        Hoko.deeplinking().mapRoute("sth/:swId", new DeeplinkCallback() {
            @Override
            public void deeplinkOpened(Deeplink deeplink) {
                hokoHelper.notifyNewDeeplink(deeplink);
            }
        });
    }

After opening the app I got this:

04-13 09:09:01.703: D/HOKO(3475): GET from https://api.hokolinks.com/v2/version.json
04-13 09:09:01.757: D/HOKO(3475): Adding request to queue
04-13 09:09:02.028: E/HOKO(3475): A new version of HOKO is available, please update your gradle.properties to "compile 'com.hokolink:hoko:2.5.0'"

After +/- 30s I got this:

04-13 09:09:31.638: D/HOKO(3475): POST to https://api.hokolinks.com/v2/routes.json with {"route":{"build":"88","device":"Xamarin Nexus 5 (Lollipop)","path":"sth\/:swId","version":"0.1.0"}}
04-13 09:09:31.912: D/HOKO(3475): Success {"path":"\/sth\/:swId"}

And when I open a smart link (that works on iOS) I got this:

04-13 09:04:45.926: D/HOKO(3050): POST to https://api.hokolinks.com/v2/smartlinks/resolve.json with {"smartlink":"http:\/\/my_domain.com\/sth\/some_UUID","uid":"C0650565-BE11-4021-8FA8-20CABE2F3C53-1492065930"}
04-13 09:04:46.212: E/HOKO(3050): Code=7 Description=Error Omnilink with id 'sth' could not be found
04-13 09:04:46.212: E/HOKO(3050): com.hokolinks.model.exceptions.ServerErrorException: Code=7 Description=Error Omnilink with id 'sth' could not be found
04-13 09:04:46.212: E/HOKO(3050):   at com.hokolinks.utils.networking.async.HttpRequest.handleHttpResponse(HttpRequest.java:320)
04-13 09:04:46.212: E/HOKO(3050):   at com.hokolinks.utils.networking.async.HttpRequest.performPOST(HttpRequest.java:288)
04-13 09:04:46.212: E/HOKO(3050):   at com.hokolinks.utils.networking.async.HttpRequest.access$200(HttpRequest.java:35)
04-13 09:04:46.212: E/HOKO(3050):   at com.hokolinks.utils.networking.async.HttpRequest$1.run(HttpRequest.java:183)
04-13 09:04:46.212: E/HOKO(3050):   at com.hokolinks.utils.networking.async.NetworkAsyncTask.doInBackground(NetworkAsyncTask.java:19)
04-13 09:04:46.212: E/HOKO(3050):   at com.hokolinks.utils.networking.async.NetworkAsyncTask.doInBackground(NetworkAsyncTask.java:9)
04-13 09:04:46.212: E/HOKO(3050):   at android.os.AsyncTask$2.call(AsyncTask.java:292)
04-13 09:04:46.212: E/HOKO(3050):   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-13 09:04:46.212: E/HOKO(3050):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-13 09:04:46.212: E/HOKO(3050):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-13 09:04:46.212: E/HOKO(3050):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-13 09:04:46.212: E/HOKO(3050):   at java.lang.Thread.run(Thread.java:818)

On the web page, in template I cannot see any routes under Android rules as well. Documentation doesn't mention about those errors at all and they coming from the server side so I cannot look through source code of hoko-android as well.

I will appreciate your help

pawlowskim commented 7 years ago

I made a huge mistake, I used iOS token instead of Android :/ Routes works well right now. I have another question. I would like to handle deeplinks manually, so I map them manually, and then I will parse them as well. But when I receive a deeplink, application doesn't shows in foreground. I wanted to send new intent to main activity but when I do, I receive crash from HokoActivity:

04-13 12:54:16.517: E/AndroidRuntime(24448): FATAL EXCEPTION: main
04-13 12:54:16.517: E/AndroidRuntime(24448): Process: com.my_app, PID: 24448
04-13 12:54:16.517: E/AndroidRuntime(24448): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my_app/com.hokolinks.activity.HokoActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.os.Handler.dispatchMessage(Handler.java:102)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.os.Looper.loop(Looper.java:135)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.ActivityThread.main(ActivityThread.java:5254)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at java.lang.reflect.Method.invoke(Native Method)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at java.lang.reflect.Method.invoke(Method.java:372)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
04-13 12:54:16.517: E/AndroidRuntime(24448): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.content.ComponentName.<init>(ComponentName.java:77)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.content.Intent.<init>(Intent.java:4160)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.my_app.hoko.HokoHelper.notifyNewDeeplink(HokoHelper.java:29)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.my_app.MainApplication$2.deeplinkOpened(MainApplication.java:100)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.model.RouteImpl.execute(RouteImpl.java:15)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.deeplinking.Routing.openDeeplink(Routing.java:249)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.deeplinking.Routing.handleOpenURL(Routing.java:194)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.deeplinking.Routing.openURL(Routing.java:165)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.deeplinking.Deeplinking.openURL(Deeplinking.java:166)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.deeplinking.Deeplinking.openURL(Deeplinking.java:153)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at com.hokolinks.activity.HokoActivity.onCreate(HokoActivity.java:26)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.Activity.performCreate(Activity.java:5990)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
04-13 12:54:16.517: E/AndroidRuntime(24448):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
04-13 12:54:16.517: E/AndroidRuntime(24448):    ... 10 more
04-13 12:54:21.146: E/InputDispatcher(467): channel '1071b7dc com.my_app/com.my_app.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
04-13 12:54:21.153: E/EGL_xap(467): egl: current context mark for deletion

com.my_app.hoko.HokoHelper is my helper that I will use to communicate with JS (because it's react native app).

rikas commented 7 years ago

Hi @pawlowskim,

We tried to figure out the problem, but we have never developed in react native and I don't seem to understand what's going on.

Sorry about that. Is there a chance you can try to follow the error and see what's going on in here?:

com.hokolinks.model.RouteImpl.execute(RouteImpl.java:15)

Thanks

pawlowskim commented 7 years ago

I was able to fix it. Application is opening after depplink opens but I faced other issues. This is most certain related with react. Thanks.