requestAccessToken gives Error

jyothish
Hi , When i try to do a login via Android App using Eclipse and try this line :

userModel = kiteSdk.requestAccessToken("nth031oxykomzdnjgcfbms3huvz8yjye", "secretkey");

I get an error as shown below , any idea why ?


01-29 21:00:18.997: E/AndroidRuntime(28880): java.lang.NoSuchMethodError: No static method encodeHexString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of 'org.apache.commons.codec.binary.Hex' appears in /system/framework/ext.jar)
01-29 21:00:18.997: E/AndroidRuntime(28880): at org.apache.commons.codec.digest.DigestUtils.sha256Hex(DigestUtils.java:532)
01-29 21:00:18.997: E/AndroidRuntime(28880): at com.rainmatter.kiteconnect.KiteConnect.requestAccessToken(KiteConnect.java:174)
01-29 21:00:18.997: E/AndroidRuntime(28880): at jinga.proj.stocks.LandingPage$1.run(LandingPage.java:200)
01-29 21:00:18.997: E/AndroidRuntime(28880): at android.os.Handler.handleCallback(Handler.java:815)
01-29 21:00:18.997: E/AndroidRuntime(28880): at android.os.Handler.dispatchMessage(Handler.java:104)
01-29 21:00:18.997: E/AndroidRuntime(28880): at android.os.Looper.loop(Looper.java:194)
01-29 21:00:18.997: E/AndroidRuntime(28880): at android.app.ActivityThread.main(ActivityThread.java:5706)
01-29 21:00:18.997: E/AndroidRuntime(28880): at java.lang.reflect.Method.invoke(Native Method)
01-29 21:00:18.997: E/AndroidRuntime(28880): at java.lang.reflect.Method.invoke(Method.java:372)
01-29 21:00:18.997: E/AndroidRuntime(28880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1033)
01-29 21:00:18.997: E/AndroidRuntime(28880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
  • sujith
    Hi @jyothish,
    I think it is dependency issue with org.apache.commons. Checkout this thread.
  • jyothish
    Hi Sujith , the link you provided says convert to -
    String encodedString = new String(Base64.encodeBase64('string to encode'));

    But the problem I have is with line -
    userModel = kiteSdk.requestAccessToken("svlo1ylhol1wbuttybr5w5y7r37t30ml", "api secret");

    Can you show me how to convert this requestAccessToken to encode format ?
    I am not able to get past this line.
  • sujith
    Hi @jyothish,
    I just pointed to similar issue. Try importing org.apache.commons package to your project.
    This is just some dependency issue.
    Check this pom file and import all dependencies to your project and try running it.
  • jyothish
    Hi Sujith, After adding all the dependencies to the project , the project does not compile now .

    Error:
    2017-02-02 00:07:29 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/mashape/unirest/http/Headers;
    [2017-02-02 00:07:29 - jinga.fin.stock2] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/mashape/unirest/http/Headers;

    Any idea why ?
  • sujith
    @jyothish,
    Your build path has multiple sources defining com.mashape.unirest package, uncheck one of the file in build path and build the project.
  • jyothish
    Hi Sujith,

    I have checked only 1 APACHE jar and the KITE CONNECT JAR.
    And i get error.
    [2017-02-02 11:14:51 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/apache/commons/codec/Decoder;
    [2017-02-02 11:14:51 - jinga.test.test1] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/commons/codec/Decoder;
    [2017-02-02 11:17:26 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/apache/commons/codec/Decoder;
    [2017-02-02 11:17:26 - jinga.test.test1] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/apache/commons/codec/Decoder;

    See my Java Build Path settings.
    imgh.us/kite_clash.jpg

    When i uncheck the KITE CONNECT JAR , the error goes away
    When i check all the Apache jar and uncheck KITE CONNECT JAR , the error goes away
    When i check only KITE CONNECT and uncheck APACHE jar , the error goes away

    So my conclusion is something in the KITE CONNECT JAR is clashing with APACHE JAR files.

    So how can i get this resolved ? please advice.
  • sujith
    sujith edited February 2017
    @jyothish,
    Keep Kite Connect and remove apache jar
  • jyothish
    Did that , and now I get this error :
    https://i.imgsafe.org/2db2e544cb.jpg

    02-02 12:36:08.911: E/AndroidRuntime(3563): FATAL EXCEPTION: main
    02-02 12:36:08.911: E/AndroidRuntime(3563): Process: jinga.test.test1, PID: 3563
    02-02 12:36:08.911: E/AndroidRuntime(3563): java.lang.NoSuchMethodError: No static method encodeHexString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of 'org.apache.commons.codec.binary.Hex' appears in /system/framework/ext.jar)
    02-02 12:36:08.911: E/AndroidRuntime(3563): at org.apache.commons.codec.digest.DigestUtils.sha256Hex(DigestUtils.java:532)
    02-02 12:36:08.911: E/AndroidRuntime(3563): at com.rainmatter.kiteconnect.KiteConnect.requestAccessToken(KiteConnect.java:174)


    i was told earlier this was missing apache jar files but adding them causes compile error as stated earlier and not adding them causes crash at the line : userModel = kiteSdk.requestAccessToken(requestToken, secretKey);

    Please suggest
  • sujith
    @jyothish,
    You will have to do more trial and error by googling for package name.
    So now issue is apache jar has other packages also which are already present in KiteConnect jar which is causing multiple dependency issue. So solution is to find a jar which has only org.apache.commons.codec package and not other packages. Try adding this jar to build path.
  • jyothish
    Added org-apache-commons-codec.jar along with KITE jar
    Please see error and settings
    imgh.us/kite_crash_3.jpg

    Any other combination I can try ?
  • sujith
    @jyothish,
    I will check for alternate solution and get back to you.
  • jyothish
    Thanks Sujith .. i shall try various combinations as well meanwhile ..
  • sujith
    Hi @jyothish,
    Even if we fix this issue. I am afraid, it won't work on android sdk because network library we use is java specific. I would suggest you to port java sdk to android and use it.
    We can help you with all the information you need about API for porting.
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • sujith
    Hi @jyothish,
    Kite Connect documentation is here and javakiteconnect documentation is here. You will have to change http library to android specific http library.
  • jyothish
    ok Sujith, so this is what I did -
    I unchecked org apache jar and checked only KITE connect jar in Build Path
    Then added the KITE connect imports
    Then added the login code as show in pic below:
    imgh.us/crash_with_eror_2.jpg

    And then compile works fine
    But when the code gets executed, the error that comes up is -
    No Such Methid Error , see pic below:
    imgh.us/crash_with_eror_1.jpg

    Please help
  • sujith
    Hi @jyothish,
    This thread has similar issue, you can take a look. But even if you fix dependency issue, it won't run because android has stopped supporting Apache HttpClient for networking. It only supports HttpUrlConnection and our network layer uses Unirest which uses Apache HttpClient.

    You have to download javakiteConnect repository and remove KiteRequest class and use your own version of KiteRequest class with android supported http library.
  • jyothish
    "even if you fix dependency issue, it won't run because android has stopped supporting Apache HttpClient for networking. It only supports HttpUrlConnection and our network layer uses Unirest which uses Apache HttpClient"

    So Sujith are you saying KITE CONNECT will not run on ANDROID ?
  • sujith
    @jyothish,
    Yes, javakiteconnect doesn't support android.
  • jyothish
    ok cool , let me try using Python , maybe thats simpler to implement and full support available i hope ..
  • sujith
    @jyothish,
    Yes. You can try python.
  • jyothish
    Thanks , Can place orders using Python
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • jyothish
    Ok Sujith, so is there a document you can share that explains how to port the kite connect api from java to android ?
  • sujith
    sujith edited February 2017
    Hi @jyothish,
    We don't have document for porting. javakiteconnect is a modular library, you can find Java documentation here.
    To get started, I would suggest you to start with KiteRequest class which uses unirest for making http requests. You just need to rewrite this file with android specific http library like okhttp, volley or retrofit.
This discussion has been closed.