-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The API method for using this SDK in android has an exception #44
Comments
The project used HttpClient, but it is deprecated in Android SDK 23. |
I prepared a JAR file without dependencies: https://www.dropbox.com/s/0z3bu5c67mv9eka/stellar-sdk.jar?dl=0 Please do not use it in production, just check if it works for you and let me know. |
@bartekn tried your jar but it didnt worked for me. Take a look at this: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client I think we need to update Server.java class (https://github.com/stellar/java-stellar-sdk/blob/master/src/main/java/org/stellar/sdk/Server.java) in order to use HttpUrlConnection (https://developer.android.com/reference/java/net/HttpURLConnection.html) Could you help me with that? |
@SunriseCompany I have committed the fixes for the ability to use Android with the java sdk. Check it out here - https://github.com/srayhunter/java-stellar-sdk Feedback welcome! |
@srayhunter I have tried your fixes but with no luck. I get apk build errors when i use my own compiled version of the java-stellar-sdk jar. I've build the jar with gradlew.bat build. I have also tried to change the guava dependency from guava to guava-android, but without luck. Have you maybe a working android sample project? |
@srayhunter I get this error when i build the apk: Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
Someone know what i'm doing wrong? |
@eschgi I found a couple issues last night that I will fix today and let you know when those are committed. Thank you for the feedback! Much appreciated. |
@srayhunter Ok perfect. Eventually for the future it would be better to use OkHttp for all http requests. OkHttp supports additionally HTTP/2 and supports also asynchronous programming patterns. |
@srayhunter @bartekn Thank you. |
After spending some time on this issue, I confirm that java-stellar-jdk does not work on Android because it uses Apache classes that cannot be loaded into the Android plataform. The culprit classes live on packages Surprisingly, the problem shows up even on recent (6.0 and later) versions of Android, after support for the Apache HTTP client was officially removed from the platform (https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html). What happens on earlier versions of Android is clear. Those versions are bundled with a legacy version of Apache's java-stellar-jdk does not work with the legacy Apache classes, as it calls One would expect that this problem would vanish from Android 6.0 (API 23) on, after support to the legacy Apache classes was officially dropped from the platform. However, this did not happen, and here is where things get messy. Even though those classes are not exposed as part of any user-visible Android APIs, it appears that they somehow remain existing within Android and still prevent applications to load newer To demonstrate the problem, I ran a quick experiment on Android 7.0. My experiment did not use java-stellar-jdk at all. This is the relevant code:
The code above fails with the following exception:
The exception above was produced on Android 7.0, by an app that had commons-codec:1.5 as one of the its dependencies:
Note the information at the end of the first line of the stack trace above (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar). Instead of loading class To remove any doubt, I ran a second test. Grabbed the source code for commons-codec:1.5, refactored it so that there would be no conflict with the legacy classes anymore (just renamed
Now the app ran with no errors, correctly showing the decoded string. |
Apologies for the very long comment above. Some additional thoughts... This would be an easy way of making java-stellar-jdk work on Android:
Of course this "solution" has two big inconveniences. First, the trouble of keeping parallel versions of Apache projects just to circumvent a silly Android-specific name clashing issue. Second, the trouble of having a special version of java-stellar-jdk for Android. The second inconvenience could be avoided by using dependency injection, so that java-stellar-jdk is It appears that the ideal solution for running java-stellar-jdk on Android would be to move away from Apache HttpClient and Commons Codec. |
Fix for Android related-issues is now being reviewed: #72 You can check it out but pulling |
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar:classes2.dex)
when I wirte this:“
String uri = "https://horizon-testnet.stellar.org";
Server server=null;
try {
server = new Server(uri);
}catch (Throwable e){
e.printStackTrace();
System.out.println("==========异常");
}
”then,has an exception,
The text was updated successfully, but these errors were encountered: