Skip to content

Commit fd8ecf6

Browse files
committed
Add gradle task automatically copying prebuilt libs after compiling, distinction between debug/release builds, limit architectures
1 parent aeec010 commit fd8ecf6

File tree

4 files changed

+74
-33
lines changed

4 files changed

+74
-33
lines changed

app/build.gradle

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
plugins {
2-
id 'com.android.application'
3-
}
4-
51
//
6-
// Uncomment the blocks "externalNativeBuild" and "externalNativeBuild.cmake" for building the app
7-
// with liblsl (LSL) from the source code using CMake. Make sure you have liblsl's source code
2+
// Uncomment the blocks "externalNativeBuild" for building the app with liblsl (LSL) from the source
3+
// code using CMake. Make sure you have liblsl's source code
84
// (https://github.com/sccn/liblsl/releases/latest -> Source code) on /app-root/liblsl or the path
95
// you specified on the block "externalNativeBuild.cmake" -> path "./liblsl-path/CMakeLists.txt"
106
//
117
// In case of an external CMake installation (https://cmake.org/download/ -> Binary distributions),
128
// specify cmake.dir=path on local.properties, e.g. cmake.dir=/home/user/Android/SDK/cmake/3.18.0
139
// Otherwise you can install CMake using Android Studio's menu via Tools -> SDK Manager -> SDK Tools
14-
// Also note that you will need CMake version >=3.12.0 to make the build. If your Gradle version is
15-
// >= 7 you will need CMake <= 3.18.0 to make it work.
1610
// In case of external CMake installation, you will need the Ninja binary inside your cmake/bin
1711
// folder to make the build work: https://github.com/ninja-build/ninja/releases/latest
1812
//
19-
// Comment these blocks for building the app using the compiled library (liblsl.so). Make sure you
20-
// copy the build library on /app-root/module-root/src/main/jniLibs/
21-
// By compiling liblsl from source, CMake generates it for all Android architectures. The outcome is
22-
// stored on /app-root/module-root/build/intermediates/cmake/debug/obj/
23-
// Just copy all the folders (arm64-v8a, armeabi-v7a, x86, and x86_64) on the "jniLibs" folder and
24-
// the build will succeed.
25-
//
13+
// Comment the "externalNativeBuild" blocks for building the app using the compiled library
14+
// (liblsl.so). Once the build succeeds, the library files (.so) are automatically copied inside
15+
// the folders:
16+
// /project-root/app/src/debug/jniLibs (for a debug build)
17+
// /project-root/app/src/main/jniLibs (for a release build)
2618
// IMPORTANT to use LSL on your code:
2719
// - Take the the last version of LSL.java:
2820
// https://github.com/labstreaminglayer/liblsl-Java/blob/master/src/edu/ucsd/sccn/LSL.java
@@ -31,48 +23,97 @@ plugins {
3123
// - Include the following permission on your AndroidManifest.xml:
3224
// <uses-permission android:name="android.permission.INTERNET" />
3325
// - Include the jna (Java Native Access) in your dependencies block. E.g.:
34-
// implementation 'net.java.dev.jna:jna:5.9.0@aar'
26+
// implementation 'net.java.dev.jna:jna:5.10.0@aar'
3527
//
3628

29+
apply plugin: 'com.android.application'
30+
31+
def keystoreProperties = new Properties()
32+
keystoreProperties.load(new FileInputStream(file('../keystore.properties')))
33+
3734
android {
35+
signingConfigs {
36+
debug {
37+
storeFile file('key.jks')
38+
storePassword keystoreProperties['storePassword']
39+
keyAlias keystoreProperties['keyAlias']
40+
keyPassword keystoreProperties['keyPassword']
41+
}
42+
release {
43+
storeFile file('key.jks')
44+
storePassword keystoreProperties['storePassword']
45+
keyAlias keystoreProperties['keyAlias']
46+
keyPassword keystoreProperties['keyPassword']
47+
}
48+
}
3849
compileSdk 31
3950
defaultConfig {
4051
minSdk 24
4152
targetSdk 31
4253
versionCode 1
4354
versionName '1.15.2'
55+
setProperty('archivesBaseName', "liblsl-android-builder-$versionName")
4456
ndk {
4557
// Specifies the ABI configurations of your native
4658
// libraries Gradle should build and package with your app.
4759
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
4860
}
49-
externalNativeBuild.cmake {
50-
arguments "-DANDROID_CPP_FEATURES=rtti exceptions", "-DLSL_NO_FANCY_LIBNAME=1", "-DANDROID_PLATFORM=24"
51-
targets "lsl"
52-
}
53-
}
54-
externalNativeBuild.cmake {
55-
version "3.18.1"
56-
path "./liblsl/CMakeLists.txt"
61+
// externalNativeBuild.cmake {
62+
// arguments "-DANDROID_CPP_FEATURES=rtti exceptions", "-DLSL_NO_FANCY_LIBNAME=1", "-DANDROID_PLATFORM=24"
63+
// targets "lsl"
64+
// }
5765
}
66+
// externalNativeBuild.cmake {
67+
// path "./liblsl/CMakeLists.txt"
68+
// }
5869
buildTypes {
59-
release {
60-
minifyEnabled true
61-
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
70+
debug {
6271
debuggable true
72+
jniDebuggable true
73+
renderscriptDebuggable true
74+
signingConfig signingConfigs.debug
75+
}
76+
release {
77+
debuggable false
78+
jniDebuggable false
79+
renderscriptDebuggable false
80+
signingConfig signingConfigs.release
81+
minifyEnabled false
82+
shrinkResources false
83+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
6384
}
6485
}
6586
compileOptions {
6687
sourceCompatibility JavaVersion.VERSION_1_8
6788
targetCompatibility JavaVersion.VERSION_1_8
6889
}
90+
packagingOptions {
91+
pickFirst '**/lib/**'
92+
}
6993
buildToolsVersion '32.0.0'
7094
ndkVersion '21.4.7075529'
7195
}
7296

7397
dependencies {
7498
implementation 'androidx.appcompat:appcompat:1.4.1'
75-
implementation 'net.java.dev.jna:jna:5.10.0@aar'
76-
implementation 'com.google.android.material:material:1.5.0'
7799
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
100+
implementation 'com.google.android.material:material:1.5.0'
101+
implementation 'net.java.dev.jna:jna:5.10.0@aar'
102+
}
103+
104+
// copy native libraries to per project location
105+
task copyDebugJniLibs(type: Copy) {
106+
from 'build/intermediates/cmake/debug/obj'
107+
include('**/*.*')
108+
into 'src/debug/jniLibs'
109+
}
110+
task copyReleaseJniLibs(type: Copy) {
111+
from 'build/intermediates/cmake/release/obj'
112+
include('**/*.*')
113+
into 'src/main/jniLibs'
114+
}
115+
116+
tasks.whenTaskAdded { task ->
117+
if (task.name == 'assembleDebug') task.finalizedBy('copyDebugJniLibs')
118+
if (task.name == 'assembleRelease') task.finalizedBy('copyReleaseJniLibs')
78119
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:7.0.4'
8+
classpath 'com.android.tools.build:gradle:7.1.0'
99
// classpath 'com.netflix.nebula:gradle-lint-plugin:latest.release' // not working gradle > 7
1010

1111
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Sep 30 14:59:02 CEST 2021
1+
#Thu Feb 03 18:21:06 CET 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':builder'
1+
include ':app'

0 commit comments

Comments
 (0)