diff --git a/Android/shared/build.gradle b/Android/shared/build.gradle deleted file mode 100644 index 60f182c..0000000 --- a/Android/shared/build.gradle +++ /dev/null @@ -1,110 +0,0 @@ -plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'org.mozilla.rust-android-gradle.rust-android' -} - -android { - namespace 'com.example.simple_counter.shared' - compileSdk 34 - - ndkVersion "27.0.11902837" - - defaultConfig { - minSdk 33 - targetSdk 34 - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles "consumer-rules.pro" - } - - buildTypes { - release { - minifyEnabled 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' - } - - sourceSets { - main.java.srcDirs += "${projectDir}/../../shared_types/generated/java" - } -} - -dependencies { - implementation "net.java.dev.jna:jna:5.14.0@aar" - - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.appcompat:appcompat:1.7.0' - implementation 'com.google.android.material:material:1.12.0' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.2.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1' -} - -apply plugin: 'org.mozilla.rust-android-gradle.rust-android' - -cargo { - module = "../.." - libname = "shared" - // these are the four recommended targets for Android that will ensure your library works on all mainline android devices - // make sure you have included the rust toolchain for each of these targets: \ - // `rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android` - targets = ["arm", "arm64", "x86", "x86_64"] - extraCargoBuildArguments = ['--package', 'shared'] - pythonCommand = "python3" -} - -afterEvaluate { - // The `cargoBuild` task isn't available until after evaluation. - android.libraryVariants.configureEach { variant -> - def productFlavor = "" - variant.productFlavors.each { - productFlavor += "${it.name.capitalize()}" - } - def buildType = "${variant.buildType.name.capitalize()}" - - tasks.named("compileDebugKotlin") { - it.dependsOn(tasks.named("typesGen"), tasks.named("bindGen")) - } - - tasks.named("generate${productFlavor}${buildType}Assets") { - it.dependsOn(tasks.named("cargoBuild")) - } - } -} - -tasks.register('bindGen', Exec) { - def outDir = "${projectDir}/../../shared_types/generated/java" - workingDir "../../" - if (System.getProperty('os.name').toLowerCase().contains('windows')) { - commandLine("cmd", "/c", - "cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate shared\\src\\shared.udl " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\')) - } else { - commandLine("sh", "-c", - """\ - cargo build -p shared && \ - target/debug/uniffi-bindgen generate shared/src/shared.udl \ - --language kotlin \ - --out-dir $outDir - """) - } -} - -tasks.register('typesGen', Exec) { - workingDir "../../" - if (System.getProperty('os.name').toLowerCase().contains('windows')) { - commandLine("cmd", "/c", "cargo build -p shared_types") - } else { - commandLine("sh", "-c", "cargo build -p shared_types") - } -} diff --git a/Android/shared/build.gradle.kts b/Android/shared/build.gradle.kts new file mode 100644 index 0000000..a8aa485 --- /dev/null +++ b/Android/shared/build.gradle.kts @@ -0,0 +1,120 @@ +plugins { + id("com.android.library") + id("org.jetbrains.kotlin.android") + id("org.mozilla.rust-android-gradle.rust-android") +} + +android { + namespace = "com.example.simple_counter.shared" + compileSdk = 34 + + ndkVersion = "27.0.11902837" + + defaultConfig { + minSdk = 33 + targetSdk = 34 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles( "consumer-rules.pro" ) + } + + 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" + } + + sourceSets { +// main.java.srcDirs += "${projectDir}/../../shared_types/generated/java" + named("main") { + java.srcDirs("${projectDir}/../../shared_types/generated/java") + } + } +} + +dependencies { + implementation("net.java.dev.jna:jna:5.14.0@aar") + + implementation("androidx.core:core-ktx:1.13.1") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("com.google.android.material:material:1.12.0") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") +} + +//apply plugin: "org.mozilla.rust-android-gradle.rust-android" +apply(plugin = "org.mozilla.rust-android-gradle.rust-android") +cargo { + module = "../.." + libname = "shared" + // these are the four recommended targets for Android that will ensure your library works on all mainline android devices + // make sure you have included the rust toolchain for each of these targets: \ + // `rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android` + targets = listOf("arm", "arm64", "x86", "x86_64") + extraCargoBuildArguments = listOf("--package", "shared") + pythonCommand = "python3" +} + +afterEvaluate { + // The `cargoBuild` task isn"t available until after evaluation. + android.libraryVariants.configureEach { + var productFlavor = "" + productFlavors.forEach { + productFlavor += "${it.name.capitalize()}" + } + val buildType = "${buildType.name.capitalize()}" + + tasks.named("compileDebugKotlin") { + dependsOn(tasks.named("typesGen"), tasks.named("bindGen")) + } + + tasks.named("generate${productFlavor}${buildType}Assets") { + dependsOn(tasks.named("cargoBuild")) + } + } +} + +tasks.register("bindGen") { + val outDir = "${projectDir}/../../shared_types/generated/java" + workingDir = File("../../") + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + commandLine( + "cmd", "/c", + "cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate shared\\src\\shared.udl " + "--language kotlin " + "--out-dir " + outDir.replace( + "/", + "\\" + ) + ) + } else { + commandLine( + "sh", "-c", + """\ + cargo build -p shared && \ + target/debug/uniffi-bindgen generate shared/src/shared.udl \ + --language kotlin \ + --out-dir $outDir + """ + ) + } +} + +tasks.register("typesGen") { + workingDir = File("../../") + if (System.getProperty("os.name").toLowerCase().contains("windows")) { + commandLine("cmd", "/c", "cargo build -p shared_types") + } else { + commandLine("sh", "-c", "cargo build -p shared_types") + } +}