diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 094cca8e9..95bbf1589 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -66,8 +66,39 @@ jobs: name: javadoc path: javadoc + android-test: + needs: shadow_jar + runs-on: macos-latest + name: android-test (api ${{ matrix.api-level }}) + strategy: + fail-fast: false + matrix: + # minSdk and targetSdk, see ${project_root}/android_test/app/build.gradle.kts + api-level: [ 26, 33 ] + steps: + - name: checkout + uses: actions/checkout@v3 + - name: Download JAR Artifact + uses: actions/download-artifact@v2 + with: + name: jar + path: android_test/app/libs/ + - uses: actions/setup-java@v3 + with: + java-version: 17 # TODO: Android Gradle plugin requires Java 11, consider replacing other parts with Java 17. + distribution: ${{ env.JAVA_DISTRIBUTION }} + - name: run tests + uses: reactivecircus/android-emulator-runner@v2 + with: + working-directory: ./android_test + api-level: ${{ matrix.api-level }} + script: ./gradlew connectedCheck + target: google_apis + arch: x86_64 + profile: 'pixel_2' + deploy: - needs: [ shadow_jar, javadoc ] + needs: [ javadoc, android-test ] permissions: contents: write if: github.event_name == 'release' && github.event.action == 'created' diff --git a/android_test/.gitignore b/android_test/.gitignore new file mode 100644 index 000000000..aa724b770 --- /dev/null +++ b/android_test/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/android_test/README.md b/android_test/README.md new file mode 100644 index 000000000..fa6194375 --- /dev/null +++ b/android_test/README.md @@ -0,0 +1,4 @@ +# Android Test +This folder contains a simple project for testing whether stellar-sdk can be successfully integrated into an Android project. + +This project is based on a template project created using Android Studio, and I have tried my best not to make any excessive modifications. \ No newline at end of file diff --git a/android_test/app/.gitignore b/android_test/app/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/android_test/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android_test/app/build.gradle.kts b/android_test/app/build.gradle.kts new file mode 100644 index 000000000..e8ee153b8 --- /dev/null +++ b/android_test/app/build.gradle.kts @@ -0,0 +1,71 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") +} + +android { + namespace = "org.stellar.javastellarsdkdemoapp" + compileSdk = 33 + + defaultConfig { + applicationId = "org.stellar.javastellarsdkdemoapp" + minSdk = 26 + targetSdk = 33 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.4.3" + } + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +dependencies { + + 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") + implementation(platform("androidx.compose:compose-bom:2023.03.00")) + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-graphics") + implementation("androidx.compose.ui:ui-tooling-preview") + implementation("androidx.compose.material3:material3") + implementation(files("libs/stellar-sdk.jar")) + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.uiautomator:uiautomator:2.3.0-alpha03") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00")) + androidTestImplementation("androidx.compose.ui:ui-test-junit4") + debugImplementation("androidx.compose.ui:ui-tooling") + debugImplementation("androidx.compose.ui:ui-test-manifest") +} \ No newline at end of file diff --git a/android_test/app/libs/README.md b/android_test/app/libs/README.md new file mode 100644 index 000000000..fb24dd7e4 --- /dev/null +++ b/android_test/app/libs/README.md @@ -0,0 +1 @@ +You need to place stellar-sdk.jar into this folder. \ No newline at end of file diff --git a/android_test/app/proguard-rules.pro b/android_test/app/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/android_test/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/android_test/app/src/androidTest/java/org/stellar/javastellarsdkdemoapp/MainInstrumentedTest.kt b/android_test/app/src/androidTest/java/org/stellar/javastellarsdkdemoapp/MainInstrumentedTest.kt new file mode 100644 index 000000000..9c538f291 --- /dev/null +++ b/android_test/app/src/androidTest/java/org/stellar/javastellarsdkdemoapp/MainInstrumentedTest.kt @@ -0,0 +1,62 @@ +package org.stellar.javastellarsdkdemoapp + +import android.content.Intent +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.uiautomator.By +import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.Until +import org.junit.Assert.* +import org.junit.Test +import org.junit.runner.RunWith + +private const val ONE_MINUTE = 1000L * 60 +private const val PACKAGE = "org.stellar.javastellarsdkdemoapp" + +/** + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class MainInstrumentedTest { + @Test + fun testGetNetwork() { + val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) + // open app + device.pressHome() + val launcherPackage: String = device.launcherPackageName + assertNotNull(launcherPackage) + device.wait( + Until.hasObject(By.pkg(launcherPackage).depth(0)), + ONE_MINUTE + ) + val context = InstrumentationRegistry.getInstrumentation().context + val intent = + context.packageManager.getLaunchIntentForPackage(PACKAGE) + intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) + context.startActivity(intent) + // wait for app to appear + device.wait( + Until.hasObject(By.pkg(PACKAGE).depth(0)), + ONE_MINUTE + ) + + // get text + val textNoNetworkInfo = device.wait( + Until.findObject(By.text("No network info")), + ONE_MINUTE + ) + assertNotNull(textNoNetworkInfo) + + // get button + val button = device.wait( + Until.findObject(By.text("Get Network")), + ONE_MINUTE + ) + assertNotNull(button) + + // click button and wait text to appear + button.click() + + assertTrue(device.wait(Until.hasObject(By.text("public")), ONE_MINUTE * 5)) + } +} \ No newline at end of file diff --git a/android_test/app/src/main/AndroidManifest.xml b/android_test/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..9fd8d46b2 --- /dev/null +++ b/android_test/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt new file mode 100644 index 000000000..a7b0f7fab --- /dev/null +++ b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt @@ -0,0 +1,119 @@ +package org.stellar.javastellarsdkdemoapp + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.stellar.javastellarsdkdemoapp.ui.theme.JavaStellarSDKDemoAppTheme +import org.stellar.sdk.Server + +private const val HORIZON_SERVER = "https://horizon.stellar.org/" +private const val PUBLIC = "Public Global Stellar Network ; September 2015" +private const val TESTNET = "Test SDF Network ; September 2015" + +class MainActivity : ComponentActivity() { + private lateinit var networkViewModel: NetworkViewModel + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + networkViewModel = ViewModelProvider(this).get(NetworkViewModel::class.java) + + setContent { + JavaStellarSDKDemoAppTheme { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + Main(networkViewModel) + } + } + } + } +} + +class NetworkViewModel : ViewModel() { + private val _network = mutableStateOf(null) + val network: String? get() = _network.value + + fun fetchNetworkPassphrase() { + viewModelScope.launch { + _network.value = withContext(Dispatchers.IO) { + getNetwork() + } + } + } +} + +@Composable +fun Main(networkViewModel: NetworkViewModel, modifier: Modifier = Modifier) { + Column( + modifier = modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Button( + onClick = { networkViewModel.fetchNetworkPassphrase() } + ) { + Text(text = "Get Network") + } + + Spacer(modifier = Modifier.height(16.dp)) + + Text( + text = networkViewModel.network ?: "No network info", + modifier = Modifier.padding(horizontal = 16.dp) + ) + } +} + +@Preview(showBackground = true) +@Composable +fun MainPreview() { + JavaStellarSDKDemoAppTheme { + val networkViewModel = NetworkViewModel() + Main(networkViewModel) + } +} + +private fun getNetwork(): String? { + val server = Server(HORIZON_SERVER) + return try { + when (server.root().networkPassphrase) { + PUBLIC -> { + "public" + } + + TESTNET -> { + "testnet" + } + + else -> { + "others" + } + } + } catch (e: Exception) { + null + } +} \ No newline at end of file diff --git a/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Color.kt b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Color.kt new file mode 100644 index 000000000..f7d8cbce3 --- /dev/null +++ b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package org.stellar.javastellarsdkdemoapp.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Theme.kt b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Theme.kt new file mode 100644 index 000000000..46f1756e7 --- /dev/null +++ b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package org.stellar.javastellarsdkdemoapp.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun JavaStellarSDKDemoAppTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Type.kt b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Type.kt new file mode 100644 index 000000000..315916918 --- /dev/null +++ b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package org.stellar.javastellarsdkdemoapp.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/android_test/app/src/main/res/drawable/ic_launcher_background.xml b/android_test/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..07d5da9cb --- /dev/null +++ b/android_test/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android_test/app/src/main/res/drawable/ic_launcher_foreground.xml b/android_test/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 000000000..2b068d114 --- /dev/null +++ b/android_test/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/android_test/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/android_test/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 000000000..6f3b755bf --- /dev/null +++ b/android_test/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android_test/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/android_test/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 000000000..6f3b755bf --- /dev/null +++ b/android_test/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android_test/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/android_test/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 000000000..c209e78ec Binary files /dev/null and b/android_test/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/android_test/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/android_test/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 000000000..b2dfe3d1b Binary files /dev/null and b/android_test/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/android_test/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/android_test/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 000000000..4f0f1d64e Binary files /dev/null and b/android_test/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/android_test/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/android_test/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 000000000..62b611da0 Binary files /dev/null and b/android_test/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/android_test/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/android_test/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 000000000..948a3070f Binary files /dev/null and b/android_test/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/android_test/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/android_test/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..1b9a6956b Binary files /dev/null and b/android_test/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/android_test/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/android_test/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 000000000..28d4b77f9 Binary files /dev/null and b/android_test/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/android_test/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/android_test/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..9287f5083 Binary files /dev/null and b/android_test/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/android_test/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/android_test/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 000000000..aa7d6427e Binary files /dev/null and b/android_test/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/android_test/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/android_test/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 000000000..9126ae37c Binary files /dev/null and b/android_test/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/android_test/app/src/main/res/values/colors.xml b/android_test/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..f8c6127d3 --- /dev/null +++ b/android_test/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/android_test/app/src/main/res/values/strings.xml b/android_test/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..fb91d5377 --- /dev/null +++ b/android_test/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + JavaStellarSDKDemoApp + \ No newline at end of file diff --git a/android_test/app/src/main/res/values/themes.xml b/android_test/app/src/main/res/values/themes.xml new file mode 100644 index 000000000..3ef499ada --- /dev/null +++ b/android_test/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +