From f38b377edc19fb9d32c206e94b4ca17a6903246b Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Tue, 24 Sep 2024 18:41:30 -0300 Subject: [PATCH 1/8] chore: rename build.gradle to build.gradle.kts --- android/{build.gradle => build.gradle.kts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename android/{build.gradle => build.gradle.kts} (100%) diff --git a/android/build.gradle b/android/build.gradle.kts similarity index 100% rename from android/build.gradle rename to android/build.gradle.kts From 45a61b7e22efe4529aae345ad64eef24b414d552 Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Tue, 24 Sep 2024 22:24:19 -0300 Subject: [PATCH 2/8] feat: Migrate build configuration from goovy DSL to Kotlin DSL --- android/build.gradle.kts | 47 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 54a2175e4..06613aae0 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -1,33 +1,30 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext { - buildToolsVersion = "34.0.0" - minSdkVersion = 24 - compileSdkVersion = 34 - targetSdkVersion = 34 - ndkVersion = "23.2.8568313" - kotlinVersion = '1.9.0' - } - repositories { - google() - mavenCentral() - } - dependencies { - classpath('com.android.tools.build:gradle:8.1.1') - classpath("com.facebook.react:react-native-gradle-plugin") - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - } + val kotlinVersion = "1.9.0" + val buildToolsVersion = "34.0.0" + val minSdkVersion = 24 + val compileSdkVersion = 34 + val targetSdkVersion = 34 + val ndkVersion = "23.2.8568313" + + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:8.1.1") + classpath("com.facebook.react:react-native-gradle-plugin") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + } } allprojects { - repositories { - google() - maven { - url("$rootDir/../node_modules/detox/Detox-android") - } - maven { url 'https://www.jitpack.io' } - } + repositories { + google() + maven("$rootDir/../node_modules/detox/Detox-android") + maven("https://www.jitpack.io") + } } // this is not the best solution, but while the libraries have no namespace... @@ -43,4 +40,4 @@ allprojects { // } // } // } -//} \ No newline at end of file +//} From 700a5b57b6edfa699d1f28dec6ea598857057f01 Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Tue, 24 Sep 2024 22:52:18 -0300 Subject: [PATCH 3/8] chore: rename build.gradle to build.gradle.kts inside app --- android/app/{build.gradle => build.gradle.kts} | 0 android/gradle.properties | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename android/app/{build.gradle => build.gradle.kts} (100%) diff --git a/android/app/build.gradle b/android/app/build.gradle.kts similarity index 100% rename from android/app/build.gradle rename to android/app/build.gradle.kts diff --git a/android/gradle.properties b/android/gradle.properties index ac3fd9b55..754b8082d 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -15,7 +15,7 @@ org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1024m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true +org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app's APK From 6baefa8d71bce7de632756fcafc47593207543e6 Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Wed, 25 Sep 2024 00:01:50 -0300 Subject: [PATCH 4/8] fix: migrate plugins to Kotlin DSL --- android/app/build.gradle.kts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 8f360dc76..19a627fec 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,7 +1,6 @@ -apply plugin: 'com.android.application' -apply plugin: 'com.facebook.react' -apply plugin: 'kotlin-android' - +apply(plugin = "com.android.application") +apply(plugin = "com.facebook.react") +apply(plugin = "kotlin-android") /** * This is the configuration block to customize your React Native Android app. @@ -83,7 +82,7 @@ ext.splitApk = project.properties['splitApk'] ?: false ext.includeUniversalApk = project.properties['includeUniversalApk'] ?: false android { - ndkVersion rootProject.ext.ndkVersion + ndkVersion rootProject.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion From 529e2d01ffff4268a8d851885fe79eeee25f58ed Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Thu, 26 Sep 2024 14:01:44 -0300 Subject: [PATCH 5/8] fix: change syntax to kotlin DSL --- android/app/build.gradle.kts | 131 ++++++++++++++++++++--------------- android/build.gradle.kts | 16 +++-- 2 files changed, 85 insertions(+), 62 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 19a627fec..b0a1f2b24 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -54,7 +54,7 @@ react { /** * Set this to true to Run Proguard on Release builds to minify the Java bytecode. */ -def enableProguardInReleaseBuilds = false +var enableProguardInReleaseBuilds = false /** * The preferred build flavor of JavaScriptCore (JSC). @@ -67,7 +67,7 @@ def enableProguardInReleaseBuilds = false * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default. */ -def jscFlavor = 'org.webkit:android-jsc:+' +var jscFlavor = "org.webkit:android-jsc:+" /** * Whether to enable building a separate APK for each ABI. @@ -82,46 +82,47 @@ ext.splitApk = project.properties['splitApk'] ?: false ext.includeUniversalApk = project.properties['includeUniversalApk'] ?: false android { - ndkVersion rootProject.ndkVersion - compileSdkVersion rootProject.ext.compileSdkVersion + var ndkVersion = rootProject.extra["ndkVersion"] + var compileSdkVersion = rootProject.extra["compileSdkVersion"] + + namespace = "org.ZingoLabs.Zingo" //fun ? - namespace 'org.ZingoLabs.Zingo' compileOptions { sourceCompatibility = "18.0.2.1" targetCompatibility = "18.0.2.1" } kotlinOptions { - jvmTarget = '18' + jvmTarget = "18" } defaultConfig { - applicationId 'org.ZingoLabs.Zingo' // Real - minSdkVersion rootProject.ext.minSdkVersion - targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 187 // Real - versionName "zingo-1.4.3" // Real - missingDimensionStrategy 'react-native-camera', 'general' - testBuildType System.getProperty('testBuildType', 'debug') - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + applicationId = namespace // Real + minSdkVersion = rootProject.extra["minSdkVersion"] + targetSdkVersion = rootProject.extra["targetSdkVersion"] + versionCode = 187 // Real + versionName = "zingo-1.4.3" // Real + missingDimensionStrategy("react-native-camera", "general") + testBuildType(System.getProperty("testBuildType", "debug")) + testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner") } splits { abi { - enable splitApk.toBoolean() + enable(splitApk.toBoolean()) reset() - include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" - universalApk includeUniversalApk.toBoolean() + include("armeabi-v7a", "x86", "arm64-v8a", "x86_64") + universalApk(includeUniversalApk.toBoolean()) } } signingConfigs { debug { storeFile file('debug.keystore') - storePassword 'android' - keyAlias 'androiddebugkey' - keyPassword 'android' + storePassword("android") + keyAlias("androiddebugkey") + keyPassword("android") } } @@ -133,14 +134,14 @@ android { buildTypes { debug { - signingConfig signingConfigs.debug + signingConfig(signingConfigs.debug) } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. - signingConfig signingConfigs.debug - minifyEnabled enableProguardInReleaseBuilds - proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + signingConfig(signingConfigs.debug) + minifyEnabled(enableProguardInReleaseBuilds) + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") } } @@ -177,42 +178,60 @@ android { // Map for the version code that gives each ABI a value. -ext.abiCodes = ['armeabi-v7a':1, 'x86':2, 'arm64-v8a': 3, 'x86_64':4] + +extra.set( + "abiCodes", + mapOf( + "armeabi-v7a" to 1, + "x86" to 2, + "arm-v8a" to 3, + "x86_64" to 4 + ) +) +//ext.abiCodes = [armeabi-v7a':1, 'x86':2, 'arm64-v8a': 3, 'x86_64':4] // For each APK output variant, override versionCode with a combination of // ext.abiCodes * 10000 + variant.versionCode. // variant.versionCode is equal to defaultConfig.versionCode. // If you configure product flavors that define their own versionCode, // variant.versionCode uses that value instead. -android.applicationVariants.all { variant -> - variant.outputs.each { output -> - def baseAbiVersionCode = project.ext.abiCodes.get(output.getFilter(com.android.build.OutputFile.ABI)) - - // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes, - // the following code doesn't override the version code for universal APKs. - // However, because you want universal APKs to have the lowest version code, - // this outcome is desirable. - if (baseAbiVersionCode != null) { - - // Assigns the new version code to versionCodeOverride, which changes the - // version code for only the output APK, not for the variant itself. Skipping - // this step causes Gradle to use the value of variant.versionCode for the APK. - output.versionCodeOverride = baseAbiVersionCode * 10000 + variant.versionCode +android.applicationVariants.all { + outputs.all { + val output = this + if (output != null) { + val baseAbiVersionCode = (project.extra["abiCodes"] as Map) + .get(output.getFilter(com.android.build.OutputFile.ABI)) + + // Because abiCodes.get() returns null for ABIs that are not mapped by extra["abiCodes"], + // the following code doesn't override the version code for universal APKs. + // However, because you want universal APKs to have the lowest version code, + // this outcome is desirable. + if (baseAbiVersionCode != null) { + // Assigns the new version code to versionCodeOverride, which changes the + // version code for only the output APK, not for the variant itself. Skipping + // this step causes Gradle to use the value of variant.versionCode for the APK. + output.versionCodeOverride = baseAbiVersionCode * 10000 + versionCode + } + } } - } } -android.applicationVariants.all { variant -> - def t = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) { - workingDir "${rootProject.projectDir}/../rust" - // Runs the bindings generation, note that you must have uniffi-bindgen installed and in your PATH environment variable - commandLine 'cargo', 'run', '--release', '--features=uniffi/cli', '--bin', 'uniffi-bindgen', - 'generate', '../rust/lib/src/zingo.udl', '--language', 'kotlin', - '--out-dir', "${buildDir}/generated/source/uniffi/${variant.name}/java" +android.applicationVariants.all { + val variant = this + val taskName = "generate${variant.name.capitalize()}UniFFIBindings" + val task = tasks.register(taskName) { + workingDir("${rootProject.projectDir}/../rust") + // Runs the binding as? com.android.build.gradle.internal.api.BaseVariantOutputImpls generation, note that you must have uniffi-bindgen installed and in your PATH environment variable + commandLine( + "cargo", "run", "--release", "--features=uniffi/cli", "--bin", "uniffi-bindgen", + "generate", "../rust/lib/src/zingo.udl", "--language", "kotlin", + "--out-dir", "${buildDir}/generated/source/uniffi/${variant.name}/java" + ) } - variant.javaCompileProvider.get().dependsOn(t) - def sourceSet = variant.sourceSets.find { it.name == variant.name } - sourceSet.java.srcDir new File(buildDir, "generated/source/uniffi/${variant.name}/java") + variant.javaCompileProvider.get().dependsOn(task) + val sourceSet = variant.sourceSets.find { it.name == variant.name } + sourceSet?.java?.srcDir(File(buildDir, "generated/source/uniffi/${variant.name}/java")) + // XXX: I've been trying to make this work but I can't, so the compiled bindings will show as "regular sources" in Android Studio. //idea.module.generatedSourceDirs += file("${buildDir}/generated/source/uniffi/${variant.name}/java/uniffi") } @@ -221,19 +240,19 @@ dependencies { // The version of react-native is set by the React Native Gradle Plugin implementation("com.facebook.react:react-android") - androidTestImplementation('com.wix:detox:+') - implementation 'androidx.appcompat:appcompat:1.1.0' + androidTestImplementation("com.wix:detox:+") + implementation("androidx.appcompat:appcompat:1.1.0") - implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" - implementation 'com.facebook.soloader:soloader:0.10.5+' + implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0") + implementation("com.facebook.soloader:soloader:0.10.5+") // Detox tests getAttributes() needs this - debugImplementation('com.google.android.material:material:1.2.1') + debugImplementation("com.google.android.material:material:1.2.1") debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { - exclude group:'com.squareup.okhttp3', module:'okhttp' + exclude group:"com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") diff --git a/android/build.gradle.kts b/android/build.gradle.kts index 06613aae0..ae58e5d16 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -1,12 +1,16 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - val kotlinVersion = "1.9.0" - val buildToolsVersion = "34.0.0" - val minSdkVersion = 24 - val compileSdkVersion = 34 - val targetSdkVersion = 34 - val ndkVersion = "23.2.8568313" + extra.apply { + set("kotlinVersion", "1.9.0") + set("buildToolsVersion", "34.0.0") + set("minSdkVersion", 24) + set("compileSdkVersion", 34) + set("targetSdkVersion", 34) + set("ndkVersion", "23.2.8568313") + } + + val kotlinVersion = extra["kotlinVersion"] repositories { google() From 4179314f96e0944bea05a22bcd667fe25a3221c5 Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Thu, 26 Sep 2024 21:16:38 -0300 Subject: [PATCH 6/8] fix: add lazy evaluation and improved code clarity --- android/app/build.gradle.kts | 86 +++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index b0a1f2b24..331056904 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,6 +1,8 @@ -apply(plugin = "com.android.application") -apply(plugin = "com.facebook.react") -apply(plugin = "kotlin-android") +plugins { + id("com.android.application") + id("com.facebook.react") + id("kotlin-android") +} /** * This is the configuration block to customize your React Native Android app. @@ -17,8 +19,7 @@ react { // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js // cliFile = file("../node_modules/react-native/cli.js") - /* Variants */ - // The list of variants to that are debuggable. For those we're going to + /* Variants */ // The list of variants to that are debuggable. For those we're going to // skip the bundling of the JS bundle and the assets. By default is just 'debug'. // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. // debuggableVariants = ["liteDebug", "prodDebug"] @@ -78,19 +79,26 @@ var jscFlavor = "org.webkit:android-jsc:+" * Additional option to include a universal APK * e.g. ./gradlew assembleRelease -PsplitApk=true -PincludeUniversalApk=true */ -ext.splitApk = project.properties['splitApk'] ?: false -ext.includeUniversalApk = project.properties['includeUniversalApk'] ?: false +//val splitApk = rootProject.findProperty("splitApk")?.toString().toBoolean()?: false +val splitApk by lazy { + (project.findProperty("splitApk") as? String)?.toBoolean() ?: false +} -android { +val includeUniversalApk by lazy { + (project.findProperty("includeUniversalApk") as?String)?.toBoolean() ?: false +} - var ndkVersion = rootProject.extra["ndkVersion"] - var compileSdkVersion = rootProject.extra["compileSdkVersion"] +android { + var _ndkVersion = rootProject.extra["ndkVersion"] + var _compileSdkVersion = rootProject.extra["compileSdkVersion"] + var _minSdkVersion = rootProject.extra["minSdkVersion"] + var _targetSdkVersion = rootProject.extra["targetSdkVersion"] namespace = "org.ZingoLabs.Zingo" //fun ? compileOptions { - sourceCompatibility = "18.0.2.1" - targetCompatibility = "18.0.2.1" + sourceCompatibility = JavaVersion.toVersion("18.0.2.1") + targetCompatibility = JavaVersion.toVersion("18.0.2.1") } kotlinOptions { @@ -98,22 +106,23 @@ android { } defaultConfig { - applicationId = namespace // Real - minSdkVersion = rootProject.extra["minSdkVersion"] - targetSdkVersion = rootProject.extra["targetSdkVersion"] + applicationId = namespace // Real + minSdkVersion(_minSdkVersion as Int) + targetSdkVersion(_targetSdkVersion as Int) + versionCode = 187 // Real versionName = "zingo-1.4.3" // Real missingDimensionStrategy("react-native-camera", "general") - testBuildType(System.getProperty("testBuildType", "debug")) - testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner") + testBuildType = System.getProperty("testBuildType", "debug") + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } splits { abi { - enable(splitApk.toBoolean()) + isEnable = splitApk reset() include("armeabi-v7a", "x86", "arm64-v8a", "x86_64") - universalApk(includeUniversalApk.toBoolean()) + isUniversalApk = includeUniversalApk } } @@ -252,7 +261,10 @@ dependencies { debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { - exclude group:"com.squareup.okhttp3', module:'okhttp' + exclude( + group="com.squareup.okhttp3", + module="okhttp" + ) } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") @@ -260,46 +272,48 @@ dependencies { if (hermesEnabled.toBoolean()) { implementation("com.facebook.react:hermes-android") } else { - implementation jscFlavor + implementation(jscFlavor) } - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.5.0" + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0") - def work_version = "2.7.1" + val work_version = "2.7.1" // (Java only) - implementation "androidx.work:work-runtime:$work_version" + implementation("androidx.work:work-runtime:$work_version") // Kotlin + coroutines - implementation "androidx.work:work-runtime-ktx:$work_version" + implementation("androidx.work:work-runtime-ktx:$work_version") // optional - RxJava2 support - implementation "androidx.work:work-rxjava2:$work_version" + implementation("androidx.work:work-rxjava2:$work_version") // optional - GCMNetworkManager support - implementation "androidx.work:work-gcm:$work_version" + implementation("androidx.work:work-gcm:$work_version") // optional - Test helpers - androidTestImplementation "androidx.work:work-testing:$work_version" + androidTestImplementation("androidx.work:work-testing:$work_version") // optional - Multiprocess support - implementation "androidx.work:work-multiprocess:$work_version" + implementation("androidx.work:work-multiprocess:$work_version") // google truth testing framework - androidTestImplementation "com.google.truth:truth:1.1.3" + androidTestImplementation("com.google.truth:truth:1.1.3") // JSON parsing - implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.14.+" + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.+") // JUnit test runners - androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation("androidx.test.ext:junit:1.1.5") // Kotlin extensions for androidx.test.ext.junit - androidTestImplementation "androidx.test.ext:junit-ktx:1.1.5" + androidTestImplementation("androidx.test.ext:junit-ktx:1.1.5") // uniffi needs this - implementation "net.java.dev.jna:jna:5.9.0@aar" + implementation("net.java.dev.jna:jna:5.9.0@aar") } -apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +//apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) +apply(from = file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")) +project.extra.applyNativeModulesAppBuildGradle(project) From 5efdc62a42d38d5d4b4c3f308b281d728574252a Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Tue, 1 Oct 2024 16:53:11 -0300 Subject: [PATCH 7/8] fix: device types and build types --- android/app/build.gradle.kts | 119 ++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 52 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 331056904..b1f763b18 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -127,31 +127,44 @@ android { } signingConfigs { - debug { - storeFile file('debug.keystore') - storePassword("android") - keyAlias("androiddebugkey") - keyPassword("android") + create("debug") { + storeFile = file("debug.keystore") + storePassword = "android" + keyAlias = "androiddebugkey" + keyPassword = "android" } } packagingOptions { jniLibs { - pickFirsts += ['lib/armeabi-v7a/libc++_shared.so', 'lib/arm64-v8a/libc++_shared.so', 'lib/x86/libc++_shared.so', 'lib/x86_64/libc++_shared.so'] + pickFirsts.addAll( + listOf( + "lib/armeabi-v7a/libc++_shared.so", + "lib/arm64-v8a/libc++_shared.so", + "lib/x86/libc++_shared.so", + "lib/x86_64/libc++_shared.so" + ) + ) } } - buildTypes { - debug { - signingConfig(signingConfigs.debug) - } - release { + buildTypes { + getByName("release") { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. - signingConfig(signingConfigs.debug) - minifyEnabled(enableProguardInReleaseBuilds) - proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + signingConfig = signingConfigs.getByName("release") + + isMinifyEnabled = enableProguardInReleaseBuilds + proguardFiles( + getDefaultProguardFile("proguard-android.txt"), + "proguard-rules.pro" + ) } + /* + getByName("debug") { + signingConfig = signingConfig.getByName("debug") + } + */ } buildFeatures { @@ -162,13 +175,13 @@ android { // Managed devices for gradle integration testing managedDevices { devices { - pixel2api29_x86 (com.android.build.api.dsl.ManagedVirtualDevice) { + create("pixel2api29_x86") { device = "Pixel 2" apiLevel = 29 systemImageSource = "aosp" require64Bit = false } - pixel2api30_x86_64 (com.android.build.api.dsl.ManagedVirtualDevice) { + create("pixel2api30_x86_64") { //(com.android.build.api.dsl.ManagedVirtualDevice) { device = "Pixel 2" apiLevel = 30 systemImageSource = "aosp" @@ -176,9 +189,9 @@ android { } } groups { - x86_Archs { - targetDevices.add(devices.pixel2api29_x86) - targetDevices.add(devices.pixel2api30_x86_64) + create("x86_Archs") { + targetDevices.add(devices.getByName("pixel2api29_x86")) + targetDevices.add(devices.getByName("pixel2api30_x86_64")) } } } @@ -204,45 +217,47 @@ extra.set( // variant.versionCode is equal to defaultConfig.versionCode. // If you configure product flavors that define their own versionCode, // variant.versionCode uses that value instead. -android.applicationVariants.all { - outputs.all { - val output = this - if (output != null) { - val baseAbiVersionCode = (project.extra["abiCodes"] as Map) - .get(output.getFilter(com.android.build.OutputFile.ABI)) - - // Because abiCodes.get() returns null for ABIs that are not mapped by extra["abiCodes"], - // the following code doesn't override the version code for universal APKs. - // However, because you want universal APKs to have the lowest version code, - // this outcome is desirable. - if (baseAbiVersionCode != null) { - // Assigns the new version code to versionCodeOverride, which changes the - // version code for only the output APK, not for the variant itself. Skipping - // this step causes Gradle to use the value of variant.versionCode for the APK. - output.versionCodeOverride = baseAbiVersionCode * 10000 + versionCode +android { + applicationVariants.all { + val variant = this + outputs.map { output -> + if (output is com.android.build.gradle.internal.api.ApkVariantOutputImpl) { + val abiCodes: Map by project.extra + val baseAbiVersionCode = abiCodes[output.filters.find { it.filterType == "ABI" }?.identifier] + + baseAbiVersionCode?.let { baseCode -> + output.versionCodeOverride = baseCode * 10000 + (variant.versionCode ?: 0) + } } } } } -android.applicationVariants.all { - val variant = this - val taskName = "generate${variant.name.capitalize()}UniFFIBindings" - val task = tasks.register(taskName) { - workingDir("${rootProject.projectDir}/../rust") - // Runs the binding as? com.android.build.gradle.internal.api.BaseVariantOutputImpls generation, note that you must have uniffi-bindgen installed and in your PATH environment variable - commandLine( - "cargo", "run", "--release", "--features=uniffi/cli", "--bin", "uniffi-bindgen", - "generate", "../rust/lib/src/zingo.udl", "--language", "kotlin", - "--out-dir", "${buildDir}/generated/source/uniffi/${variant.name}/java" - ) +android { + applicationVariants.all { + val variant = this + val taskName = "generate${variant.name.capitalize()}UniFFIBindings" + + val task = tasks.register(taskName) { + workingDir("${rootProject.projectDir}/../rust") + commandLine( + "cargo", "run", "--release", "--features=uniffi/cli", "--bin", "uniffi-bindgen", + "generate", "../rust/lib/src/zingo.udl", "--language", "kotlin", + "--out-dir", "${buildDir}/generated/source/uniffi/${variant.name}/java" + ) + } + + variant.javaCompileProvider.get().dependsOn(task) + + variant.sourceSets.find { it.name == variant.name }?.let { sourceSet -> + sourceSet.java.srcDirs(sourceSet.java.srcDirs + File(buildDirs, "generated/source/uniffi/$variant.name/java")) + } + + // Note: The following line is commented out as it wasn't working in the original code + // project.extensions.getByType().sourceSets.getByName(variant.name) { + // kotlin.srcDir("${buildDir}/generated/source/uniffi/${variant.name}/java") + // } } - variant.javaCompileProvider.get().dependsOn(task) - val sourceSet = variant.sourceSets.find { it.name == variant.name } - sourceSet?.java?.srcDir(File(buildDir, "generated/source/uniffi/${variant.name}/java")) - - // XXX: I've been trying to make this work but I can't, so the compiled bindings will show as "regular sources" in Android Studio. - //idea.module.generatedSourceDirs += file("${buildDir}/generated/source/uniffi/${variant.name}/java/uniffi") } dependencies { From 808f519ee6bc08d28e6e1b45894387326a4150e9 Mon Sep 17 00:00:00 2001 From: sebastianlujan Date: Mon, 7 Oct 2024 13:06:43 -0300 Subject: [PATCH 8/8] fix: migration using Kotlin DSL --- android/app/build.gradle.kts | 68 ++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index b1f763b18..6bc55af3a 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -1,3 +1,5 @@ +import groovy.lang.Closure + plugins { id("com.android.application") id("com.facebook.react") @@ -127,12 +129,18 @@ android { } signingConfigs { - create("debug") { + getByName("debug") { storeFile = file("debug.keystore") - storePassword = "android" + storePassword = "androisigningConfigsd" keyAlias = "androiddebugkey" keyPassword = "android" } + create("release") { + storeFile = file("release.keystore") + storePassword = "androisigningConfigsd" + keyAlias = "androiddebugkey" + keyPassword = "androiddebugkey" + } } packagingOptions { @@ -212,6 +220,10 @@ extra.set( ) //ext.abiCodes = [armeabi-v7a':1, 'x86':2, 'arm64-v8a': 3, 'x86_64':4] +val FLIPPER_VERSION: String by project +val hermesEnabled: String by project +val kotlinVersion: String by project + // For each APK output variant, override versionCode with a combination of // ext.abiCodes * 10000 + variant.versionCode. // variant.versionCode is equal to defaultConfig.versionCode. @@ -225,7 +237,14 @@ android { val abiCodes: Map by project.extra val baseAbiVersionCode = abiCodes[output.filters.find { it.filterType == "ABI" }?.identifier] + // Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes, + // the following code doesn't override the version code for universal APKs. + // However, because you want universal APKs to have the lowest version code, + // this outcome is desirable. baseAbiVersionCode?.let { baseCode -> + // Assigns the new version code to versionCodeOverride, which changes the + // version code for only the output APK, not for the variant itself. Skipping + // this step causes Gradle to use the value of variant.versionCode for the APK. output.versionCodeOverride = baseCode * 10000 + (variant.versionCode ?: 0) } } @@ -236,28 +255,32 @@ android { android { applicationVariants.all { val variant = this - val taskName = "generate${variant.name.capitalize()}UniFFIBindings" + // val taskName = "generate${variant.name.capitalize()}UniFFIBindings" - val task = tasks.register(taskName) { - workingDir("${rootProject.projectDir}/../rust") - commandLine( - "cargo", "run", "--release", "--features=uniffi/cli", "--bin", "uniffi-bindgen", - "generate", "../rust/lib/src/zingo.udl", "--language", "kotlin", - "--out-dir", "${buildDir}/generated/source/uniffi/${variant.name}/java" - ) - } - - variant.javaCompileProvider.get().dependsOn(task) + // val task = tasks.register(taskName) { + // workingDir("${rootProject.projectDir}/../rust") + // commandLine( + // "cargo", "run", "--release", "--features=uniffi/cli", "--bin", "uniffi-bindgen", + // "generate", "../rust/lib/src/zingo.udl", "--language", "kotlin", + // "--out-dir", "${buildDir}/generated/source/uniffi/${variant.name}/java" + // ) + // } + // variant.javaCompileProvider.get().dependsOn(task) - variant.sourceSets.find { it.name == variant.name }?.let { sourceSet -> - sourceSet.java.srcDirs(sourceSet.java.srcDirs + File(buildDirs, "generated/source/uniffi/$variant.name/java")) - } + val sourceSet = variant.sourceSets.find { it.name == name } + val uniffiGeneratedPath = "generated/source/uniffi/${variant.name}/java" + //sourceSets["main"].java.srcDir(File(buildDir, uniffiGeneratedPath)) - // Note: The following line is commented out as it wasn't working in the original code - // project.extensions.getByType().sourceSets.getByName(variant.name) { - // kotlin.srcDir("${buildDir}/generated/source/uniffi/${variant.name}/java") + // sourceSets.getByName(variant.name) { + // java.srcDir(File(buildDir, uniffiGeneratedPath)) // } - } + + sourceSets { + getByName("main") { + java.srcDir(File(buildDir, uniffiGeneratedPath)) + } + } + } } dependencies { @@ -329,6 +352,7 @@ dependencies { implementation("net.java.dev.jna:jna:5.9.0@aar") } -//apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply(from = file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")) -project.extra.applyNativeModulesAppBuildGradle(project) + +val applyNativeModulesAppBuildGradle = extra.get("applyNativeModulesAppBuildGradle") as Closure<*> +applyNativeModulesAppBuildGradle(project) \ No newline at end of file