import org.gradle.api.artifacts.transform.CacheableTransform import org.gradle.api.artifacts.transform.InputArtifact import org.gradle.api.artifacts.transform.TransformAction import org.gradle.api.artifacts.transform.TransformOutputs import org.gradle.api.artifacts.transform.TransformParameters import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassVisitor import org.objectweb.asm.ClassWriter import org.objectweb.asm.MethodVisitor import org.objectweb.asm.Opcodes import java.util.zip.ZipEntry import java.util.zip.ZipFile import java.util.zip.ZipOutputStream plugins { id 'com.android.application' id 'project-report' id 'kotlin-android' id 'kotlin-parcelize' id 'com.google.devtools.ksp' id 'dagger.hilt.android.plugin' id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' id 'androidx.navigation.safeargs.kotlin' id 'org.jetbrains.kotlin.plugin.compose' } ext { archivesBaseName = 'dash-wallet' // dashj-platform SDK version per product flavor. // prod uses the stable release; all other flavors use the latest snapshot. dppVersions = [ prod : dppVersion, _testNet3 : dppVersion, staging : dppVersion, devnet : dppVersion, ] } repositories { mavenLocal() mavenCentral() maven { url 'https://maven.google.com/' name 'Google' } } dependencies { implementation project(path: ':common') implementation project(path: ":features:exploredash") implementation project(path: ':integrations:uphold') implementation project(path: ":integrations:coinbase") implementation project(path: ":integrations:crowdnode") implementation project(path: ":integrations:maya") implementation(project(':integration-android')) { exclude(group: 'com.google.android', module: 'android') } implementation 'com.google.android.libraries.identity.googleid:googleid:1.1.1' implementation 'com.google.android.gms:play-services-auth:21.3.0' implementation 'com.google.android.gms:play-services-ads-identifier:18.2.0' coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:$desugaringLibraryVersion" implementation 'androidx.legacy:legacy-support-v4:1.0.0' // Android arch implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.annotation:annotation:1.5.0' implementation "androidx.core:core-ktx:$jetpackVersion" implementation "androidx.fragment:fragment-ktx:1.5.5" implementation('androidx.legacy:legacy-support-v13:1.0.0') { exclude(group: 'com.android.support', module: 'support-fragment') exclude(group: 'com.android.support', module: 'support-media-compat') } implementation 'androidx.legacy:legacy-support-core-utils:1.0.0' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' implementation "androidx.work:work-runtime-ktx:$workRuntimeVersion" implementation "androidx.biometric:biometric:1.1.0" implementation 'org.bouncycastle:bcprov-jdk15to18:1.74' implementation "org.dashj:dashj-core:$dashjVersion" // Dash Platform Kotlin SDK (Phase 3+ of the dashj migration; see docs/kotlin-sdk-migration-plan.md). // Published from the platform repo's kotlin-sdk package (locally: ./gradlew :sdk:publishToMavenLocal). // Step B1 (tx-detail) experimental AAR: adds the transaction_decode JNI // binding (TransactionDecoder). Published from platform branch // claude/b1-txdetail-jni; NEVER repoint at 0.1.0-SNAPSHOT without also // dropping the TransactionDecoder usage below. implementation "org.dashj:dash-sdk-android:$dashSdkVersion" // dashj-platform SDK is declared per-flavor in a dependencies block after the // android {} block, since the flavor-scoped configurations (e.g. prodImplementation) // only exist once productFlavors have been registered. implementation 'io.grpc:grpc-stub:1.54.0' // CURRENT_GRPC_VERSION implementation "org.dashj.android:dashj-bls-android:1.0.1" implementation "org.dashj.android:dashj-x11-android:1.0.0" implementation "org.dashj.android:dashj-scrypt-android:1.0.1" implementation 'com.google.guava:guava:29.0-android' //noinspection GradleDependency implementation "com.google.zxing:core:$zxingVersion" implementation "org.slf4j:slf4j-api:$slf4jVersion" implementation('com.github.tony19:logback-android:3.0.0') { exclude(group: 'com.google.android', module: 'android') } implementation 'com.google.code.findbugs:jsr305:3.0.2' implementation 'com.tbuonomo:dotsindicator:4.2' implementation 'com.github.amulyakhare:textdrawable:558677ea31' // Network implementation "com.squareup.okhttp3:okhttp:$ok_http_version" implementation "com.squareup.okhttp3:logging-interceptor:$ok_http_version" implementation 'com.squareup.moshi:moshi:1.11.0' implementation 'com.squareup.moshi:moshi-kotlin:1.11.0' implementation 'com.squareup.retrofit2:converter-moshi:2.6.4' implementation 'org.conscrypt:conscrypt-android:2.5.3' // TLS 1.3 support for Android <= 9.0 // Credential Manager implementation "androidx.credentials:credentials:1.3.0" // UI implementation "androidx.appcompat:appcompat:$appCompatVersion" implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0' implementation "com.google.android.material:material:$materialVersion" implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion" implementation 'com.google.android.flexbox:flexbox:3.0.0' implementation "androidx.constraintlayout:constraintlayout:$constrainLayoutVersion" implementation "com.github.bumptech.glide:glide:$glideVersion" ksp "com.github.bumptech.glide:compiler:$glideVersion" implementation 'com.github.MikeOrtiz:TouchImageView:3.6' implementation "io.coil-kt:coil:$coilVersion" implementation "io.coil-kt:coil-compose:$coilVersion" // Compose implementation(platform("androidx.compose:compose-bom:$composeBom")) implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui-tooling") implementation("androidx.compose.material3:material3") implementation("androidx.activity:activity-compose:1.7.2") implementation("androidx.activity:activity-ktx:1.7.2") implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycleVersion" implementation "com.airbnb.android:lottie-compose:6.6.7" // Navigation implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion" implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion" // Database implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-runtime:$roomVersion" implementation "androidx.room:room-paging:$roomVersion" ksp "androidx.room:room-compiler:$roomVersion" // Prefs implementation "androidx.preference:preference-ktx:$preferenceVersion" implementation 'com.scottyab:secure-preferences-lib:0.1.7' implementation "androidx.datastore:datastore-preferences:$datastoreVersion" implementation "androidx.paging:paging-runtime-ktx:3.1.1" implementation 'androidx.multidex:multidex:2.0.1' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" // Firebase // Import the BoM for the Firebase platform implementation platform("com.google.firebase:firebase-bom:$firebaseVersion") implementation 'com.google.firebase:firebase-database-ktx:20.0.2' implementation 'com.google.firebase:firebase-auth-ktx' implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-inappmessaging-display' implementation 'com.google.firebase:firebase-installations' implementation 'com.google.firebase:firebase-messaging-ktx' // AppsFlyer SDK for deep linking implementation 'com.appsflyer:af-android-sdk:6.17.0' // Google Drive Dependencies implementation ('com.google.api-client:google-api-client-android:1.26.0') { exclude group: 'com.google.guava', module: 'guava-jdk5' } implementation('com.google.apis:google-api-services-drive:v3-rev173-1.25.0') { exclude group: 'com.google.guava', module: 'guava-jdk5' } implementation ('com.google.http-client:google-http-client-gson:1.26.0') { // do we need this exclude group: 'com.google.guava', module: 'guava-jdk5' } implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" // DI implementation "com.google.dagger:hilt-android:$hiltVersion" ksp "com.google.dagger:hilt-compiler:$hiltVersion" implementation "androidx.hilt:hilt-work:$hiltWorkVersion" implementation "androidx.hilt:hilt-navigation-compose:$hiltCompilerVersion" ksp "androidx.hilt:hilt-compiler:$hiltCompilerVersion" // Unit tests testImplementation "junit:junit:$junitVersion" testImplementation "io.mockk:mockk:1.13.8" testImplementation "androidx.arch.core:core-testing:$coreTestingVersion" testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion" testImplementation "com.squareup.okhttp3:mockwebserver:$ok_http_version" testImplementation "org.robolectric:robolectric:4.15.1" // Instrumental tests androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion" androidTestImplementation "androidx.room:room-testing:$roomVersion" androidTestImplementation "androidx.test.ext:junit:$junitExtVersion" androidTestImplementation('androidx.test:runner:1.3.0') { exclude group: 'com.android.support', module: 'support-annotations' } androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0') { exclude group: 'com.google.code.findbugs', module: 'jsr305' exclude group: 'com.android.support', module: 'support-annotations' } androidTestImplementation('androidx.test.espresso:espresso-intents:3.3.0') { exclude group: 'com.google.code.findbugs', module: 'jsr305' exclude group: 'com.android.support', module: 'support-annotations' } // DI for instrumentation tests androidTestImplementation "com.google.dagger:hilt-android-testing:$hiltVersion" kspAndroidTest "com.google.dagger:hilt-compiler:$hiltVersion" // DI for local unit tests testImplementation "com.google.dagger:hilt-android-testing:$hiltVersion" kspTest "com.google.dagger:hilt-compiler:$hiltVersion" } hilt { enableAggregatingTask = true } ext { archivesBaseName = 'dash-wallet' } def props = new Properties() if (file("../service.properties").exists()) { file("../service.properties").withInputStream { props.load(it) } } def localProps = new Properties() if (file("../local.properties").exists()) { file("../local.properties").withInputStream { localProps.load(it) } } def sakuraSporkAddress = providers.gradleProperty("sakuraSporkAddress") .getOrElse(localProps.getProperty("sakuraSporkAddress", "")) def sakuraCorePort = providers.gradleProperty("sakuraCorePort").getOrElse("20001").toInteger() def validateSakuraConfiguration = tasks.register("validateSakuraConfiguration") { doLast { if (sakuraSporkAddress.trim().isEmpty()) { throw new GradleException("Set sakuraSporkAddress to Sakura's public spork address before building devnet") } if (sakuraCorePort < 1 || sakuraCorePort > 65535) { throw new GradleException("sakuraCorePort must be between 1 and 65535") } } } tasks.configureEach { if (name.startsWith("preDevnet") && name.endsWith("Build")) { dependsOn(validateSakuraConfiguration) } } // Year of the most recent commit on the current branch, used for the copyright notice. // Uses providers.exec so it stays compatible with the Gradle configuration cache. // Falls back to the current year if git is unavailable (e.g. building from a source tarball). def commitYear try { def out = providers.exec { workingDir = rootDir commandLine 'git', 'log', '-1', '--format=%cd', '--date=format:%Y' }.standardOutput.asText.get().trim() commitYear = (out ==~ /\d{4}/) ? out : new Date().format('yyyy') } catch (Exception ignored) { commitYear = new Date().format('yyyy') } // Short commit hash of HEAD, shown on the About screen in debug builds so // testers can verify exactly which build is installed. Same // configuration-cache-safe pattern as commitYear; falls back to "unknown". def gitCommit try { def out = providers.exec { workingDir = rootDir commandLine 'git', 'rev-parse', '--short', 'HEAD' }.standardOutput.asText.get().trim() gitCommit = (out ==~ /[0-9a-f]{7,12}/) ? out : "unknown" } catch (Exception ignored) { gitCommit = "unknown" } android { android.ndkVersion '21.3.6528147' namespace "de.schildbach.wallet_test" compileSdk 36 defaultConfig { minSdkVersion 29 targetSdkVersion 36 // version code: MMmmppbb; MM = Major Version, mm = minor version, pp == patch version, bb = build versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 12000019 versionName project.hasProperty('versionName') ? project.property('versionName') : "12.0.0-sync" multiDexEnabled true generatedDensities = ['hdpi', 'xhdpi'] vectorDrawables.useSupportLibrary = true // 64-bit only: the Kotlin SDK's native core (Halo2/Orchard) cannot build 32-bit, // and Platform features were already disabled on 32-bit devices. // QA builds pass -PqaArm64 to drop the x86_64 native lib (~65 MB) — the QA // devices are all arm64, so this halves the native payload and the upload size. // Default (prod, x86_64 emulators) keeps both ABIs. ndk { if (project.hasProperty('qaArm64')) { abiFilters 'arm64-v8a' } else { abiFilters 'arm64-v8a', 'x86_64' } } testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ksp { arg("room.schemaLocation", "$projectDir/schemas") } buildConfigField("String", "UPHOLD_CLIENT_ID", "\"UPHOLD_CLIENT_ID\"") buildConfigField("String", "UPHOLD_CLIENT_SECRET", "\"UPHOLD_CLIENT_SECRET\"") buildConfigField("String", "SUPPORT_EMAIL", "\"\"") buildConfigField("String", "COINBASE_CLIENT_ID", "\"COINBASE_CLIENT_ID\"") buildConfigField("String", "COINBASE_CLIENT_SECRET", "\"COINBASE_CLIENT_SECRET\"") def supportEmail = localProps.getProperty("SUPPORT_EMAIL") if (supportEmail != null) { buildConfigField("String", "SUPPORT_EMAIL", "\"$supportEmail\"") } else if(System.getenv("SUPPORT_EMAIL") != null) { buildConfigField("String", "SUPPORT_EMAIL", "\"${System.getenv("SUPPORT_EMAIL")}\"") } buildConfigField("String", "DASHJ_VERSION", "\"$dashjVersion\"") buildConfigField("String", "DASH_SDK_VERSION", "\"$dashSdkVersion\"") buildConfigField("int", "COMMIT_YEAR", "$commitYear") buildConfigField("String", "GIT_COMMIT", "\"$gitCommit\"") buildConfigField("String", "SAKURA_SPORK_ADDRESS", groovy.json.JsonOutput.toJson(sakuraSporkAddress)) buildConfigField("int", "SAKURA_CORE_PORT", sakuraCorePort.toString()) } buildTypes { all { def imgurClientId = props.getProperty("IMGUR_CLIENT_ID") def imgurClientSecret = props.getProperty("IMGUR_CLIENT_SECRET") if (imgurClientId == null) { imgurClientId = "\"IMGUR_CLIENT_ID\"" } if (imgurClientSecret == null) { imgurClientSecret = "\"IMGUR_CLIENT_SECRET\"" } buildConfigField("String", "IMGUR_CLIENT_ID", imgurClientId) buildConfigField("String", "IMGUR_CLIENT_SECRET", imgurClientSecret) } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg' testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg', 'proguardTest-rules.txt' } debug { multiDexEnabled true minifyEnabled false debuggable true def supportEmail = localProps.getProperty("INTERNAL_SUPPORT_EMAIL") if (supportEmail != null) { buildConfigField("String", "SUPPORT_EMAIL", "\"$supportEmail\"") } else if(System.getenv('INTERNAL_SUPPORT_EMAIL') != null) { buildConfigField("String", "SUPPORT_EMAIL", "\"${System.getenv('INTERNAL_SUPPORT_EMAIL')}\"") } } } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } test { java.srcDirs = ['test'] resources.srcDirs = ['test'] } androidTest { assets.srcDirs += "$projectDir/schemas" assets.srcDirs += "androidTest/assets" java.srcDirs = ['androidTest'] resources.srcDirs = ['androidTest/java'] res.srcDirs = ['androidTest/testNet3/res'] } prod { manifest.srcFile 'prod/AndroidManifest.xml' java.srcDirs += ['standard/src'] } _testNet3 { manifest.srcFile 'testNet3/AndroidManifest.xml' java.srcDirs += ['standard/src'] res.srcDirs = ["testNet3/res"] } staging { res.srcDirs = ["staging/res"] java.srcDirs += ['standard/src'] } devnet { res.srcDirs = ["devnet/res"] java.srcDirs += ['devnet/src'] } } flavorDimensions "default" productFlavors { all { buildConfigField("String", "DPP_VERSION", "\"${dppVersions[name]}\"") def coinbaseClientId = props.getProperty("COINBASE_CLIENT_ID", "\"COINBASE_CLIENT_ID\"") def coinbaseClientSecret = props.getProperty("COINBASE_CLIENT_SECRET", "\"COINBASE_CLIENT_SECRET\"") buildConfigField("String", "COINBASE_CLIENT_ID", coinbaseClientId) buildConfigField("String", "COINBASE_CLIENT_SECRET", coinbaseClientSecret) def appsFlyerId = props.getProperty("APPSFLYER_ID", "\"\"") def appsFlyerTemplateId = props.getProperty("APPSFLYER_TEMPLATE_ID", "\"\"") buildConfigField("String", "APPSFLYER_ID", appsFlyerId) buildConfigField("String", "APPSFLYER_TEMPLATE_ID", appsFlyerTemplateId) } prod { applicationId = "hashengineering.darkcoin.wallet" def upholdClientId = props.getProperty("UPHOLD_CLIENT_ID", "\"UPHOLD_CLIENT_ID\"") def upholdClientSecret = props.getProperty("UPHOLD_CLIENT_SECRET", "\"UPHOLD_CLIENT_SECRET\"") buildConfigField("String", "UPHOLD_CLIENT_ID", upholdClientId) buildConfigField("String", "UPHOLD_CLIENT_SECRET", upholdClientSecret) def topperKeyId = props.getProperty("TOPPER_KEY_ID", "\"TOPPER_KEY_ID\"") def topperWidgetId = props.getProperty("TOPPER_WIDGET_ID", "\"TOPPER_WIDGET_ID\"") def topperPrivateKey = props.getProperty("TOPPER_PRIVATE_KEY", "\"TOPPER_PRIVATE_KEY\"") buildConfigField("String", "TOPPER_KEY_ID", topperKeyId) buildConfigField("String", "TOPPER_WIDGET_ID", topperWidgetId) buildConfigField("String", "TOPPER_PRIVATE_KEY", topperPrivateKey) def zenLedgerClientId = props.getProperty("ZENLEDGER_CLIENT_ID", "\"\"") def zenLedgerClientSecret = props.getProperty("ZENLEDGER_CLIENT_SECRET", "\"\"") buildConfigField("String", "ZENLEDGER_CLIENT_ID", zenLedgerClientId) buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", zenLedgerClientSecret) def appsFlyerTemplateId = props.getProperty("APPSFLYER_TEMPLATE_ID", "\"\"") buildConfigField("String", "APPSFLYER_TEMPLATE_ID", appsFlyerTemplateId) buildConfigField("String", "APPSFLYER_BRAND_DOMAIN", "\"dashpay.onelink.me\"") } _testNet3 { applicationId = "hashengineering.darkcoin.wallet_test" def upholdClientId = props.getProperty("UPHOLD_CLIENT_ID_SANDBOX", "\"UPHOLD_CLIENT_ID\"") def upholdClientSecret = props.getProperty("UPHOLD_CLIENT_SECRET_SANDBOX", "\"UPHOLD_CLIENT_SECRET\"") buildConfigField("String", "UPHOLD_CLIENT_ID", upholdClientId) buildConfigField("String", "UPHOLD_CLIENT_SECRET", upholdClientSecret) def topperKeyId = props.getProperty("TOPPER_KEY_ID_SANDBOX", "\"TOPPER_KEY_ID\"") def topperWidgetId = props.getProperty("TOPPER_WIDGET_ID_SANDBOX", "\"TOPPER_WIDGET_ID\"") def topperPrivateKey = props.getProperty("TOPPER_PRIVATE_KEY_SANDBOX", "\"TOPPER_PRIVATE_KEY\"") buildConfigField("String", "TOPPER_KEY_ID", topperKeyId) buildConfigField("String", "TOPPER_WIDGET_ID", topperWidgetId) buildConfigField("String", "TOPPER_PRIVATE_KEY", topperPrivateKey) buildConfigField("String", "ZENLEDGER_CLIENT_ID", "\"\"") buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", "\"\"") def appsFlyerTemplateId = props.getProperty("APPSFLYER_TEMPLATE_ID_TESTNET", "\"\"") buildConfigField("String", "APPSFLYER_TEMPLATE_ID", appsFlyerTemplateId) buildConfigField("String", "APPSFLYER_BRAND_DOMAIN", "\"dashpaytest.onelink.me\"") } staging { applicationId = "org.dash.dashpay.testnet" def upholdClientId = props.getProperty("UPHOLD_CLIENT_ID_SANDBOX") def upholdClientSecret = props.getProperty("UPHOLD_CLIENT_SECRET_SANDBOX") if (upholdClientId == null) { upholdClientId = "\"UPHOLD_CLIENT_ID\"" } if (upholdClientSecret == null) { upholdClientSecret = "\"UPHOLD_CLIENT_SECRET\"" } buildConfigField("String", "UPHOLD_CLIENT_ID", upholdClientId) buildConfigField("String", "UPHOLD_CLIENT_SECRET", upholdClientSecret) def topperKeyId = props.getProperty("TOPPER_KEY_ID_SANDBOX", "\"TOPPER_KEY_ID\"") def topperWidgetId = props.getProperty("TOPPER_WIDGET_ID_SANDBOX", "\"TOPPER_WIDGET_ID\"") def topperPrivateKey = props.getProperty("TOPPER_PRIVATE_KEY_SANDBOX", "\"TOPPER_PRIVATE_KEY\"") buildConfigField("String", "TOPPER_KEY_ID", topperKeyId) buildConfigField("String", "TOPPER_WIDGET_ID", topperWidgetId) buildConfigField("String", "TOPPER_PRIVATE_KEY", topperPrivateKey) buildConfigField("String", "ZENLEDGER_CLIENT_ID", "\"\"") buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", "\"\"") def appsFlyerTemplateId = props.getProperty("APPSFLYER_TEMPLATE_ID_TESTNET", "\"\"") buildConfigField("String", "APPSFLYER_TEMPLATE_ID", appsFlyerTemplateId) buildConfigField("String", "APPSFLYER_BRAND_DOMAIN", "\"dashpaytest.onelink.me\"") } devnet { applicationId = "org.dash.wallet.devnet" def imgurClientId = props.getProperty("UPHOLD_CLIENT_ID_SANDBOX") def imgurClientSecret = props.getProperty("UPHOLD_CLIENT_SECRET_SANDBOX") if (imgurClientId == null) { imgurClientId = "\"UPHOLD_CLIENT_ID\"" } if (imgurClientSecret == null) { imgurClientSecret = "\"UPHOLD_CLIENT_SECRET\"" } buildConfigField("String", "UPHOLD_CLIENT_ID", "\"UPHOLD_CLIENT_ID\"") buildConfigField("String", "UPHOLD_CLIENT_SECRET", "\"UPHOLD_CLIENT_SECRET\"") def topperKeyId = props.getProperty("TOPPER_KEY_ID_SANDBOX", "\"TOPPER_KEY_ID\"") def topperWidgetId = props.getProperty("TOPPER_WIDGET_ID_SANDBOX", "\"TOPPER_WIDGET_ID\"") def topperPrivateKey = props.getProperty("TOPPER_PRIVATE_KEY_SANDBOX", "\"TOPPER_PRIVATE_KEY\"") buildConfigField("String", "TOPPER_KEY_ID", topperKeyId) buildConfigField("String", "TOPPER_WIDGET_ID", topperWidgetId) buildConfigField("String", "TOPPER_PRIVATE_KEY", topperPrivateKey) buildConfigField("String", "ZENLEDGER_CLIENT_ID", "\"\"") buildConfigField("String", "ZENLEDGER_CLIENT_SECRET", "\"\"") buildConfigField("String", "APPSFLYER_BRAND_DOMAIN", "\"dashpaytest.onelink.me\"") } } packaging { jniLibs { excludes += [ // android libscrypt.so is in dashj-x11-android 'lib/x86_64/freebsd/libscrypt.so', 'lib/x86_64/linux/libscrypt.so', 'lib/x86_64/darwin/libscrypt.dylib', '**/lib/x86_64/darwin/libscrypt.dylib', 'root/lib/x86_64/darwin/libscrypt.dylib', //'**/lib/**', // 32-bit Platform SDK is not supported 'lib/x86/libsdklib.so', 'lib/armeabi-v7a/libsdklib.so' ] } resources { excludes += [ 'com/google/thirdparty/publicsuffix/PublicSuffixPatterns.gwt.xml', 'com/google/thirdparty/publicsuffix/PublicSuffixType.gwt.xml', 'org/bitcoinj/crypto/mnemonic/wordlist/english.txt', 'org/bitcoinj/crypto/cacerts', 'org.bitcoin.production.checkpoints.txt', 'org.bitcoin.test.checkpoints.txt', 'google/protobuf/*.proto', 'META-INF/DEPENDENCIES', 'META-INF/AL2.0', 'META-INF/LGPL2.1', 'lib/**', 'root/lib/**' ] } } kotlinOptions { jvmTarget = "17" } compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } buildFeatures { viewBinding true compose true buildConfig true } composeOptions { kotlinCompilerExtensionVersion = "1.5.14" } testOptions { unitTests.includeAndroidResources = true unitTests.returnDefaultValues = true unitTests.all { maxHeapSize = "2g" } } lint { abortOnError false disable 'MissingTranslation' disable 'NullSafeMutableLiveData' } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn" } } } // Declared after the android {} block so the flavor-scoped configurations // (prodImplementation, _testNet3Implementation, ...) exist. Each flavor pulls the // dashj-platform SDK version mapped in ext.dppVersions above. dependencies { dppVersions.each { flavor, ver -> ["java", "kotlin", "android"].each { artifact -> "${flavor}Implementation"("org.dashj.platform:dash-sdk-$artifact:$ver") } } } // --------------------------------------------------------------------------- // Covariant java.nio buffer patch (fixes NoSuchMethodError crash on Android <= 15) // // dashj-core 22.x is compiled with a modern JDK without `--release 8`, so javac // binds e.g. SPVBlockStore's `buffer.position(int)` call to the JDK-13 covariant // override `MappedByteBuffer.position(I)Ljava/nio/MappedByteBuffer;`. Android's // libcore does NOT declare the covariant java.nio buffer overrides up to and // including API 35 (android.jar 35: MappedByteBuffer.position(int) still returns // java.nio.Buffer), so on those devices ART throws // java.lang.NoSuchMethodError: No virtual method position(I)Ljava/nio/MappedByteBuffer; // from SPVBlockStore.getChainHead, crash-looping BlockchainServiceImpl and // killing sync on Android <= 15. Neither D8 (verified: 8.7.18 / 8.9.35 / 8.13.19) // nor any desugar_jdk_libs release (verified: 1.1.5, 2.1.5, 2.1.5-nio) retargets // these invokes, so we patch the dependency bytecode at build time instead. // // The transform rewrites, in every external jar on this module's classpaths, // invokevirtual java/nio/.{position(I)|limit(I)|mark()|reset()| // clear()|flip()|rewind()} : L; // to the API-1 base declaration // invokevirtual java/nio/Buffer. : Ljava/nio/Buffer; + checkcast // which is exactly the call shape javac emits with `--release 8`. Jars without // matching call sites are passed through untouched. // --------------------------------------------------------------------------- @CacheableTransform abstract class NioCovariantBufferPatch implements TransformAction { // Methods declared on java.nio.Buffer since API 1 that JDK 9/13 re-declared on // the typed buffer subclasses with covariant return types (absent on Android <= 15). private static final Map RETARGETABLE_ARGS = [ 'position': '(I)', 'limit' : '(I)', 'mark' : '()', 'reset' : '()', 'clear' : '()', 'flip' : '()', 'rewind' : '()', ] private static final Set TYPED_NIO_BUFFERS = [ 'java/nio/MappedByteBuffer', 'java/nio/ByteBuffer', 'java/nio/CharBuffer', 'java/nio/DoubleBuffer', 'java/nio/FloatBuffer', 'java/nio/IntBuffer', 'java/nio/LongBuffer', 'java/nio/ShortBuffer', ] as Set @Classpath @InputArtifact abstract Provider getInputArtifact() @Override void transform(TransformOutputs outputs) { File input = inputArtifact.get().asFile // Never touch Android platform/bootstrap jars - they legitimately contain // (and define) the java.nio classes themselves. boolean platformJar = input.name == 'android.jar' || input.name.startsWith('core-for-system-modules') || input.name.startsWith('core-lambda-stubs') if (!input.isFile() || !input.name.endsWith('.jar') || platformJar) { outputs.file(input) return } // First pass: read entries, patching classes that contain covariant calls. Map patchedEntries = [:] List rewrites = [] new ZipFile(input).withCloseable { zip -> zip.entries().each { entry -> if (entry.directory || !entry.name.endsWith('.class') || entry.name.startsWith('java/') || entry.name.startsWith('javax/')) { return } byte[] bytes = zip.getInputStream(entry).withCloseable { it.bytes } // Cheap pre-filter: the constant pool must name a typed buffer class. String haystack = new String(bytes, java.nio.charset.StandardCharsets.ISO_8859_1) if (!TYPED_NIO_BUFFERS.any { haystack.contains(it) }) { return } try { byte[] patched = rewriteClass(bytes, entry.name, rewrites) if (patched != null) { patchedEntries[entry.name] = patched } } catch (Throwable t) { // Unparseable class (exotic version etc.) - leave it untouched. System.err.println("NioCovariantBufferPatch: skipped ${input.name}!${entry.name}: $t") } } } if (patchedEntries.isEmpty()) { outputs.file(input) return } System.out.println( "NioCovariantBufferPatch: patched ${rewrites.size()} covariant java.nio call site(s) " + "in ${input.name}: ${rewrites.toSorted().toUnique().join(', ')}" ) // Second pass: copy the jar, substituting patched classes and dropping any // now-stale signature files. File outFile = outputs.file(input.name) Set seen = [] new ZipFile(input).withCloseable { zip -> new ZipOutputStream(outFile.newOutputStream()).withCloseable { zos -> zip.entries().each { entry -> String name = entry.name if (!seen.add(name)) { return // malformed duplicate entry } if (name ==~ /META-INF\/[^\/]+\.(SF|RSA|DSA|EC)/) { return // signature invalidated by patching } ZipEntry out = new ZipEntry(name) out.time = entry.time zos.putNextEntry(out) if (!entry.directory) { byte[] bytes = patchedEntries[name] ?: zip.getInputStream(entry).withCloseable { it.bytes } zos.write(bytes) } zos.closeEntry() } } } } /** * Returns patched class bytes, or null if the class has no covariant buffer calls. * Not private: Gradle instantiates a decorated subclass, and Groovy's dynamic * dispatch from the closure inside transform() cannot reach private members of * the base class through it. */ protected static byte[] rewriteClass(byte[] classBytes, String entryName, List rewrites) { ClassReader reader = new ClassReader(classBytes) ClassWriter writer = new ClassWriter(reader, 0) boolean[] changed = [false] ClassVisitor visitor = new ClassVisitor(Opcodes.ASM9, writer) { @Override MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions) return new MethodVisitor(Opcodes.ASM9, mv) { @Override void visitMethodInsn(int opcode, String owner, String mName, String mDesc, boolean isInterface) { String args = RETARGETABLE_ARGS[mName] if (opcode == Opcodes.INVOKEVIRTUAL && !isInterface && args != null && TYPED_NIO_BUFFERS.contains(owner) && mDesc == "${args}L${owner};") { // e.g. MappedByteBuffer.position(I)LMappedByteBuffer; // -> Buffer.position(I)LBuffer; + checkcast MappedByteBuffer super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, 'java/nio/Buffer', mName, "${args}Ljava/nio/Buffer;", false) super.visitTypeInsn(Opcodes.CHECKCAST, owner) changed[0] = true rewrites.add("${entryName}: ${owner.substring(owner.lastIndexOf('/') + 1)}.${mName}${args}".toString()) return } super.visitMethodInsn(opcode, owner, mName, mDesc, isInterface) } } } } reader.accept(visitor, 0) return changed[0] ? writer.toByteArray() : null } } def nioCovariantPatched = Attribute.of('nioCovariantBufferPatched', Boolean) dependencies { attributesSchema { attribute(nioCovariantPatched) } artifactTypes { jar { attributes.attribute(nioCovariantPatched, false) } } registerTransform(NioCovariantBufferPatch) { from.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, 'jar') .attribute(nioCovariantPatched, false) to.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, 'jar') .attribute(nioCovariantPatched, true) } } configurations.configureEach { conf -> if (conf.canBeResolved) { conf.attributes.attribute(nioCovariantPatched, true) } } apply from: file("../gradle/google-services.gradle") // Generate a SHA-256 checksum file next to each assembled APK. // For every APK output, a ".sha256" file is written in the same folder, // in sha256sum format (" "), so it can be verified with: // sha256sum -c dash-wallet-.apk.sha256 // This runs automatically as a finalizer of each assemble task. android.applicationVariants.all { variant -> // One task per variant covering all of its APK outputs, so ABI/density splits // do not attempt to register the same task name more than once. Only plain // values (variant name, File list) are captured, keeping the task closures // compatible with the configuration cache. def variantName = variant.name def apkFiles = variant.outputs.collect { it.outputFile } def sha256Task = tasks.register("generate${variantName.capitalize()}ApkSha256") { description = "Writes a SHA-256 checksum file next to each ${variantName} APK" onlyIf { apkFiles.any { it.exists() } } doLast { apkFiles.each { apkFile -> if (!apkFile.exists()) { logger.warn("Skipping checksum for missing APK: ${apkFile}") return } def digest = java.security.MessageDigest.getInstance("SHA-256") apkFile.withInputStream { stream -> def buffer = new byte[8192] int read while ((read = stream.read(buffer)) != -1) { digest.update(buffer, 0, read) } } def hex = digest.digest().encodeHex().toString() def shaFile = new File(apkFile.parentFile, "${apkFile.name}.sha256") shaFile.text = "${hex} ${apkFile.name}\n" logger.lifecycle("SHA-256 (${apkFile.name}): ${hex}") logger.lifecycle("Wrote checksum to ${shaFile}") } } } // A finalizer only runs when the finalized task actually executes, and the // assemble lifecycle task is skipped whenever one of its dependencies // (e.g. package) fails, so a stale APK left over from a failed build // is never checksummed as if it were the new artifact. variant.assembleProvider.configure { finalizedBy(sha256Task) } }