Skip to content

Commit babbce3

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

25 files changed

+542
-71
lines changed

Diff for: .gitignore

+9
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

Diff for: .idea/compiler.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: README.md

+10-8
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

Diff for: app/app.iml

+17-28
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>

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

+5-5
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)

Diff for: app/src/main/java/com/example/user/myapplication/SwiftApp.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SwiftApp : Application() {
1111

1212
companion object {
1313

14-
var sharedApplication: Application? = null
14+
lateinit var sharedApplication: Application
1515
private set
1616
}
1717
}

Diff for: app/src/main/java/com/jh/SwiftHelloBinding.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
package com.jh;
3+
4+
public interface SwiftHelloBinding {
5+
6+
public interface Listener {
7+
8+
public void setCacheDir( String cacheDir );
9+
10+
public void processNumber( double number );
11+
12+
public void processText( String text );
13+
14+
}
15+
16+
public interface Responder {
17+
18+
public void processedNumber( double number );
19+
20+
public void processedText( String text );
21+
22+
public String[] debug( String msg );
23+
24+
public SwiftHelloTest.TestListener testResponder();
25+
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
/// interface com.jh.SwiftHelloBinding$Listener ///
3+
4+
package org.genie.com_jh;
5+
6+
@SuppressWarnings("JniMissingFunction")
7+
public class SwiftHelloBinding_ListenerProxy implements com.jh.SwiftHelloBinding.Listener {
8+
9+
long swiftObject;
10+
11+
SwiftHelloBinding_ListenerProxy( long swiftObject ) {
12+
this.swiftObject = swiftObject;
13+
}
14+
15+
/// public abstract void com.jh.SwiftHelloBinding$Listener.setCacheDir(java.lang.String)
16+
17+
public native void __setCacheDir( java.lang.String cacheDir );
18+
19+
public void setCacheDir( java.lang.String cacheDir ) {
20+
__setCacheDir( cacheDir );
21+
}
22+
23+
/// public abstract void com.jh.SwiftHelloBinding$Listener.processNumber(double)
24+
25+
public native void __processNumber( double number );
26+
27+
public void processNumber( double number ) {
28+
__processNumber( number );
29+
}
30+
31+
/// public abstract void com.jh.SwiftHelloBinding$Listener.processText(java.lang.String)
32+
33+
public native void __processText( java.lang.String text );
34+
35+
public void processText( java.lang.String text ) {
36+
__processText( text );
37+
}
38+
39+
}

0 commit comments

Comments
 (0)