Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from vgorloff/develop
Browse files Browse the repository at this point in the history
RC 1.0.2
  • Loading branch information
vgorloff committed Jul 16, 2019
2 parents 74736b5 + ae4b448 commit e0edc25
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.DS_Store
local.properties.yml
/*.code-workspace
/.build
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2] - 2019-07-16
### Changed
* Android Studio project now builds Swift sources using custom Gradle task instead of CMake build.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
1 change: 1 addition & 0 deletions hello-application/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
/.idea/assetWizardSettings.xml
.DS_Store
/build
/.build
/captures
.externalNativeBuild
62 changes: 62 additions & 0 deletions hello-application/Builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'yaml'
require_relative "../Scripts/Tool.rb"

class Builder < Tool

def self.perform(arch)
if arch.empty?
Builder.new("armeabi-v7a").build()
Builder.new("arm64-v8a").build()
Builder.new("x86").build()
Builder.new("x86_64").build()
else
Builder.new(arch).build()
end
end

def initialize(arch)
@root = File.dirname(__FILE__)
@arch = arch
@sources = "#{@root}/Sources"
@builds = "#{@root}/app/build/swift/#{arch}"

settingsFilePath = "#{@root}/local.properties.yml"
if File.exist?(settingsFilePath)
@config = YAML.load_file(settingsFilePath)
else
raise "File \"#{settingsFilePath}\" not exists."
end

toolchainDir = @config['swiftToolchain.dir']
if toolchainDir.nil?
raise "Setting \"swiftToolchain.dir\" is missed in file \"#{settingsFilePath}\"."
end

@toolchainDir = File.expand_path(toolchainDir)

if @arch == "armeabi-v7a"
@ndkArchPath = "arm-linux-androideabi"
elsif @arch == "x86"
@ndkArchPath = "i686-linux-android"
elsif @arch == "arm64-v8a"
@ndkArchPath = "aarch64-linux-android"
elsif @arch == "x86_64"
@ndkArchPath = "x86_64-linux-android"
end
@swiftc = @toolchainDir + "/bin/swiftc-" + @ndkArchPath
@copyLibsCmd = @toolchainDir + "/bin/copy-libs-" + @ndkArchPath
end

def build()
execute "mkdir -p \"#{@builds}\""
binary = "#{@builds}/libHelloMessages.so"
sources = Dir["#{@sources}/*.swift"].join(" ")
execute "cd #{@builds} && #{@swiftc} -emit-library -parse-as-library -module-name HelloMessages -o #{binary} #{sources}"
copyLibs
end

def copyLibs()
execute "#{@copyLibsCmd} #{@builds}"
end

end
47 changes: 23 additions & 24 deletions hello-application/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
apply plugin: 'com.android.application'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
compileSdkVersion 28
defaultConfig {
Expand All @@ -12,16 +9,6 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang", '-DANDROID_ARM_NEON=TRUE',
"-DSA_SWIFT_TOOLCHAIN_DIR=${properties.getProperty('swiftToolchain.dir')}"
cppFlags "-frtti -fexceptions"
cFlags '-O3', '-fsigned-char'
}
}

ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
Expand All @@ -32,22 +19,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

sourceSets {
main {
jniLibs.srcDirs 'build/swift'
}
}

// Encapsulates your external native build configurations.
externalNativeBuild {

// Encapsulates your CMake build configurations.
cmake {
// Provides a relative path to your CMake build script.
path "src/main/cpp/CMakeLists.txt"
}
}
}

dependencies {
Expand All @@ -58,3 +34,26 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

// https://stackoverflow.com/a/36730534/1418981
// https://stackoverflow.com/q/50448281/1418981
def getDeviceAbi() {
return "adb shell getprop ro.product.cpu.abi".execute().text.trim()
}

// See: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html
task spm(type:Exec) {
project.logger.lifecycle("Building Swift sources for: ${getDeviceAbi()}")
workingDir "$rootDir"
executable = '/usr/bin/env'
args = ["ruby", "-r", "./Builder.rb", "-e", "Builder.perform('${getDeviceAbi()}')"]
}

afterEvaluate {
if (project.hasProperty("assembleRelease")) {
assembleRelease.dependsOn spm
}
if (project.hasProperty("assembleDebug")) {
assembleDebug.dependsOn spm
}
}
1 change: 1 addition & 0 deletions hello-application/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.home.helloNDK">

<application
android:extractNativeLibs="false"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
87 changes: 0 additions & 87 deletions hello-application/app/src/main/cpp/CMakeLists.txt

This file was deleted.

5 changes: 0 additions & 5 deletions hello-application/app/src/main/cpp/Dummy.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion hello-application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.4.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions hello-application/local.properties.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Replace with path to Swift for Android Toolchain.
swiftToolchain.dir: ../../swift-everywhere-toolchain/ToolChain/swift-android-toolchain

0 comments on commit e0edc25

Please sign in to comment.