Skip to content

Commit

Permalink
Fix compatibility on Android platforms below Android API 28 (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Sep 28, 2023
1 parent 19eb5a1 commit 63c7531
Show file tree
Hide file tree
Showing 383 changed files with 3,901 additions and 1,306 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
# minSdk and targetSdk, see ${project_root}/android_test/app/build.gradle.kts
# TODO: Investigate why it is unstable on API 33.
emulator: [
{ api-level: 26, target: google_apis },
{ api-level: 23, target: google_apis },
{ api-level: 32, target: playstore }
]
steps:
Expand All @@ -91,17 +91,20 @@ jobs:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
uses: Wandalen/wretry.action@master
with:
working-directory: ./android_test
api-level: ${{ matrix.emulator.api-level }}
target: ${{ matrix.emulator.target }}
script: ./gradlew connectedCheck
arch: x86_64
profile: 'pixel_2'
attempt_limit: 3 # android test is not stable, let's retry it
action: reactivecircus/android-emulator-runner@v2
with: |
working-directory: ./android_test
api-level: ${{ matrix.emulator.api-level }}
target: ${{ matrix.emulator.target }}
script: ./gradlew connectedCheck
arch: x86_64
profile: 'pixel_2'
deploy:
needs: [ build, javadoc ] # TODO: add android-test when it is stable.
needs: [ build, javadoc, android-test ]
permissions:
contents: write
if: github.event_name == 'release' && github.event.action == 'created'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
As this project is pre 1.0, breaking changes may happen for minor version bumps. A breaking change will get clearly notified in this log.

## Pending
* Add `org.stellar.sdk.spi.SdkProvider`, users can implement this interface to provide their own implementation of the SDK. We provide an [Android specific implementation](https://github.com/stellar/java-stellar-sdk-android-spi), if you are integrating this SDK into an Android project, be sure to check it out. ([#543](https://github.com/stellar/java-stellar-sdk/pull/543))
* Fix issues where the validity of the encoded strkey is not verified in certain scenarios. ([#541](https://github.com/stellar/java-stellar-sdk/pull/541))
* Fix the issue of javadocJar not including documentation. ([#539](https://github.com/stellar/java-stellar-sdk/pull/539))
* Publish sourcesJar to the GitHub Release page. ([#539](https://github.com/stellar/java-stellar-sdk/pull/539))
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ xdr/Stellar-contract.x \
xdr/Stellar-internal.x \
xdr/Stellar-contract-config-setting.x

XDRGEN_COMMIT=f0c41458ca0b66b4649b18deddc9f7a11199f1f9
XDRGEN_COMMIT=7c9349c62844e376bc637be678695387e88d125f
XDRNEXT_COMMIT=9ac02641139e6717924fdad716f6e958d0168491

.PHONY: xdr xdr-clean xdr-update
Expand Down
13 changes: 10 additions & 3 deletions android_test/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {

defaultConfig {
applicationId = "org.stellar.javastellarsdkdemoapp"
minSdk = 26
minSdk = 23
targetSdk = 33
versionCode = 1
versionName = "1.0"
Expand All @@ -30,6 +30,11 @@ android {
}
}
compileOptions {
// Flag to enable support for the new language APIs
// For AGP 4.1+
// https://developer.android.com/studio/write/java8-support
isCoreLibraryDesugaringEnabled = true

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Expand All @@ -50,7 +55,9 @@ android {
}

dependencies {

// For AGP 7.4+
// https://developer.android.com/studio/write/java8-support
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.2")
Expand All @@ -59,9 +66,9 @@ dependencies {
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation(files("libs/stellar-sdk.jar"))
// Since we are adding local jar(libs/stellar-sdk.jar) as dependency,
// gradle cannot automatically download the required third-party dependencies.
implementation(files("libs/stellar-sdk.jar"))
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation("com.squareup.okhttp3:okhttp-sse:4.11.0")
implementation("com.moandjiezana.toml:toml4j:0.7.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private const val PACKAGE = "org.stellar.javastellarsdkdemoapp"
@RunWith(AndroidJUnit4::class)
class MainInstrumentedTest {
@Test
fun testGetNetwork() {
fun testSDK() {
val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
// open app
device.pressHome()
Expand All @@ -41,22 +41,22 @@ class MainInstrumentedTest {
)

// get text
val textNoNetworkInfo = device.wait(
Until.findObject(By.text("No network info")),
val textNoTestResult = device.wait(
Until.findObject(By.text("Not Run")),
ONE_MINUTE
)
assertNotNull(textNoNetworkInfo)
assertNotNull(textNoTestResult)

// get button
val button = device.wait(
Until.findObject(By.text("Get Network")),
Until.findObject(By.text("Run Test")),
ONE_MINUTE
)
assertNotNull(button)

// click button and wait text to appear
button.click()

assertTrue(device.wait(Until.hasObject(By.text("public")), ONE_MINUTE * 5))
assertTrue(device.wait(Until.hasObject(By.text("SUCCESS")), ONE_MINUTE * 5))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.stellar.javastellarsdkdemoapp

import org.stellar.sdk.Base32
import org.stellar.sdk.Base64
import org.stellar.sdk.spi.SdkProvider

class AndroidSdkProvider : SdkProvider {
override fun createBase64(): Base64 {
return AndroidBase64()
}

override fun createBase32(): Base32 {
return AndroidBase32()
}

class AndroidBase64 : Base64 {
override fun encodeToString(data: ByteArray?): String {
return android.util.Base64.encodeToString(data, android.util.Base64.NO_WRAP)
}

override fun encode(data: ByteArray?): ByteArray {
return android.util.Base64.encode(data, android.util.Base64.NO_WRAP)
}

override fun decode(data: String?): ByteArray {
return android.util.Base64.decode(data, android.util.Base64.NO_WRAP)
}
}

class AndroidBase32 : Base32 {
private val base32: ApacheCodec.Base32 = ApacheCodec.Base32()

override fun encode(data: ByteArray?): ByteArray? {
return base32.encode(data)
}

override fun decode(data: String?): ByteArray? {
return base32.decode(data)
}

override fun decode(data: ByteArray?): ByteArray? {
return base32.decode(data)
}

}
}
Loading

0 comments on commit 63c7531

Please sign in to comment.