Skip to content

Commit babbce3

Browse files
committed
New macOS & Ubuntu toolchain
1 parent f61cffe commit babbce3

25 files changed

+542
-71
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/compiler.xml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
## Kotlin example for the SwiftAndroid toolchain.
1+
# Kotlin example for the Android Swift toolchain.
22

3-
Requires a build of the latest Android toolchain downloadable [here](http://johnholdsworth.com/android_toolchain.tgz). Once you've extracted the toolchain, run `swift-install/setup.sh` to get started. Once you've extracted this example you may need to edit local.properties to point to your Android SDK and then you should be able to run `./gradlew installDebug` or build the project in Android Studio. Make sure the that the `ANDROID_HOME` environment variable is set to the path to the SDK.
3+
![](http://johnholdsworth.com/kotlin.png)
4+
5+
Requires a build of the latest Android toolchain downloadable [here](http://johnholdsworth.com/android_toolchain.tgz). Once you've extracted the toolchain, run `swift-install/setup.sh` to get started. You then run `./gradlew installDebug` or build the project in Android Studio. Make sure the that the `ANDROID_HOME` environment variable is set to the path to an [Android SDK](https://developer.android.com/studio/index.html).
46
The phone must be api 21 aka Android v5+ aka Lollipop or better (I used an LG K4.)
7+
58
To create a new application, decide on a pair of interfaces to connect to and from your Swift
69
code and place them in a [Java Source](https://github.com/SwiftJava/swift-android-samples/blob/master/swifthello/src/main/java/com/jh/SwiftHello.java).
710
Use the command `./genswift.sh` in the [SwiftJava Project](https://github.com/SwiftJava/SwiftJava)
@@ -18,15 +21,14 @@ Context.getCacheDir().getPath() from the java side. In addition, to be able to u
1821
need to add a [CARoot info file](http://curl.haxx.se/docs/caextract.html) to the application's
1922
raw resources and copy it to this cache directory to be picked up by Foundation as follows:
2023

21-
URLSession.sslCertificateAuthorityFile = URL(fileURLWithPath: cacheDir! + "/cacert.pem")
24+
setenv("URLSessionCAInfo", cacheDir! + "/cacert.pem", 1)
25+
setenv("TMPDIR", cacheDir!, 1)
2226

2327
If you don't want peer validation you have the following option (not recommended at all)
2428

25-
URLSession.verifyPeerSSLCertificate = false
26-
27-
##
28-
29-
Simple demo of Swift code accessed over JNI.
29+
setenv("URLSessionCAInfo", “INSECURE_SSL_NO_VERIFY”, 1)
30+
31+
## Simple demo of Swift code accessed over JNI.
3032

3133
To build, setup the Gradle plugin, then run `./gradlew installDebug`
3234

app/app.iml

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@
2121
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
2222
</configuration>
2323
</facet>
24-
<facet type="kotlin-language" name="Kotlin">
25-
<configuration version="3" platform="JVM 1.8" useProjectSettings="false">
26-
<compilerSettings />
27-
<compilerArguments>
28-
<option name="jvmTarget" value="1.8" />
29-
<option name="languageVersion" value="1.1" />
30-
<option name="apiVersion" value="1.1" />
31-
<option name="pluginOptions">
32-
<array />
33-
</option>
34-
<option name="pluginClasspaths">
35-
<array />
36-
</option>
37-
</compilerArguments>
38-
</configuration>
39-
</facet>
4024
</component>
4125
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
4226
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
@@ -78,40 +62,45 @@
7862
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
7963
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
8064
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
81-
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
82-
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
83-
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
84-
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
85-
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
86-
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
87-
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
8865
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
8966
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
9067
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
9168
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
9269
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
9370
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
9471
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
9579
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
9680
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/build-info" />
9782
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
9884
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes-jar" />
9986
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
10087
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
10188
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
102-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
10389
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
10490
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
10591
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
92+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
10693
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
10794
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
95+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
10896
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
10997
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
110-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
11198
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
11299
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
113100
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
101+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
114102
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
103+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
115104
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
116105
<excludeFolder url="file://$MODULE_DIR$/build/kotlin" />
117106
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
@@ -133,8 +122,8 @@
133122
<orderEntry type="library" exported="" name="support-fragment-25.3.1" level="project" />
134123
<orderEntry type="library" exported="" scope="TEST" name="espresso-core-2.2.2" level="project" />
135124
<orderEntry type="library" exported="" scope="TEST" name="exposed-instrumentation-api-publish-0.5" level="project" />
136-
<orderEntry type="library" exported="" scope="TEST" name="rules-0.5" level="project" />
137125
<orderEntry type="library" exported="" name="constraint-layout-solver-1.0.2" level="project" />
126+
<orderEntry type="library" exported="" scope="TEST" name="rules-0.5" level="project" />
138127
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
139128
<orderEntry type="library" exported="" name="annotations-13.0" level="project" />
140129
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
@@ -146,9 +135,9 @@
146135
<orderEntry type="library" exported="" name="recyclerview-v7-25.3.1" level="project" />
147136
<orderEntry type="library" exported="" name="kotlin-stdlib-1.1.3-2" level="project" />
148137
<orderEntry type="library" exported="" name="support-annotations-25.3.1" level="project" />
149-
<orderEntry type="library" exported="" name="support-vector-drawable-25.3.1" level="project" />
150138
<orderEntry type="library" exported="" name="appcompat-v7-25.3.1" level="project" />
151-
<orderEntry type="library" exported="" name="support-compat-25.3.1" level="project" />
139+
<orderEntry type="library" exported="" name="support-vector-drawable-25.3.1" level="project" />
152140
<orderEntry type="library" exported="" name="animated-vector-drawable-25.3.1" level="project" />
141+
<orderEntry type="library" exported="" name="support-compat-25.3.1" level="project" />
153142
</component>
154143
</module>

app/src/main/java/com/example/user/myapplication/MainActivity.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import android.view.Menu
99
import android.view.MenuItem
1010
import android.widget.TextView
1111

12-
import com.jh.SwiftHello.Listener
13-
import com.jh.SwiftHello.Responder
12+
import com.jh.SwiftHelloBinding.Listener
13+
import com.jh.SwiftHelloBinding.Responder
1414
import com.jh.SwiftHelloTest.TestListener
1515
import com.jh.SwiftHelloTest.TestResponderImpl
1616

@@ -35,10 +35,10 @@ class MainActivity : AppCompatActivity(), Responder {
3535
}
3636
loadNativeDependencies()
3737
listener = bind(this)
38-
val context = SwiftApp.sharedApplication?.getApplicationContext()
38+
val context = SwiftApp.sharedApplication.getApplicationContext()
3939
val cacheDir = context?.getCacheDir()?.getPath()
4040
val pemfile = cacheDir + "/cacert.pem"
41-
val pemStream = SwiftApp.sharedApplication?.getResources()?.openRawResource(R.raw.cacert)
41+
val pemStream = SwiftApp.sharedApplication.getResources()?.openRawResource(R.raw.cacert)
4242
copyResource(pemStream, pemfile)
4343
listener.setCacheDir(cacheDir)
4444
listener.processText("World")
@@ -49,7 +49,7 @@ class MainActivity : AppCompatActivity(), Responder {
4949
val out = FileOutputStream(to)
5050
`in`?.copyTo(out)
5151
`in`?.close()
52-
out?.close()
52+
out.close()
5353
} catch (e: IOException) {
5454
e.printStackTrace()
5555
System.out.println("" + e)

0 commit comments

Comments
 (0)