Skip to content

Commit

Permalink
Improve Android SDK detection and fix NDK and build tools version.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Jul 13, 2020
1 parent e54ed51 commit 7904a6e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 32 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: Android CI

env:
NDK_VERSION: "21.3.6528147"

on:
push:
branches:
Expand All @@ -26,12 +23,11 @@ jobs:
with:
go-version: 1.14
id: go
- name: Install NDK
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;${NDK_VERSION}"
- name: Configure local.properties
- name: Configure Android SDK
run: |
echo "sdk.dir=${ANDROID_HOME}" >> local.properties
echo "ndk.dir=${ANDROID_HOME}/ndk/${NDK_VERSION}" >> local.properties
BUILD_TOOLS_VERSION="$(grep -E "^io\.github\.x0b\.rcx\.buildToolsVersion=" gradle.properties | cut -d'=' -f2)"
NDK_VERSION="$(grep -E "^io\.github\.x0b\.rcx\.ndkVersion=" gradle.properties | cut -d'=' -f2)"
yes | sudo "${ANDROID_HOME}/tools/bin/sdkmanager" "build-tools;${BUILD_TOOLS_VERSION}" "ndk;${NDK_VERSION}"
- name: Build app
run: ./gradlew assembleOssDebug
- name: Upload APK
Expand Down
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ android {
preBuild.dependsOn(':rclone:buildNative')
}

buildToolsVersion project.properties['io.github.x0b.rcx.buildToolsVersion']
ndkVersion project.properties['io.github.x0b.rcx.ndkVersion']

signingConfigs {
github_x0b {
keyAlias 'github_x0b'
Expand Down Expand Up @@ -87,7 +90,6 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '30.0.1'
}

repositories {
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ android.useAndroidX=true
# android.enableR8=true
org.gradle.jvmargs=-Xmx1536m

io.github.x0b.rcx.rCloneVersion=v1.51.0
io.github.x0b.rcx.buildToolsVersion=30.0.1
io.github.x0b.rcx.ndkVersion=21.3.6528147

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down
82 changes: 60 additions & 22 deletions rclone/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
import java.nio.file.Paths

def repository = 'github.com/rclone/rclone'
def goPath = Paths.get(projectDir.absolutePath, 'gopath').toAbsolutePath().toString()
def RCLONE_VERSION = project.properties['io.github.x0b.rcx.rCloneVersion']
def RCLONE_REPOSITORY = 'github.com/rclone/rclone'
def GO_PATH = Paths.get(projectDir.absolutePath, 'gopath').toAbsolutePath().toString()

def getCrossCompiler(bin) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')
def findSdkDir() {
def androidHome = System.getenv('ANDROID_HOME')
if (androidHome != null) {
return androidHome
}

def localPropertiesFile = project.rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Properties properties = new Properties()
properties.load(localPropertiesFile.newDataInputStream())
def sdkDir = properties.get('sdk.dir')
if (sdkDir != null) {
return sdkDir
}
}

throw GradleException(
"Couldn't locate your android SDK location. Make sure to set sdk.dir property "
+ "in your local.properties at the root of the project or set ANDROID_HOME "
+ "environment variable"
)
}

def findNdkDir() {
def ndkVersion = project.properties['io.github.x0b.rcx.ndkVersion']
def sdkDir = findSdkDir()
def ndkPath = Paths.get(sdkDir, 'ndk', ndkVersion).resolve().toAbsolutePath()
if (!ndkPath.toFile().exists()) {
throw new GradleException(
"Couldn't find a ndk-bundle in " + ndkPath.toString() + ". Make sure it is installed " +
"by running the command 'sdkmanager \"ndk;" + ndkVersion + "\"."
)
}
return ndkPath.toString()
}

def getCrossCompiler(bin) {
def ndkDir = findNdkDir()
def osName = System.properties['os.name'].toLowerCase()
def osArch = System.properties['os.arch']
def os
Expand Down Expand Up @@ -36,75 +70,79 @@ def getCrossCompiler(bin) {
)
}

def getLibrclone(arch) {
return Paths.get('..', 'app', 'lib', arch, 'librclone.so').toString()
}

task fetchRclone(type: Exec) {
mkdir goPath
environment 'GOPATH', goPath
commandLine 'go', 'get', '-d', repository
mkdir GO_PATH
environment 'GOPATH', GO_PATH
commandLine 'go', 'get', '-d', RCLONE_REPOSITORY
}

task checkoutRclone(type: Exec) {
dependsOn fetchRclone
workingDir Paths.get(goPath, "src/${repository}".split('/'))
workingDir Paths.get(GO_PATH, 'src', RCLONE_REPOSITORY)
commandLine 'git', 'checkout', RCLONE_VERSION
}

task cleanNative {
enabled = false
doLast {
delete '../app/lib/armeabi-v7a/librclone.so'
delete '../app/lib/arm64-v8a/librclone.so'
delete '../app/lib/x86/librclone.so'
delete '../app/lib/x86_64/librclone.so'
delete getLibrclone('armeabi-v7a')
delete getLibrclone('arm64-v8a')
delete getLibrclone('x86')
delete getLibrclone('x86_64')
}
}

task buildArm(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', goPath
environment 'GOPATH', GO_PATH
def crossCompiler = getCrossCompiler('armv7a-linux-androideabi21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', 'arm'
environment 'GOARM', '7'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-tags', 'linux', '-o', '../app/lib/armeabi-v7a/librclone.so', repository
commandLine 'go', 'build', '-tags', 'linux', '-o', getLibrclone('armeabi-v7a'), RCLONE_REPOSITORY
}

task buildArm64(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', goPath
environment 'GOPATH', GO_PATH
def crossCompiler = getCrossCompiler('aarch64-linux-android21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', 'arm64'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-tags', 'linux', '-o', '../app/lib/arm64-v8a/librclone.so', repository
commandLine 'go', 'build', '-tags', 'linux', '-o', getLibrclone('arm64-v8a'), RCLONE_REPOSITORY
}

task buildx86(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', goPath
environment 'GOPATH', GO_PATH
def crossCompiler = getCrossCompiler('i686-linux-android21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', '386'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-tags', 'linux', '-o', '../app/lib/x86/librclone.so', repository
commandLine 'go', 'build', '-tags', 'linux', '-o', getLibrclone('x86'), RCLONE_REPOSITORY
}

task buildx64(type: Exec) {
dependsOn checkoutRclone
environment 'GOPATH', goPath
environment 'GOPATH', GO_PATH
def crossCompiler = getCrossCompiler('x86_64-linux-android21-clang')
environment 'CC', crossCompiler
environment 'CC_FOR_TARGET', crossCompiler
environment 'GOOS', 'android'
environment 'GOARCH', 'amd64'
environment 'CGO_ENABLED', '1'
commandLine 'go', 'build', '-tags', 'linux', '-o', '../app/lib/x86_64/librclone.so', repository
commandLine 'go', 'build', '-tags', 'linux', '-o', getLibrclone('x86_64'), RCLONE_REPOSITORY
}

task buildNative {
Expand Down
1 change: 0 additions & 1 deletion rclone/gradle.properties

This file was deleted.

0 comments on commit 7904a6e

Please sign in to comment.