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+
3734android {
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
7397dependencies {
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}
0 commit comments