From 515897f63d7278acdc1de2fd1a7b6c4ed2b386c6 Mon Sep 17 00:00:00 2001 From: Andrew Druk Date: Wed, 24 Mar 2021 00:09:03 +0200 Subject: [PATCH 1/5] System: update swift gradle plugin --- build.gradle | 6 ++-- compiler/build.gradle | 2 +- gradle.properties | 4 ++- sample/build.gradle | 29 ++++++++++++++----- .../readdle/swiftjava/sample/BoolTests.java | 2 +- .../readdle/swiftjava/sample/DoubleTests.java | 2 +- .../readdle/swiftjava/sample/FloatTests.java | 2 +- .../readdle/swiftjava/sample/Int16Tests.java | 2 +- .../readdle/swiftjava/sample/Int32Tests.java | 2 +- .../readdle/swiftjava/sample/Int64Tests.java | 2 +- .../readdle/swiftjava/sample/Int8Tests.java | 2 +- .../readdle/swiftjava/sample/IntTests.java | 2 +- .../swiftjava/sample/SampleReferenceTest.java | 7 ++--- .../swiftjava/sample/SampleValueTest.kt | 2 +- .../readdle/swiftjava/sample/StringTests.java | 2 +- .../readdle/swiftjava/sample/UInt16Tests.java | 2 +- .../readdle/swiftjava/sample/UInt32Tests.java | 2 +- .../readdle/swiftjava/sample/UInt64Tests.java | 2 +- .../readdle/swiftjava/sample/UInt8Tests.java | 2 +- .../readdle/swiftjava/sample/UIntTests.java | 2 +- .../swiftjava/sample/MainActivity.java | 2 +- sample/src/main/res/layout/activity_main.xml | 4 +-- 22 files changed, 49 insertions(+), 35 deletions(-) diff --git a/build.gradle b/build.gradle index 9ec671f..a92f2b7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.61' + ext.kotlin_version = '1.4.21' repositories { google() @@ -9,8 +9,8 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.1' - classpath "com.readdle.android.swift:gradle:1.3.2" + classpath 'com.android.tools.build:gradle:4.1.2' + classpath "com.readdle.android.swift:gradle:1.3.4" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" diff --git a/compiler/build.gradle b/compiler/build.gradle index d1a160d..83ee0f8 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -4,7 +4,7 @@ archivesBaseName = "compiler" dependencies { implementation project(':library') - implementation 'com.google.code.gson:gson:2.8.5' + implementation 'com.google.code.gson:gson:2.8.6' } apply from: rootProject.file('bintray-publish.gradle') \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 48d849e..b574b09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,6 @@ GROUP=com.readdle.swift.java.codegen -VERSION_NAME=0.9.0 +VERSION_NAME=0.9.1 org.gradle.jvmargs=-Xmx1536m +android.useAndroidX=true +android.enableJetifier=true diff --git a/sample/build.gradle b/sample/build.gradle index 4442445..dd89a2a 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -9,7 +9,6 @@ swift { useKapt true cleanEnabled true debug { - abiFilters("x86_64") extraBuildFlags("-Xswiftc", "-DDEBUG") } } @@ -22,7 +21,7 @@ android { targetSdkVersion 30 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' javaCompileOptions { annotationProcessorOptions { arguments = ["com.readdle.codegen.package": """{ @@ -39,8 +38,22 @@ android { } buildTypes { release { + debuggable false + jniDebuggable false minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + shrinkResources false + ndk { + abiFilters = ["armeabi-v7a", "arm64-v8a", "x86", "x86_64"] + } + } + debug { + debuggable true + jniDebuggable true + minifyEnabled false + shrinkResources false + ndk { + abiFilters = ["x86", "x86_64"] + } } } @@ -68,10 +81,10 @@ dependencies { kapt project(':compiler') implementation project(':library') - implementation 'com.android.support.constraint:constraint-layout:2.0.4' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.13.1' - androidTestImplementation 'com.android.support:support-annotations:28.0.0' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test:rules:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.annotation:annotation:1.1.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test:rules:1.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' } diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/BoolTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/BoolTests.java index 83137bf..2201621 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/BoolTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/BoolTests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/DoubleTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/DoubleTests.java index 78bd91a..83f11af 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/DoubleTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/DoubleTests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/FloatTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/FloatTests.java index f71a888..45aba9b 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/FloatTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/FloatTests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int16Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int16Tests.java index 9a649d2..5a49119 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int16Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int16Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int32Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int32Tests.java index 8f8cc2e..521300e 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int32Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int32Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int64Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int64Tests.java index dd7ed09..1069996 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int64Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int64Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int8Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int8Tests.java index e1f28b0..33650d2 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int8Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Int8Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java index 83456d5..cf18c93 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; import com.readdle.codegen.anotation.SwiftRuntimeError; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleReferenceTest.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleReferenceTest.java index 8864a58..db84260 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleReferenceTest.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleReferenceTest.java @@ -1,9 +1,8 @@ package com.readdle.swiftjava.sample; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.test.runner.AndroidJUnit4; -import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; import com.readdle.codegen.anotation.SwiftError; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleValueTest.kt b/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleValueTest.kt index 611de56..fffa24b 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleValueTest.kt +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/SampleValueTest.kt @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample -import android.support.test.runner.AndroidJUnit4 +import androidx.test.ext.junit.runners.AndroidJUnit4 import com.readdle.codegen.anotation.JavaSwift import com.readdle.codegen.anotation.SwiftError import com.readdle.swiftjava.sample.SampleValue.Companion.funcThrows diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/StringTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/StringTests.java index 54d1a0b..f8e9ed6 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/StringTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/StringTests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; import com.readdle.codegen.anotation.SwiftRuntimeError; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt16Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt16Tests.java index bb7592d..133d343 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt16Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt16Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt32Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt32Tests.java index ddba571..7f65547 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt32Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt32Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt64Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt64Tests.java index 270854d..70f112d 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt64Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt64Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt8Tests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt8Tests.java index 48f29f7..e0a0588 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt8Tests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UInt8Tests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java index 4e4eda6..69c0dbe 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.readdle.codegen.anotation.JavaSwift; import com.readdle.codegen.anotation.SwiftRuntimeError; diff --git a/sample/src/main/java/com/readdle/swiftjava/sample/MainActivity.java b/sample/src/main/java/com/readdle/swiftjava/sample/MainActivity.java index 7d9f94c..eb048a7 100644 --- a/sample/src/main/java/com/readdle/swiftjava/sample/MainActivity.java +++ b/sample/src/main/java/com/readdle/swiftjava/sample/MainActivity.java @@ -1,6 +1,6 @@ package com.readdle.swiftjava.sample; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index dce8e2a..d974cd0 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - + From 31132cd6d5ca14f1be83b762dc635c82f0057733 Mon Sep 17 00:00:00 2001 From: Andrew Druk Date: Fri, 26 Mar 2021 00:45:57 +0200 Subject: [PATCH 2/5] Dev: fix 32-bit support --- .../java/com/readdle/swiftjava/sample/IntTests.java | 13 +++++++++---- .../com/readdle/swiftjava/sample/UIntTests.java | 5 ++++- .../readdle/swiftjava/sample/SwiftEnvironment.kt | 3 +++ sample/src/main/swift/Package.resolved | 4 ++-- sample/src/main/swift/Package.swift | 2 +- .../Sources/SampleAppCore/SwiftEnvironment.swift | 8 ++++++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java index cf18c93..dc75c47 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/IntTests.java @@ -29,9 +29,11 @@ public void testZero() { public void testMin() { try { Assert.assertEquals(IntTest.testMin(), Integer.MIN_VALUE); - Assert.fail(); - } - catch (Exception e) { + if (SwiftEnvironment.is64BitArch()) { + // Only on 64 bit arch there is not enough bytes to represent system Int.min + Assert.fail(); + } + } catch (Exception e) { Assert.assertTrue(e instanceof SwiftRuntimeError); Assert.assertEquals(e.getMessage(), "Invalid value \"" + Long.MIN_VALUE + "\": Not enough bits to represent Int []"); } @@ -41,7 +43,10 @@ public void testMin() { public void testMax() { try { Assert.assertEquals(IntTest.testMax(), Integer.MAX_VALUE); - Assert.fail(); + if (SwiftEnvironment.is64BitArch()) { + // Only on 64 bit arch there is not enough bytes to represent system Int.maxÄ + Assert.fail(); + } } catch (Exception e) { Assert.assertTrue(e instanceof SwiftRuntimeError); diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java index 69c0dbe..7db1373 100644 --- a/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/UIntTests.java @@ -37,7 +37,10 @@ public void testMin() { public void testMax() { try { Assert.assertEquals(UIntTest.testMax(), MAX_VALUE); - Assert.fail(); + if (SwiftEnvironment.is64BitArch()) { + // Only on 64 bit arch there is not enough bytes to represent system UInt.max + Assert.fail(); + } } catch (Exception e) { Assert.assertTrue(e instanceof SwiftRuntimeError); diff --git a/sample/src/main/java/com/readdle/swiftjava/sample/SwiftEnvironment.kt b/sample/src/main/java/com/readdle/swiftjava/sample/SwiftEnvironment.kt index 56ae45b..0c0a63b 100644 --- a/sample/src/main/java/com/readdle/swiftjava/sample/SwiftEnvironment.kt +++ b/sample/src/main/java/com/readdle/swiftjava/sample/SwiftEnvironment.kt @@ -17,6 +17,9 @@ class SwiftEnvironment private constructor() { @JvmStatic external fun initEnvironment() + + @JvmStatic + external fun is64BitArch(): Boolean } } diff --git a/sample/src/main/swift/Package.resolved b/sample/src/main/swift/Package.resolved index c3a5675..841cb0c 100644 --- a/sample/src/main/swift/Package.resolved +++ b/sample/src/main/swift/Package.resolved @@ -41,8 +41,8 @@ "package": "JavaCoder", "repositoryURL": "https://github.com/readdle/swift-java-coder.git", "state": { - "branch": "dev/kotlin-support", - "revision": "b708c7527a387e8c3830cf90d6e78a687078e0cf", + "branch": "dev/32-bit-support", + "revision": "328decd14703ebd2e44cd1d81386565d1b1f3877", "version": null } } diff --git a/sample/src/main/swift/Package.swift b/sample/src/main/swift/Package.swift index 5132987..b59e73c 100755 --- a/sample/src/main/swift/Package.swift +++ b/sample/src/main/swift/Package.swift @@ -55,7 +55,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/readdle/java_swift.git", .upToNextMinor(from: "2.1.8")), .package(url: "https://github.com/readdle/swift-java.git", .upToNextMinor(from: "0.2.2")), - .package(url: "https://github.com/readdle/swift-java-coder.git", .branch("dev/kotlin-support")), + .package(url: "https://github.com/readdle/swift-java-coder.git", .branch("dev/32-bit-support")), .package(url: "https://github.com/readdle/swift-anycodable.git", .upToNextMinor(from: "1.0.3")), ], targets: addGenerated([ diff --git a/sample/src/main/swift/Sources/SampleAppCore/SwiftEnvironment.swift b/sample/src/main/swift/Sources/SampleAppCore/SwiftEnvironment.swift index d306f9b..511172e 100644 --- a/sample/src/main/swift/Sources/SampleAppCore/SwiftEnvironment.swift +++ b/sample/src/main/swift/Sources/SampleAppCore/SwiftEnvironment.swift @@ -15,4 +15,12 @@ public class SwiftEnvironment { AnyCodable.RegisterType(FourthChild.self) } + public static func is64BitArch() -> Bool { + #if arch(x86_64) || arch(arm64) + return true + #else + return false + #endif + } + } From 5c8f0a62efd03caf1f84272791afb9f628fb4b48 Mon Sep 17 00:00:00 2001 From: Andrew Druk Date: Fri, 26 Mar 2021 01:05:14 +0200 Subject: [PATCH 3/5] Dev: add x86 CI check --- .github/workflows/android_x86.yml | 41 +++++++++++++++++++ .../{android.yml => android_x86_64.yml} | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/android_x86.yml rename .github/workflows/{android.yml => android_x86_64.yml} (98%) diff --git a/.github/workflows/android_x86.yml b/.github/workflows/android_x86.yml new file mode 100644 index 0000000..3fb0263 --- /dev/null +++ b/.github/workflows/android_x86.yml @@ -0,0 +1,41 @@ +name: Android CI x86 + +on: [push] + +jobs: + build: + + runs-on: macOS-latest + + steps: + - uses: actions/checkout@v1 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Install Swift toolchain 5.0.3 + run: wget https://swift.org/builds/swift-5.0.3-release/xcode/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-osx.pkg; + sudo installer -pkg swift-5.0.3-RELEASE-osx.pkg -target / + - name: Install NDK + run: wget https://dl.google.com/android/repository/android-ndk-r17c-darwin-x86_64.zip; + unzip android-ndk-r17c-darwin-x86_64.zip + - name: Install Swift Android Toolchain + run: SWIFT_ANDROID=$(curl -fsSL https://api.bintray.com/packages/readdle/swift-android-toolchain/swift-android-toolchain/versions/_latest | python -c 'import json,sys;print(json.load(sys.stdin))["name"]'); + wget https://dl.bintray.com/readdle/swift-android-toolchain/swift-android-$SWIFT_ANDROID.zip; + unzip swift-android-$SWIFT_ANDROID.zip; + swift-android-$SWIFT_ANDROID/bin/swift-android tools --update; + ln -sfn swift-android-$SWIFT_ANDROID swift-android-current + - name: Download Android Emulator + run: $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-29;google_apis;x86" + - name: Create Android Emulator + run: $ANDROID_HOME/tools/bin/avdmanager create avd -n ci-test -k "system-images;android-29;google_apis;x86" -d "pixel" --force + - name: Start Android Emulator + run: $ANDROID_HOME/emulator/emulator -no-window -avd ci-test -noaudio > /dev/null & + - name: Run connected android tests + run: export TOOLCHAINS=org.swift.50320190830a; + export ANDROID_NDK_HOME=$(pwd)/android-ndk-r17c; + export SWIFT_ANDROID_HOME=$(pwd)/swift-android-current; + export PATH=$ANDROID_NDK_HOME:$PATH; + export PATH=$SWIFT_ANDROID_HOME/bin:$SWIFT_ANDROID_HOME/build-tools/current:$PATH; + adb wait-for-device; + ./gradlew sample:cAT diff --git a/.github/workflows/android.yml b/.github/workflows/android_x86_64.yml similarity index 98% rename from .github/workflows/android.yml rename to .github/workflows/android_x86_64.yml index b19e504..903343c 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android_x86_64.yml @@ -1,4 +1,4 @@ -name: Android CI +name: Android CI x86_64 on: [push] From c62a0892a353d3afc6fcab499a914c0677223710 Mon Sep 17 00:00:00 2001 From: Andrew Druk Date: Wed, 14 Apr 2021 13:15:09 +0300 Subject: [PATCH 4/5] Dev: fix wrong getters signature for primitives --- .../codegen/SwiftGetterDescriptor.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/src/main/java/com/readdle/codegen/SwiftGetterDescriptor.java b/compiler/src/main/java/com/readdle/codegen/SwiftGetterDescriptor.java index 6deca49..09e186e 100644 --- a/compiler/src/main/java/com/readdle/codegen/SwiftGetterDescriptor.java +++ b/compiler/src/main/java/com/readdle/codegen/SwiftGetterDescriptor.java @@ -62,7 +62,10 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw String retType = ""; if (returnSwiftType != null) { - retType = " -> " + returnSwiftType.javaSigType(isReturnTypeOptional) + "?"; + retType = " -> " + returnSwiftType.javaSigType(isReturnTypeOptional); + if (isReturnTypeOptional || !returnSwiftType.isPrimitiveType()) { + retType += "?"; + } } swiftWriter.emit(String.format(")%s {\n", retType)); @@ -75,7 +78,12 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw swiftWriter.emitStatement("}"); swiftWriter.emitStatement("catch {"); Utils.handleRuntimeError(swiftWriter); - swiftWriter.emitStatement(String.format("return%s", returnSwiftType != null ? " nil" : "")); + if (!isReturnTypeOptional && returnSwiftType.isPrimitiveType()) { + swiftWriter.emitStatement("return " + returnSwiftType.primitiveDefaultValue()); + } + else { + swiftWriter.emitStatement("return nil"); + } swiftWriter.emitStatement("}"); } @@ -96,7 +104,12 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw swiftWriter.emitStatement("}"); swiftWriter.emitStatement("catch {"); Utils.handleRuntimeError(swiftWriter); - swiftWriter.emitStatement("return nil"); + if (!isReturnTypeOptional && returnSwiftType.isPrimitiveType()) { + swiftWriter.emitStatement("return " + returnSwiftType.primitiveDefaultValue()); + } + else { + swiftWriter.emitStatement("return nil"); + } swiftWriter.emitStatement("}"); } From a0f315e66ff5c3367453b0475ddeb0d07833d37f Mon Sep 17 00:00:00 2001 From: Andrew Druk Date: Wed, 14 Apr 2021 16:02:54 +0300 Subject: [PATCH 5/5] Dev: add tests for primitives issue --- .../readdle/swiftjava/sample/Issue31Tests.kt | 34 ++++++++++++++++ .../readdle/swiftjava/sample/Issue31Test.kt | 39 +++++++++++++++++++ .../IssueTests/Issue31Test.swift | 37 ++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 sample/src/androidTest/java/com/readdle/swiftjava/sample/Issue31Tests.kt create mode 100644 sample/src/main/java/com/readdle/swiftjava/sample/Issue31Test.kt create mode 100644 sample/src/main/swift/Sources/SampleAppCore/IssueTests/Issue31Test.swift diff --git a/sample/src/androidTest/java/com/readdle/swiftjava/sample/Issue31Tests.kt b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Issue31Tests.kt new file mode 100644 index 0000000..443a17b --- /dev/null +++ b/sample/src/androidTest/java/com/readdle/swiftjava/sample/Issue31Tests.kt @@ -0,0 +1,34 @@ +package com.readdle.swiftjava.sample + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.readdle.codegen.anotation.JavaSwift +import com.readdle.swiftjava.sample.SwiftEnvironment.Companion.initEnvironment +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class Issue31Tests { + + @Before + fun setUp() { + System.loadLibrary("SampleAppCore") + JavaSwift.init() + initEnvironment() + } + + @Test + fun testValueTypeNanBug() { + val progress = Issue31TestProgress(elapsed = 8, total = 8) + Assert.assertNotEquals(Double.NaN, progress.percentage) + Assert.assertNotEquals(Double.NaN, progress.calculatePercentage()) + } + + @Test + fun testReferenceTypeNanBug() { + val progress = Issue31ReferenceTestProgress.init(elapsed = 8, total = 8) + Assert.assertNotEquals(Double.NaN, progress.percentage) + Assert.assertNotEquals(Double.NaN, progress.calculatePercentage()) + } +} \ No newline at end of file diff --git a/sample/src/main/java/com/readdle/swiftjava/sample/Issue31Test.kt b/sample/src/main/java/com/readdle/swiftjava/sample/Issue31Test.kt new file mode 100644 index 0000000..bc66c5e --- /dev/null +++ b/sample/src/main/java/com/readdle/swiftjava/sample/Issue31Test.kt @@ -0,0 +1,39 @@ +package com.readdle.swiftjava.sample + +import com.readdle.codegen.anotation.SwiftFunc +import com.readdle.codegen.anotation.SwiftGetter +import com.readdle.codegen.anotation.SwiftReference +import com.readdle.codegen.anotation.SwiftValue + +@SwiftValue +data class Issue31TestProgress( + var elapsed: Int = 0, + var total: Int = 1 +) { + @get:SwiftGetter + val percentage: Double external get + + @SwiftFunc + external fun calculatePercentage(): Double +} + +@SwiftReference +class Issue31ReferenceTestProgress private constructor() { + // Swift JNI private native pointer + private val nativePointer = 0L + + // Swift JNI release method + external fun release() + + @get:SwiftGetter + val percentage: Double external get + + @SwiftFunc + external fun calculatePercentage(): Double + + companion object { + @JvmStatic + @SwiftFunc("init(elapsed:total:)") + external fun init(elapsed: Int, total: Int): Issue31ReferenceTestProgress + } +} \ No newline at end of file diff --git a/sample/src/main/swift/Sources/SampleAppCore/IssueTests/Issue31Test.swift b/sample/src/main/swift/Sources/SampleAppCore/IssueTests/Issue31Test.swift new file mode 100644 index 0000000..e9f453c --- /dev/null +++ b/sample/src/main/swift/Sources/SampleAppCore/IssueTests/Issue31Test.swift @@ -0,0 +1,37 @@ +import Foundation + +public struct Issue31TestProgress: Codable { + public let elapsed: Int + public let total: Int + + public var percentage: Double { + return 1.0 + } + + public init(elapsed: Int, total: Int) { + self.elapsed = elapsed + self.total = total + } + + public func calculatePercentage() -> Double { + return percentage + } +} + +public class Issue31ReferenceTestProgress: Codable { + public let elapsed: Int + public let total: Int + + public var percentage: Double { + return 1.0 + } + + public init(elapsed: Int, total: Int) { + self.elapsed = elapsed + self.total = total + } + + public func calculatePercentage() -> Double { + return percentage + } +} \ No newline at end of file