Skip to content

Commit

Permalink
Add gradle task automatically copying prebuilt libs after compiling, …
Browse files Browse the repository at this point in the history
…distinction between debug/release builds, limit architectures
  • Loading branch information
mvidaldp committed Feb 4, 2022
1 parent aeec010 commit fd8ecf6
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 33 deletions.
99 changes: 70 additions & 29 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
plugins {
id 'com.android.application'
}

//
// Uncomment the blocks "externalNativeBuild" and "externalNativeBuild.cmake" for building the app
// with liblsl (LSL) from the source code using CMake. Make sure you have liblsl's source code
// Uncomment the blocks "externalNativeBuild" for building the app with liblsl (LSL) from the source
// code using CMake. Make sure you have liblsl's source code
// (https://github.com/sccn/liblsl/releases/latest -> Source code) on /app-root/liblsl or the path
// you specified on the block "externalNativeBuild.cmake" -> path "./liblsl-path/CMakeLists.txt"
//
// In case of an external CMake installation (https://cmake.org/download/ -> Binary distributions),
// specify cmake.dir=path on local.properties, e.g. cmake.dir=/home/user/Android/SDK/cmake/3.18.0
// Otherwise you can install CMake using Android Studio's menu via Tools -> SDK Manager -> SDK Tools
// Also note that you will need CMake version >=3.12.0 to make the build. If your Gradle version is
// >= 7 you will need CMake <= 3.18.0 to make it work.
// In case of external CMake installation, you will need the Ninja binary inside your cmake/bin
// folder to make the build work: https://github.com/ninja-build/ninja/releases/latest
//
// Comment these blocks for building the app using the compiled library (liblsl.so). Make sure you
// copy the build library on /app-root/module-root/src/main/jniLibs/
// By compiling liblsl from source, CMake generates it for all Android architectures. The outcome is
// stored on /app-root/module-root/build/intermediates/cmake/debug/obj/
// Just copy all the folders (arm64-v8a, armeabi-v7a, x86, and x86_64) on the "jniLibs" folder and
// the build will succeed.
//
// Comment the "externalNativeBuild" blocks for building the app using the compiled library
// (liblsl.so). Once the build succeeds, the library files (.so) are automatically copied inside
// the folders:
// /project-root/app/src/debug/jniLibs (for a debug build)
// /project-root/app/src/main/jniLibs (for a release build)
// IMPORTANT to use LSL on your code:
// - Take the the last version of LSL.java:
// https://github.com/labstreaminglayer/liblsl-Java/blob/master/src/edu/ucsd/sccn/LSL.java
Expand All @@ -31,48 +23,97 @@ plugins {
// - Include the following permission on your AndroidManifest.xml:
// <uses-permission android:name="android.permission.INTERNET" />
// - Include the jna (Java Native Access) in your dependencies block. E.g.:
// implementation 'net.java.dev.jna:jna:5.9.0@aar'
// implementation 'net.java.dev.jna:jna:5.10.0@aar'
//

apply plugin: 'com.android.application'

def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(file('../keystore.properties')))

android {
signingConfigs {
debug {
storeFile file('key.jks')
storePassword keystoreProperties['storePassword']
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
}
release {
storeFile file('key.jks')
storePassword keystoreProperties['storePassword']
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
}
}
compileSdk 31
defaultConfig {
minSdk 24
targetSdk 31
versionCode 1
versionName '1.15.2'
setProperty('archivesBaseName', "liblsl-android-builder-$versionName")
ndk {
// Specifies the ABI configurations of your native
// libraries Gradle should build and package with your app.
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
externalNativeBuild.cmake {
arguments "-DANDROID_CPP_FEATURES=rtti exceptions", "-DLSL_NO_FANCY_LIBNAME=1", "-DANDROID_PLATFORM=24"
targets "lsl"
}
}
externalNativeBuild.cmake {
version "3.18.1"
path "./liblsl/CMakeLists.txt"
// externalNativeBuild.cmake {
// arguments "-DANDROID_CPP_FEATURES=rtti exceptions", "-DLSL_NO_FANCY_LIBNAME=1", "-DANDROID_PLATFORM=24"
// targets "lsl"
// }
}
// externalNativeBuild.cmake {
// path "./liblsl/CMakeLists.txt"
// }
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debug {
debuggable true
jniDebuggable true
renderscriptDebuggable true
signingConfig signingConfigs.debug
}
release {
debuggable false
jniDebuggable false
renderscriptDebuggable false
signingConfig signingConfigs.release
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
pickFirst '**/lib/**'
}
buildToolsVersion '32.0.0'
ndkVersion '21.4.7075529'
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'net.java.dev.jna:jna:5.10.0@aar'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.material:material:1.5.0'
implementation 'net.java.dev.jna:jna:5.10.0@aar'
}

// copy native libraries to per project location
task copyDebugJniLibs(type: Copy) {
from 'build/intermediates/cmake/debug/obj'
include('**/*.*')
into 'src/debug/jniLibs'
}
task copyReleaseJniLibs(type: Copy) {
from 'build/intermediates/cmake/release/obj'
include('**/*.*')
into 'src/main/jniLibs'
}

tasks.whenTaskAdded { task ->
if (task.name == 'assembleDebug') task.finalizedBy('copyDebugJniLibs')
if (task.name == 'assembleRelease') task.finalizedBy('copyReleaseJniLibs')
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.1.0'
// classpath 'com.netflix.nebula:gradle-lint-plugin:latest.release' // not working gradle > 7

// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 30 14:59:02 CEST 2021
#Thu Feb 03 18:21:06 CET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':builder'
include ':app'

0 comments on commit fd8ecf6

Please sign in to comment.